arduino-libraries / Arduino_AdvancedAnalog

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

Programmable Sample Time parameter for faster sample rates #62

Closed jmdodd95682 closed 4 months ago

jmdodd95682 commented 4 months ago

In HALConfig.cpp, the hal_adc_config() routine currently has the Sample Time (sConfig.SamplingTime) hard coded to a value of ADC_SAMPLETIME_8CYCLES_5 (8.5 clocks).

According to the datasheet, a value of ADC_SAMPLETIME_2CYCLES_5 (2.5 clocks) is legal. This increases the maximum sample rate from 1.8 MS/s to 2.9 MS/s.

Due to concerns about operating conditions (temperature, voltage etc), it would NOT be a good idea to simply change the hard-coded value from 8.5 clocks to 2.5 clocks. Instead, a new defaulted argument can be added to hal_adc_config() which can be set to SAMPLE_SLOW or SAMPLE_FAST to enable switching between 8.5 clocks and 2.5 clocks as the user prefers based on their operating conditions and needs. The default would be SAMPLE_SLOW to retain backward compatibility.