cancel
Showing results for 
Search instead for 
Did you mean: 

Rotary encoder timer interrupt

paul sauv
Associate III
Posted on June 30, 2017 at 11:46

Hi Everyone,

I'm struggling to make a timer interrupt for my rotary encoder

I only use keil with my STM32F103

If it was working properly, I would expect my variable codeur to increase and the value to be written on the LCD

Do you have any idea where it comes from?

(everything else ie LCD and stepper motor are working well)

I'm not sure how to post code here so I put it into pastebin

https://pastebin.com/6na7c5t4

 

Thank you

2 REPLIES 2
Zt Liu
Senior III
Posted on July 01, 2017 at 13:38

Are you using update IT? Why not using input capture mode or simply Encoder mode?

AVI-crak
Senior
Posted on July 01, 2017 at 18:40

Two different solutions, one of them is wrong.

Stepper motor can not accelerate from zero to maximum speed in zero time. It takes time for a set of angular velocity.

You can control the step without controlling the time to move, as a game. During operation, an error will accumulate which can not be eliminated.

For smoother control of the stepper motor, it is necessary to take into account its angular speed dialing time. In this case, the position of the motor shaft will always catch up with the necessary position - but not instantaneously. This means reading the value of the encoder at a time when it is convenient for the program, the processing of the value and the correction of the position of the shaft of the stepper motor depends on its inertia.

You can quickly turn the knob of the encoder - the mechanic will work late, but without errors.

You can turn the knob of the encoder to one division - the mechanic will work as soon as the movement becomes possible physically.

I do not have time to learn HAL, it's much easier to write registers right away. But I can see that the interruption in your program is superfluous.

In encoder mode, the value is read directly from the timer counter, without interrupts.

It may be necessary to limit the maximum indication of the encoder, then interrupts will be needed. The free channels of the encoder timer are used for comparison by '0 +1' and by 'convenient number -1'. In the interrupt read the value of the counter, and if it went beyond - then adjust the value of the timer. The interrupt will trigger each time the encoder is manually rotated beyond the specified limits, the processing time will be minimal.