4
\$\begingroup\$

I configured my TIM4 as encoder input and everything is working well when I execute TIM_GetCounter(TIM4) But I would like to put the timer value back to 0 (reset?) when I press a push button with an interrupt on it) and I don't find a reset function. I'm running a STM32F103 with only StdPeriph Lib.

Bence Kaulics
6,47312 gold badges35 silver badges61 bronze badges
asked Jul 18, 2017 at 13:12
\$\endgroup\$
0

1 Answer 1

6
\$\begingroup\$

You should write one for yourself based on the 'get' function:

uint32_t TIM_GetCounter(TIM_TypeDef* TIMx)
{
 /* Check the parameters */
 assert_param(IS_TIM_ALL_PERIPH(TIMx));
 /* Get the Counter Register value */
 return TIMx->CNT;
}

So a TIM_ResetCounter should look like this:

void TIM_ResetCounter(TIM_TypeDef* TIMx)
{
 /* Check the parameters */
 assert_param(IS_TIM_ALL_PERIPH(TIMx));
 /* Reset the Counter Register value */
 TIMx->CNT = 0;
}

If you check in the reference manual, you can see that the counter value register has read-write access. So you can set it to 0.

enter image description here

You can create a general set function as well with an additional "value" parameter.

answered Jul 18, 2017 at 14:26
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.