cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 Quadrature Encoder

arapp1990
Associate II
Posted on February 21, 2017 at 21:50

Hello guys,

I would like to use an quadrature encoder for a motor control application on an STM32F303K8T6.

Unfortunately the hardware gives me the following configuration:

ENCODER_OUT_A -> PA2 (TIM2_CH3)

ENCODER_OUT_B -> PA3 (TIM2_CH4)

ENCODER_OUT_Z -> PA5 (TIM2_CH1)

Is there any possibility to use CH3 and CH4 instead of CH1 and CH2 as timer count input

and

CH1 as capture timer value input?

The quadrature encoder generates 1024 per machanical revolution and get spinned up to 10krpm.

best regards

#motor-control #quadrature-encoder
8 REPLIES 8
Posted on February 21, 2017 at 22:17

Is there any possibility to use CH3 and CH4 instead of CH1 and CH2 as timer count input

No.

JW

T J
Lead
Posted on February 22, 2017 at 00:18

You may be able to use external interrupts and count the steps yourself...

1024 x 10,000 /60 = 171kHz x 4 edges, 682Khz interrupts

at 72Mhz cycle rate, its about 100 cycles per interrupt, yes it can be done, but nothing else

and if you miss a count, you are in big trouble, smashing the machine..

but it is far better to use the hardware functions provided for this purpose...

JW has the correct short answer.

Uwe Bonnes
Principal II
Posted on February 22, 2017 at 00:32

What about using TIM15?

Posted on February 22, 2017 at 00:51

you actually don't need to use timers...

just interrupt pins, but it is dangerous for the machine equipment if the count is wrong and then you smash into the stop..

Posted on February 22, 2017 at 01:01

Good idea.

Posted on February 22, 2017 at 10:29

Are you sure TIM15 can be used in encoder mode? There is no description in the reference manual for TIM15 and the datasheet 'Table 5. Timer feature comparison' says TIM15 has just an UP Counter mode.

Posted on February 22, 2017 at 10:50

Indeed. I did not dig deeper, sorry.

JW

Posted on February 22, 2017 at 12:04

You seems to be right. Also RM0316 Rev 8 Figure 256 TIM15 block diagram shows '+/-' counter  there is no downcounting mode. Congratulation to ST for some other saved transistors!