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

nrf52832 PPI SAADC Oversample,sample rate up to 250hz

I am using SAADC and PPI to sample 2 channels data with oversample,when I set  timer tick 5ms,the sample rate is 200hz and the system works well,now I want to improve the sample rete,So I change the timer tick to 2ms,the sample rate is 500hz.but I tested that the SAADC output data rate is up to 250hz, the timers frequency is 16M.

void ECG8233_saadc_sampling_event_init(void)
{
ret_code_t err_code;

err_code = nrf_drv_ppi_init();
APP_ERROR_CHECK(err_code);

nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
// timer_cfg.frequency = 
timer_cfg.bit_width =NRF_TIMER_BIT_WIDTH_32; 

err_code = nrf_drv_timer_init(&m_hardware_timer, &timer_cfg, timer_handler);//m_hardware_timer即TIMER1
APP_ERROR_CHECK(err_code);


uint32_t ticks = nrf_drv_timer_ms_to_ticks(&m_hardware_timer, 2); 

nrf_drv_timer_extended_compare(&m_hardware_timer,
NRF_TIMER_CC_CHANNEL0,
ticks,
NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
false);

nrf_drv_timer_enable(&m_hardware_timer);

uint32_t timer_compare_event_addr = nrf_drv_timer_compare_event_address_get(&m_hardware_timer,
NRF_TIMER_CC_CHANNEL0);
uint32_t saadc_sample_task_addr = nrf_drv_saadc_sample_task_get();


err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel);
APP_ERROR_CHECK(err_code);

err_code = nrf_drv_ppi_channel_assign(m_ppi_channel,
timer_compare_event_addr,
saadc_sample_task_addr);
APP_ERROR_CHECK(err_code);
}

can anyone help me to solve this problem ,is there any configuration wrong?

Parents
  • Can you share the rest of your SAADC-related code?

    I suggest you enter a debug session and read the value of the BITMODEPRESCALER, and CC[x] register. 

    That will tell us whether the TIMER is triggering the SAADC's sample task when we expect it to. 


  • void ECG8233_saadc_init(void)
    {
    	ret_code_t err_code;
    	nrf_saadc_channel_config_t channel_ECG_config =
        NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_DIFFERENTIAL(ECG_8233_ADC_PIN_IN,ECG_8233_ADC_REF_PIN_IN);
    	channel_ECG_config.gain = NRF_SAADC_GAIN1_4;
    	channel_ECG_config.burst = NRF_SAADC_BURST_ENABLED;
    
        nrf_saadc_channel_config_t channel_VBAT_config =
                NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(BAT_VOL_ADC_PIN_IN);
    	channel_VBAT_config.burst = NRF_SAADC_BURST_ENABLED;	
    
        err_code = nrf_drv_saadc_init(NULL, saadc_callback); 
        APP_ERROR_CHECK(err_code);	
    	
    
        err_code = nrf_drv_saadc_channel_init(0, &channel_ECG_config);
        APP_ERROR_CHECK(err_code);
    	//ADC  BatteryLevel config
    	nrf_delay_ms(10);
        err_code = nrf_drv_saadc_channel_init(1, &channel_VBAT_config);
        APP_ERROR_CHECK(err_code);
    
    	err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool, SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);
    }

    this is the rest  of SAADC related code,ECG signal  and battery voltage, this is saadc config

    // <0=> 8 bit 
    // <1=> 10 bit 
    // <2=> 12 bit 
    // <3=> 14 bit 
    
    #ifndef NRFX_SAADC_CONFIG_RESOLUTION
    #define NRFX_SAADC_CONFIG_RESOLUTION 3  //1:10bit
    #endif
    
    // <o> NRFX_SAADC_CONFIG_OVERSAMPLE  - Sample period
     
    // <0=> Disabled 
    // <1=> 2x 
    // <2=> 4x 
    // <3=> 8x 
    // <4=> 16x 
    // <5=> 32x 
    // <6=> 64x 
    // <7=> 128x 
    // <8=> 256x 
    
    #ifndef NRFX_SAADC_CONFIG_OVERSAMPLE
    #define NRFX_SAADC_CONFIG_OVERSAMPLE 8//8
    #endif
    

Reply
  • void ECG8233_saadc_init(void)
    {
    	ret_code_t err_code;
    	nrf_saadc_channel_config_t channel_ECG_config =
        NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_DIFFERENTIAL(ECG_8233_ADC_PIN_IN,ECG_8233_ADC_REF_PIN_IN);
    	channel_ECG_config.gain = NRF_SAADC_GAIN1_4;
    	channel_ECG_config.burst = NRF_SAADC_BURST_ENABLED;
    
        nrf_saadc_channel_config_t channel_VBAT_config =
                NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(BAT_VOL_ADC_PIN_IN);
    	channel_VBAT_config.burst = NRF_SAADC_BURST_ENABLED;	
    
        err_code = nrf_drv_saadc_init(NULL, saadc_callback); 
        APP_ERROR_CHECK(err_code);	
    	
    
        err_code = nrf_drv_saadc_channel_init(0, &channel_ECG_config);
        APP_ERROR_CHECK(err_code);
    	//ADC  BatteryLevel config
    	nrf_delay_ms(10);
        err_code = nrf_drv_saadc_channel_init(1, &channel_VBAT_config);
        APP_ERROR_CHECK(err_code);
    
    	err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool, SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);
    }

    this is the rest  of SAADC related code,ECG signal  and battery voltage, this is saadc config

    // <0=> 8 bit 
    // <1=> 10 bit 
    // <2=> 12 bit 
    // <3=> 14 bit 
    
    #ifndef NRFX_SAADC_CONFIG_RESOLUTION
    #define NRFX_SAADC_CONFIG_RESOLUTION 3  //1:10bit
    #endif
    
    // <o> NRFX_SAADC_CONFIG_OVERSAMPLE  - Sample period
     
    // <0=> Disabled 
    // <1=> 2x 
    // <2=> 4x 
    // <3=> 8x 
    // <4=> 16x 
    // <5=> 32x 
    // <6=> 64x 
    // <7=> 128x 
    // <8=> 256x 
    
    #ifndef NRFX_SAADC_CONFIG_OVERSAMPLE
    #define NRFX_SAADC_CONFIG_OVERSAMPLE 8//8
    #endif
    

Children
Related