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
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=]