(aature encoders at the time I didn't know that the PSOC4 could work with the TCPWM Quadrature decoder but I really enjoyed this circuit. It is a really good example of the digital logic power included on PSOC.
The great thing about this is that all the circuit logic is made via hardware that means there is no work required by the processor until the interrupt sequence is triggered this way processor load is reduced.
Here is a little simulation of how this works notice that on each case only one of the lights turns that would turn on the interrupt sequence for that pin.
How do Quadrature Encoders Work? (based on CUI inc encoder introduction):
Inside a rotary encoder there is a disc fixed to a shaft that is free to rotate. On one side of the disc is a signal source, on the other side a receiver. As the disc turns, the signal source is alternately allowed to pass and be blocked. When the signal is passed through the disc, an output pulse is generated.
In the illustration, signal A passes through the disc generating an output pulse. At the same time signal B is blocked and no output pulse is generated. The dotted line represents the position of the disc relative to the output pulses.
Depending on the turning direction the Channel A will be ahead or behind the channel B signal, these way the encoder can tell us which way is the shaft actually turning:
- In this example, Channel A leads B, i.e., Channel A outputs a signal before Channel B. This indicates the shaft is rotating counter-clockwise.
- In this example, Channel B leads A. This indicates the shaft is rotating clockwise.
Then depending on the total number of pulses or counts that the encoder wheel has we will have different resolutions. With the following calculations we can get speeds and distances:
Rotation Speed= (C/PPR)/(time/60) =revolutions per minute
Angle (deg) = (C/PPR)*360 deg = rotated angle
Where:
C= Counts
PPR = Total Pulses per revolution (depends on encoder)
time = time in seconds
The attached workspace can be tested with two LEDs the PSOC 4 pioneer kit makes it easy with the three integrated LEDs.
Comments