2017-06-15 01:54 AM
Hello, I'm trying to read the tension in a port with the ADC every 2 seconds. In order to achieve this, I call the ADC reading function within a HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) function and I have set the timer to accurately count 2000 ms. Nevertheless, as there is a buffer with an RC filter right before the input, I have to wait a time 10 times tau (where tau = RC) to capture the value. So, before doing the lecture I introduce a delay function with a for loop and a nop assembly instruction. This is not accurate, so I have tried to use the following function implemented with the timer:
void delay(uint32_t t){
uint32_t t1 = __HAL_TIM_GET_COUNTER(&htim3); while((__HAL_TIM_GET_COUNTER(&htim3)-t1)<t);}But calling this function within the Timer Callback function blocks the MCU. The same happens if I try to use the HAL_Delay function. How can I implement an accurate delay within the Timer Callback? Or is it just that it's not possible as it is a bad practice?
#timer #delay #hal #stm32f0912017-06-15 07:19 AM
What about use timerA(according to your update period) to trigger timerB(according to your RC time),
then your adc is trigger by timerB.