cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 and Encoder Mode

jlecl.1
Associate III

Dear community

I develop a 'robot" with odometrie.
Each geared DC motor have a rotary magnetic encoder for speed regulation.

My question is about avoid count overload.

I use a timer for read encoder count. Each interrupt, i print the value.
Capture.PNG

My aim is avoid false data by resetting the timer count ( avoid overflow regiser)

 

uint16_t MSG[10]={0};

	tick = (TIM4->CNT);
	TIM4->CNT=1000;
	sprintf(MSG,"%d\n",tick);
	HAL_UART_Transmit_DMA(&huart4, MSG, strlen(MSG));

 

This code is inside a timer function.
Without the line "Tim4->CNT=1000", the data is correct. With it, the data seem to be strange.
>> The question, is this line is the correct way to reset the register ?

1 REPLY 1
Pierre_Paris
ST Employee

Hello @jlecl.1,

Thank you for your question.

Here are some remark :

  • In downcounting mode, the counter counts from the auto-reload value (content of the TIMx_ARR register, 60000 in your case) down to 0, then restarts from the auto-reload value and generates a counter underflow event.
  • Why are you setting the counter value to 1000 but with an AutoReload value = 60000 ? Can you tell me more about your application and how you want to use the timer ?

Best Regards,

Pierre

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.