This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Sampling ADC with two sampling frequency alternately....

Hi,

I am working in one application in which I need SAADC to sample two channels at 1ksps and 500 samples per seconds.

I am sending 1 and 2 to switch the sampling rate i.e. if I send 1 then SAADC should sample at 1ksps and for 2 it should sample at 500 samples per second.

I am trying like below:

               int main(void)
{
    
    bool erase_bonds;

    // Initialize.
    gpio_init();
    app_trace_init();
    timers_init();
    buttons_leds_init(&erase_bonds);
    uart_int();
    ble_stack_init();
    device_manager_init(erase_bonds);
    gap_params_init();
    services_init();
    advertising_init();
    sensor_simulator_init();
    conn_params_init();
    
    
    
    // Start execution.
    application_timers_start();
    err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
    APP_ERROR_CHECK(err_code);
    
//    saadc_sampling_event_init();
    saadc_init();
    
    //saadc_sampling_event_enable();
                
    printf("\n\rStart: \n\r");
                
    // Enter main loop.
    for (;;)
    {
        if (data_ready == true)
        {
            data_ready = false;
            hr_algorithm();
        }
        
        if (abc == 0x01)
        {
          abc = 0x00;
          freq = 1000;
          saadc_sampling_event_init();
          nrf_delay_ms(10);
          saadc_sampling_event_enable();
          mode_2_flag = false;
        }
        if (abc == 0x02)
        {
          abc = 0x00;
          freq = 500;
          saadc_sampling_event_init();
          nrf_delay_ms(10);
          saadc_sampling_event_enable();
          mode_2_flag = true;
        }
        power_manage();
    }
}

Here abc is the variable used which receives data from APP. Freq is variable which holds sampling frequency.

saadc_sampling_event_init(); function is standard function that is used in sample codes.

While I am trying this, SAADC is not getting initialized. Complete device gets restarted when I send data from APP.

Can anyone suggest whether is correct way of doing this?

Related