adafruit / Adafruit_nRF52_Arduino

Adafruit code for the Nordic nRF52 BLE SoC on Arduino
Other
606 stars 492 forks source link

Add the ability to change SAADC acquisition time #680

Closed ajs123 closed 3 years ago

ajs123 commented 3 years ago

Provide the user with the ability to change the SAADC acquisition time to accommodate higher source resistance signals.

ajs123 commented 3 years ago

The Nordic product specification describes SAADC sample and hold time (TACQ) recommendations for higher resistance signal sources (see Figure 2 and Table 1).

These changes provide the ability to set the TACQ field in the ADC channel configuration, for users who are measuring voltages from higher-impedance sources. The needed TACQ field #defines are already provided in nrf52840_bitfields.h. In testing, the standard deviation of 10-bit ADC readings at the wiper of a 20 kohm potentiometer (ends at Vdd and GND) was reduced from 1.5 LSB to 0.7 LSB by changing TACQ from 3us to 10us. This was the case for both the default 3.6V reference and a Vdd reference, with oversampling set to 4.

The added function, analogSampleTime(uint8_t time) defaults to the current hard-coded value of 3 us. It follows the same form as analogReadResolution and analogOversample, both of which silently set the default if not provided with a valid value.

ajs123 commented 3 years ago

I apologize for making another change after the checks were run. While I was editing, I’d changed some #includes from “” form to <> form and I forgot to change them back. It builds either way but I’m sure it should remain as it was.

hathach commented 3 years ago

I apologize for making another change after the checks were run. While I was editing, I’d changed some #includes from “” form to <> form and I forgot to change them back. It builds either way but I’m sure it should remain as it was.

There is nothing to apologize, making multiple changes is not an issue at all :)