2023-09-18 01:02 PM
I have a test project that sets up TIM3.3 to count microseconds between falling edges of the timer input. The timer is started with a call to HAL_TIM_IC_Start_IT(&htim3, TIM_CHANNEL_3); to start timing the input. Inside HAL_TIM_IC_CaptureCallback(*htim), I call pulseDurations[pulseIdx++]= HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_3);
followed by __HAL_TIM_SET_COUNTER(htim, 0); to save and reset the TIM3.3 counter. This gives me the number of microseconds between falling edges of the timer input. This works perfectly until the frequency on the input exceeds 10KHz where incoming pulses appear to be lost and are not counted.
In an attempt to improve the high frequency abilities, I created a second test project to use HAL_TIM_IC_Start_DMA(&htim3, TIM_CHANNEL_3, fallData, numData); to populate an array with the timer counter values every time TIM3.3 receives a falling edge. The array gets populated correctly, albeit the 16 bit timer value overflows but, otherwise it is working correctly.
Is there a way to duplicate the ability to reset the timer counter shown in the first project after logging it in the DMA array of the second project?
I am using the HAL_ library. Would things speed up by using the LL_ library? I need to get to 150KHz.
Source code available. I didn't know how much to include. It's mostly examples from various sources.
Thanks,
Dan
Solved! Go to Solution.
2023-09-18 02:26 PM
Setting the counter back to 0 will lose the ticks between the event and the reset. The key is to use the delta between events and not reset the timer.
At 150kHz, you'll likely need to use DMA. If using a 16-bit timer, handling overflow gracefully is straightforward.
2023-09-18 01:24 PM
2023-09-18 02:26 PM
Setting the counter back to 0 will lose the ticks between the event and the reset. The key is to use the delta between events and not reset the timer.
At 150kHz, you'll likely need to use DMA. If using a 16-bit timer, handling overflow gracefully is straightforward.
2023-09-19 05:57 AM
I already saw those. That was the basis of test project #1. I programmed it up and simplified it to log the value of the timer counter and reset it. At lower frequencies, it gives me a log of the duration of the input pulses.
ControllersTech also has another video using input capture w/DMA where I similarly made my adjustments. This is test project #2. This version gives a log of the timer counts.
I'm attempting to mix the two methods to obtain a log of pulse durations with the speed of the DMA access while minimizing the amount of time spent in the ISR by avoiding having to subtract the countstamps.
Thank you for your response.
2023-09-19 06:04 AM
See also my response to Issamos.
I hadn't thought about losing ticks between the event and the reset. It looks like there will be some post processing of the log obtained by the DMA.
I thought I'd ask if anybody knew of a way to merge the two ideas. A log of the width of the pulses would have been so convenient.
Thanks!
2023-09-19 09:13 AM
I used input w/DMA. (https://www.youtube.com/watch?v=qqzZ9C0umQ4&list=PLfIJKC1ud8gjLZBzjE3kKBMDEH_lUc428&index=9_
Inside HAL_TIM_IC_CaptureCallback(), I corrected for the 16bit timer overflow and did the subtraction to get the duration of the pulse instead of the timer count.
Worked like a charm.
Thank you!