cancel
Showing results for 
Search instead for 
Did you mean: 

Reset timer counter on Input Capture

ee06091
Associate III
Posted on June 14, 2018 at 01:13

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-mode
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on June 14, 2018 at 09:51

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

View solution in original post

5 REPLIES 5
Posted on June 14, 2018 at 09:51

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

T J
Lead
Posted on June 14, 2018 at 11:39

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...

henry.dick
Senior II
Posted on June 14, 2018 at 12:12

'

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?

Posted on June 14, 2018 at 23:25

Thank you, I thought I can only use master slave to connect timers and not to trigger same timer events.

Posted on June 14, 2018 at 23:27

1. And I thought it isn't reset because the earth is plane!

2. Because the earth isn't plane!