6 years, 4 months ago.

How does one independently alter ADC configurations for A0 thru A7 inputs with the nRF51-DK?

I am developing an Environmental Sensor service for BLE using the nRF51-DK on the Nordic nRF51422 IC using Mbed OS2. The service multiplexes several sensors into the ADC for conversion. I need to be able to set the ADC_CONFIG_REFSEL and ADC_CONFIG_INPSEL bits of the NRF_ADC->CONFIG register indepently for each sensor input. Problem is I don't see how to do this while using Mbed's implementation of Analog inputs, e.g.:

<<p>>
AnalogIn ana0(A0);  // temperature
AnalogIn ana1(A1);  // pressure   
AnalogIn ana2(A2);  // humidity   
<</p>>

All my attempts to set the CONFIG registers are getting lost by the time I execute anaX_read(). How is this analog input magic implemented? Is there some way to create a method for configuring the analog inputs? Steve

I found the source for analogin_api.c in mbed-dev. It explains why I am unable to change the configuration. Constant fixed config defines are used. This code does not explain why this dev kit's maximum ADC output voltage is equal to the 1.2V VBG reference. Presumably my version of mbed has a different config setup for the analogin api.

analogin_api.c analog_init()

    NRF_ADC->CONFIG = ... |
                      (ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos) |
                      (ADC_CONFIG_REFSEL_SupplyOneThirdPrescaling << ADC_CONFIG_REFSEL_Pos) | ...
posted by Steve Wald 13 Aug 2018

1 Answer

6 years, 4 months ago.

Hi Steve,

Your analysis is correct - and on top of that after consulting the nRF51 Reference Manual it appears that the device family doesn't allow for independent configurations for each channel. A single config applies for all channels. So if your channels do need different configurations it looks like you will have to reprogram the ADC and serialize your sampling.

As you noted Mbed doesn't have a function for setting the options you would like, so you can write your own function to handle it.

-Ralph, Team Mbed

Accepted Answer