2020-10-30 04:46 AM
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
diagram updated
2020-10-30 04:55 AM
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
2020-10-30 05:40 AM
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.
2020-10-30 06:22 AM
The STM32F4 timers can be used in encoder mode, which is meant for measuring exactly this.
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.
2020-10-30 03:15 PM
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