AnsweredAssumed Answered

Quadrature encoders roll over management

Question asked by emond.daniel on Nov 19, 2013
Latest reply on Nov 20, 2013 by Clive One
Hi,
I am currently developping a firmware programmed into a STM32F407VG microcontroller.
The firmware has the following tasks:
- Reading motor positions (5 axes: 3 with quadratures/indexes and 2 with steps/directions),
- Trig a laser pulse at a specific motor positions (synchronized with only 1 axis),
- Send a PWM signal to the laser to keep it in a simmering state,
- Trig a scanner laser line to read a scanner profiles at specific motor positions (synchronized with 2 axes),
- Read a bunch of digital inputs,
- Write a few digital outputs,
- Read the Board temperature,
- Read 2 analog inputs, and
- Eventually control the motors (phase 2 of the project).
Communication is done via USB FS. Eventually, I'll require I2C communication (surprisingly, I still have the secondary I2C available for that purpose).

As you can see, I'm kinda low on available ressources. All the timers are used, 75% of the embedded RAM is used, etc.

I've been able to complete most of the work (and it seems to be working). My only concern right now is the way I extend the 16bits timers to 32bits to track the positions (a full rotation is 160000 encoder pulses and the resolution on the translation axes is 2000 encoder pulses per mm).

I have read in the reference manual (RM0090 - DM00031020.pdf) that when configured in encoder mode, the direction bit (bit 4) of the control register 1 (TIMx_CR1:DIR) is set as read only. I was hoping that the direction bit was updated as per the timer counter increment/decrement operations, i.e.: can I use it to determine the roll over direction of the counter ?
bool isCountingUpward = TIM2->CR1 & 0x0010 ? false : true;
Does it get updated by the phase A/B shifts ?

How reliable is the solution presented in this thread:
[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/32bit%20quadrature%20encoder&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&TopicsView=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/AllItems.aspx?View%3D%7bF47A9ED8-E726-42BE-ACED-732F13B66581%7d%26FilterField1%3DLinkDiscussionTitle%26FilterValue1%3D32bit%2520quadrature%2520encoder&currentviews=1132]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fcortex_mx_stm32%2f32bit%20quadrature%20encoder&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&TopicsView=https%3A%2F%2Fmy%2Est%2Ecom%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FAllItems%2Easpx%3FView%3D%7BF47A9ED8-E726-42BE-ACED-732F13B66581%7D%26FilterField1%3DLinkDiscussionTitle%26FilterValue1%3D32bit%2520quadrature%2520encoder&currentviews=1132

Outcomes