STM32F103 and Encoder Mode
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2023-11-04 12:42 PM
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.
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 ?
- Labels:
-
Interrupt
-
STM32F1 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2023-11-06 5:06 AM
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.
