Skip to main content
Aes.1
Associate
January 31, 2020
Question

reset timer count value

  • January 31, 2020
  • 1 reply
  • 698 views

i wrote a program and i want to turn on the led after passing a 500 and 750 , 1000ms.

i use out put compare and use active on mach timer mode.

but it only work one time , i realize that i should reset my timer and count value but i don't know how?

please solve my problem.

thanks in advance.

 while (1)

 {

HAL_TIM_OC_Start(&htim3,TIM_CHANNEL_1);

HAL_TIM_OC_Start(&htim3,TIM_CHANNEL_2);

HAL_TIM_OC_Start(&htim3,TIM_CHANNEL_4);

HAL_Delay(2000);

HAL_TIM_OC_Stop(&htim3,TIM_CHANNEL_1);

HAL_TIM_OC_Stop(&htim3,TIM_CHANNEL_2);

HAL_TIM_OC_Stop(&htim3,TIM_CHANNEL_4);

sConfigOC.OCMode = TIM_OCMODE_ACTIVE;

 sConfigOC.Pulse = 500;

 sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;

 sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;

 if (HAL_TIM_OC_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)

 {

  Error_Handler();

 }

 sConfigOC.Pulse = 750;

 if (HAL_TIM_OC_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)

 {

  Error_Handler();

 }

 sConfigOC.Pulse = 1000;

 if (HAL_TIM_OC_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)

 {

  Error_Handler();

 }

This topic has been closed for replies.

1 reply

dbgarasiya
Senior
February 3, 2020

TIMx->CNT = 0;