cancel
Showing results for 
Search instead for 
Did you mean: 

special incremental encoder reading

Muhammed Güler
Senior III

There is a very old machine that I want to remake.

I cannot change the machine's sensors. The incremental encoder of one of the motors produces a jitter-like signal below at position 0. How can I determine this in reading with a timer. I am using STM32f407

0693W0000059s90QAA.pngdiagram updated

4 REPLIES 4

Does this depict continuous movement to one direction, i.e. is the phase reversal we see on that picture due to real direction reversal, or is it also a feature of the encoder?

Also, what's the timing at the maximum RPM?

JW

Muhammed Güler
Senior III

I drew the signal incorrectly and fixed it. moving in one direction. it goes up to maximum 1.5KHz freq. When I tried to do it with an external interrup I missed the pals.

TDK
Guru

The STM32F4 timers can be used in encoder mode, which is meant for measuring exactly this.

0693W0000059sdeQAA.png 

You would hook up one signal to CH1 and the other to CH2 and configure the timer in encoder mode. Then read the CNT register value to get the current position.

If you feel a post has answered your question, please click "Accept as Solution".

You can't use the same timer for encoder mode and for the missing pulse detection, so you'll need to connect the input signals to multiple physical pins simultaneously.

For the missing pulse detection connect the lower (in diagram) signal to TIMx_ETR and the upper to TIMx_CH1 (choose timer where these signals don't share the same pin). Set up External Clock Mode 2, i.e. clock from ETR, and in SMCR set trigger to TI1FP1 and select Reset mode.

Now with regular pulses, this timer will count to 1 and gets reset, whereas at the missing pulse it will count to 2. So, set a different channel to Output Compare, and set the compare value to 2, and enable an interrupt on that compare. You can then count the missed pulse in that interrupt.

There will be corner cases at rotation stop/start/reversal, you'll need to cope with them separately in software.

JW