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

app_time and nrf_delay_ms

Hi

I would like to read values from three AD channels where I use different sampling frequencies and different number of samples are captured at each sampling frequency. To be clear I will explain my problem in the case of one channel. Every 10s I would like to capture five values from the actual channel and subsequently the averaging is performed. The time between each sample should be around 10ms. At this stage I do not know what is the best programming solution for my problem to be the sofware as efficient as possible. Here is my current code, where I used nrf_delay_ms(10) function for waiting between two samples. I know that this is not the most efficient way because of that I will appreciate for any advice how I can improve my code.

Best regards

Samo

static void adc_lpg_timer_handler(void * p_context) // timer executed every 10s
{ 	
	
	int i;
	nrf_adc_value_t adc_value;
	uint8_t err_code;
	uint16_t ave_adc = 0;
	
	nrf_gpio_pin_toggle(LPG_PIN);	
	
	for(i=0; i < 5; i++)
	{
		nrf_delay_ms(10);
		while(nrf_drv_adc_is_busy())
		{
		}	
		err_code = nrf_drv_adc_sample_convert(&adc_lpg,&adc_value);
		APP_ERROR_CHECK(err_code);
	
	  ave_adc = ave_adc + adc_value;
  }
	 ave_adc = ave_adc/5;
	 ave_adc = 1200*ave_adc/1023;	 	 	
	 err_code = ble_adcs_2_update(&m_adcs,ave_adc);	 
	 APP_ERROR_CHECK(err_code);
	 ave_adc = 0;	   		
	 
	 nrf_gpio_pin_toggle(LPG_PIN);	
}
Parents Reply Children
No Data
Related