ADC configuration for nRF5340DK SDK Connect SES

I need twoADC channels. I tried to configure using :

CONFIG_ADC= y in prj file,

&adc{
#io-channel-cells = < 0x2 >;
};   in overlay file .. the compile error appears as shown in atteched iamge.

Gulzar Singh

  • Hello,

    1. In the adc.h, if #define  BUFFER_SIZE 2  right or wrong to sample 2 analog channels ? If in future, 3 chhannels are required, may I set #define  BUFFER_SIZE 3.

    The buffer size should be set to N*number of enabled channels, as SCAN mode will sample each channel subsequently and put the result in the RAM buffer as described here: https://infocenter.nordicsemi.com/topic/ps_nrf5340/saadc.html?cp=3_0_0_6_28_4_3#saadc_operationmodes_scan. If you set a buffer size that does not match the number of enabled channels, you will miss samples, or samples will be stored in the buffer in non-deterministic order.

    2. In the main file, I adc instantiated by binding and then, set up channels using err = adc_channel_setup() .. function. Is it proper way ?

    yes it is.

    3. '' #if defined (CONFIG_BOARD_BMS_NRF5340_CPUAPP)
    NRF_SAADC->TASKS_CALIBRATEOFFSET = 1''

    this task will start offset auto-calibration in SAADC peripheral. 

    4. I wrote two sample functions, as in adc.c. Is this proper way to add to sequence ? If, wrong any where, may you make changes and attached corrected code file ?

    It is ok. I have added a sample code where 2 channels are used. you can look at this as reference. 

    5. I called adc sampling functions in repeatitive timer. Is the result of adc from AIN0 and AIN1 be avaialble at same index or at different indices in p_sample_buffer[]

    Indexes will be different if both channels are enabled at once and scan mode are used. p_sample_buffer[] will have different values.  

    Regards,

    Kazi Afroza Sultana

  • Hi, I tested the program in the attached file. AN0 and AN1 channels configured to sample two anlaog Inputs. The AN0 channel is sampled very well and the ADC result is avaialbale at index 0 of the buffer. The result of AN1 should be available at index 1 of buffer, but remains zero. Please, have a look at the code. If, you test it with any variable voltage at AN0 and AN1, will be better to verify.

  • Hello Gulzar,

    Sorry for the late reply; I was in sick leave.

    How does your overlay file look like? 

    / {

    zephyr,user {

    /* adjust channel number according to pinmux in board.dts */

    io-channels = <&adc 0>, <&adc 1>;

    };

    };

    For these channels to be on AN0 and AN1, the above overlay needs to be added.
    Best Regards,
    Kazi Afroza Sultana
Related