2018-06-13 04:13 PM
I have configured an timer IC channel and it is working ok however the timer counter isn't reset when I read the captured value:
void
HAL_TIM_IC_CaptureCallback
(TIM_HandleTypeDef
*
htim){
if
(htim
==
&
htim2)
{
input_capture
=
HAL_TIM_ReadCapturedValue
(
&
htim2, TIM_CHANNEL_1);
}
}
There is any register that I need to configure so the timer reset the counter each time it capture a value?
Per example I have a channel capturing a 10Hz signal however I'm only writing to serial port at 1Hz and I only want to write the last captured value. Without reset the counter the output I got is '1000, 2000, 3000, 4000,...' instead of always be 100 (I have the timer configured to 1ms resolution).
#stm32f0-hal #input-capture-modeSolved! Go to Solution.
2018-06-14 12:51 AM
If you use channel 1, you want to set TIMx_SMCR.TS to TI1FP1 and TIMx_SMCR.SMS to 0b100: Reset Mode.
I don't use Cube so don't know what are its incantations to do that, but
https://community.st.com/0D50X00009bMMA8SAO
is a Cube/CubeMX-based tutorial to do something based on this reset (it's slightly more involved, and also it uses the other channel which is not necessary; but you should get the point).JW
2018-06-14 12:51 AM
If you use channel 1, you want to set TIMx_SMCR.TS to TI1FP1 and TIMx_SMCR.SMS to 0b100: Reset Mode.
I don't use Cube so don't know what are its incantations to do that, but
https://community.st.com/0D50X00009bMMA8SAO
is a Cube/CubeMX-based tutorial to do something based on this reset (it's slightly more involved, and also it uses the other channel which is not necessary; but you should get the point).JW
2018-06-14 02:39 AM
could you calculate the relative difference.. ?
if you reset the timer you will lose accuracy due to latency.
just track the last value and subtract this value. to get a relative difference...
2018-06-14 03:12 AM
'
however the timer counter isn't reset when I read the captured value:'
1. it isn't reset because your code didn't reset it;
2. why do you want it reset anyway?
2018-06-14 04:25 PM
Thank you, I thought I can only use master slave to connect timers and not to trigger same timer events.
2018-06-14 04:27 PM
1. And I thought it isn't reset because the earth is plane!
2. Because the earth isn't plane!