2017-06-30 02:46 AM
Hi Everyone,
I'm struggling to make a timer interrupt for my rotary encoderI only use keil with my STM32F103If 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
Thank you
2017-07-01 04:38 AM
Are you using update IT? Why not using input capture mode or simply Encoder mode?
2017-07-01 09:40 AM
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.