The QDEC decodes the output from an incremental motion encoder by sampling the QDEC phase input pins (A and B).
The off-chip quadrature encoder is an incremental motion encoder outputting two waveforms, phase A and phase B. The two output waveforms are always 90 degrees out of phase, meaning that one always changes level before the other. The direction of movement is indicated by the waveform that changes level first. Invalid transitions may occur, meaning the two waveforms simultaneously switch. This may occur if the wheel rotates too fast relative to the sample rate set for the decoder.
The QDEC decodes the output from the off-chip encoder by sampling the QDEC phase input pins (A and B) at a fixed rate as specified in the SAMPLEPER register.
If the SAMPLEPER value needs to be changed, the QDEC shall be stopped using the STOP task. SAMPLEPER can be then changed upon receiving the STOPPED event, and QDEC can be restarted using the START task. Failing to do so may result in unpredictable behavior.
It is good practice to only change registers LEDPOL, REPORTPER, DBFEN, and LEDPRE when the QDEC is stopped.
When started, the decoder continuously samples the two input waveforms and decodes these by comparing the current sample pair (n) with the previous sample pair (n-1).
The decoding of the sample pairs is described in the table below.
| Previous sample pair(n - 1) | Current samples pair(n) | SAMPLE register | ACC operation | ACCDBL operation | Description | ||
|---|---|---|---|---|---|---|---|
| A | B | A | B | ||||
| 0 | 0 | 0 | 0 | 0 | No change | No change | No movement |
| 0 | 0 | 0 | 1 | 1 | Increment | No change | Movement in positive direction |
| 0 | 0 | 1 | 0 | -1 | Decrement | No change | Movement in negative direction |
| 0 | 0 | 1 | 1 | 2 | No change | Increment | Error: Double transition |
| 0 | 1 | 0 | 0 | -1 | Decrement | No change | Movement in negative direction |
| 0 | 1 | 0 | 1 | 0 | No change | No change | No movement |
| 0 | 1 | 1 | 0 | 2 | No change | Increment | Error: Double transition |
| 0 | 1 | 1 | 1 | 1 | Increment | No change | Movement in positive direction |
| 1 | 0 | 0 | 0 | 1 | Increment | No change | Movement in positive direction |
| 1 | 0 | 0 | 1 | 2 | No change | Increment | Error: Double transition |
| 1 | 0 | 1 | 0 | 0 | No change | No change | No movement |
| 1 | 0 | 1 | 1 | -1 | Decrement | No change | Movement in negative direction |
| 1 | 1 | 0 | 0 | 2 | No change | Increment | Error: Double transition |
| 1 | 1 | 0 | 1 | -1 | Decrement | No change | Movement in negative direction |
| 1 | 1 | 1 | 0 | 1 | Increment | No change | Movement in positive direction |
| 1 | 1 | 1 | 1 | 0 | No change | No change | No movement |