nrfx_saadc library simple mode and advanced mode

Hi 

I have questions on adc multichannel and multichannel configuration. 

I want to setup two adc channels, One with timely accurate sampling, for example, 5ms. Another one that doesn't need accurate timing, e.g 30s, if the sampling period is 29s or 31 s, it's not a big problem. 

The first channel, I use ppi connect to sampling. 

Can I setup a second adc channel with a different timer? 

In the first channel I use "nrfx_saadc_advanced_mode_set", can I use nrfx_saadc_simple_mode_set for the second channel? 

Or I can only use one of the setup and add the channel mask to the first argument? 

Please suggest.

  • Hi,

    Can I setup a second adc channel with a different timer? 

    Yes, just initialize a new timer and setup PPI on a new channel for that timer. Note that triggering a SAMPLE task will sample all enabled channels.

    In the first channel I use "nrfx_saadc_advanced_mode_set", can I use nrfx_saadc_simple_mode_set for the second channel? 

    No, you can only use one mode each time you initialize driver,

    regards

    Jared

  • Hi Jared

    Thanks for the answer, but I am still not clear about triggering a sample task. 

    If I trigger two adc channels with two different ppi channels. In the following code snippets (please check if I have channel compare mask number correct, I haven't fully understand the purpose of clear mask)

    //init adc
    static nrfx_saadc_channel_t saadc_channel = NRFX_SAADC_DEFAULT_CHANNEL_DIFFERENTIAL(NRF_SAADC_INPUT_AIN0,NRF_SAADC_INPUT_AIN1, SAADC_CHANNEL_NUM);
    static nrfx_saadc_channel_t saadc_battery_channel  = NRFX_SAADC_DEFAULT_CHANNEL_SE(NRF_SAADC_INPUT_AIN3, SAADC_BAT_CHANNEL_NUM);
    static nrfx_saadc_channel_t * p_channels[2] = {&saadc_channel, &saadc_battery_channel};
    err = nrfx_saadc_channels_config(p_channels,2);
    err = nrfx_saadc_advanced_mode_set((1 << SAADC_CHANNEL_NUM)  | (1 << SAADC_BAT_CHANNEL_NUM), NRF_SAADC_RESOLUTION_14BIT, &saadc_adv_cfg, saadc_evt_handler);
    err = nrfx_saadc_mode_trigger();
    //init timer
    nrfx_timer_extended_compare(&timer1, NRF_TIMER_CC_CHANNEL0, 5ms_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
    nrfx_gppi_channel_endpoints_setup(ppi_channel1,
            nrfx_timer_event_address_get(&timer1, NRF_TIMER_EVENT_COMPARE0),
            nrf_saadc_task_address_get(NRF_SAADC, NRF_SAADC_TASK_SAMPLE));
    and second channel 
    nrfx_timer_extended_compare(&timer2, NRF_TIMER_CC_CHANNEL1, 1min_ticks, NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK, true);
    nrfx_gppi_channel_endpoints_setup(ppi_channel2,
            nrfx_timer_event_address_get(&timer2, NRF_TIMER_EVENT_COMPARE1),
            nrf_saadc_task_address_get(NRF_SAADC, NRF_SAADC_TASK_SAMPLE));
    How do I know which adc channel is connected to ppi_channel1? Or, all adc channels are connected to all ppi channels. 
  • szhaulai said:
    How do I know which adc channel is connected to ppi_channel1? Or, all adc channels are connected to all ppi channels. 

    No SAADC channel is connected directly to PPI. But every enabled SAADC channel will be sampled when you trigger the task SAMPLE as specified in the product specification:

    Sampling of all enabled channels is started by triggering the SAMPLE task, and the sample results are automatically written to memory using EasyDMA.

    When multiple channels are enabled, they are sampled successively in a sequence starting with the lowest channel number. The time it takes to sample all enabled channels is given as follows:

    Total time < Sum(CH[x].tACQ+tCONV), x is the number of enabled channels

    A DONE event is generated for every single completed conversion, and an END event is generated when multiple samples, as specified in RESULT.MAXCNT, have been written to memory.

    Thus, you never "trigger two adc channels", but you trigger the task SAMPLE through PPI when the COMPARE event is generated, if a SAADC channel has been enabled at that point, then it will be sampled. 

    regards

    Jared 

Related