arduino-libraries / Arduino_AdvancedAnalog

Advanced Analog Library
GNU Lesser General Public License v2.1
7 stars 5 forks source link

Added dual-mode support for ADC. #59

Closed jmdodd95682 closed 4 months ago

jmdodd95682 commented 4 months ago

After reading the 3500-page reference manual (nicely written but so much detail...so much...) for the STM32H7xx I found how to enable the dual-mode.

I modified the begin() and start() routines and added a few new members to the AdvancedADC class to allow using dual-mode. This gives the optimal synchronization between two sampled inputs. I'm seeing between 0 and 1us skew, which is pretty good for a 1M samp/sec configuration.

It does have some restrictions. You need to always use ADC1 and 2 (dual mode is only supported in HW for ADC 1 and 2). Also, you need to configure the AdvancedADC instance to explicitly selected dual mode. I tried to keep it as general purpose as possible.

I would be happy to share my code if you're interested. I can do a pull_request.

jmdodd95682 commented 4 months ago

Oh, also...I believe once we have dual-mode, it will be possible to double sample-rate. There is a delay field which can be programmed and you can enable "Interleaved Mode". If you tie the same input to two pins, enable dual-mode w/ interleaved and set the delay right, it should give you 2X the sample rate. 4M Samp/sec should be achievable. Have not tested this yet, but seems likely it will work.