2022-10-28 01:53 PM
I'm trying to control the timing of ADC for best performance.
So, I want to give exact delay based on the number of clock cycles.
However, I don't know what API should I use to give delay.
Right know, I turned on TIM16 and I know how to get timer like below.
t = __HAL_TIM_GET_COUNTER(&htim16);
I also know HAL_Delay(ms); commend but sometimes it doesn't work.
Is there any method give delay to the microcontroller based on the number of clock cycle?
Solved! Go to Solution.
2022-10-28 03:12 PM
Well doesn't the ADC have the ability to be directly triggered by a TIM, and thus a time base / periodicity of your choice?
With the TIM, 16 or 32-bit, you can use a delta measurement technique to observe elapsed time. The time will be a function of the TIM's clocking frequency via APB clock, or other source, and the Prescaler.
The TIM should be set in maximal mode, ie ARR = 0xFFFF or 0xFFFFFFFF, and you should use equivalent sized unsigned math on the number space.
Frequency and Time have some pretty well defined relationships. If you use a Prescaler to get 1 MHz, the TIM will count micro-seconds.
Most STM32 have a DWT unit with a CYCCNT register which is 32-bit, and counts at the MCU frequency. So obviously that resolves very well.
2022-10-28 03:12 PM
Well doesn't the ADC have the ability to be directly triggered by a TIM, and thus a time base / periodicity of your choice?
With the TIM, 16 or 32-bit, you can use a delta measurement technique to observe elapsed time. The time will be a function of the TIM's clocking frequency via APB clock, or other source, and the Prescaler.
The TIM should be set in maximal mode, ie ARR = 0xFFFF or 0xFFFFFFFF, and you should use equivalent sized unsigned math on the number space.
Frequency and Time have some pretty well defined relationships. If you use a Prescaler to get 1 MHz, the TIM will count micro-seconds.
Most STM32 have a DWT unit with a CYCCNT register which is 32-bit, and counts at the MCU frequency. So obviously that resolves very well.
2022-10-30 07:32 PM
In case of very low power needs, LPTIM maybe an alternate option.