Encoder blocks provide hardware-based position and velocity measurement using quadrature encoders, essential for motor control and motion feedback applications. The MPLAB Blockset offers dedicated encoder interfaces (QEI, PDEC, QDEC) that decode incremental encoder signals with zero CPU overhead, enabling precise position tracking and velocity calculation for motor control feedback loops.
| Device Family | Recommended Block | Alternative | Notes |
|---|---|---|---|
| dsPIC30F / 33F / 33E | QEI | ChangeNotification | QEI preferred for motor control |
| dsPIC33C / 33A | QEI | ChangeNotification | Enhanced QEI with improved filtering |
| SAM E5x / D5x / E7x / S7x / V7x | PDEC | QDEC_SAMx | PDEC preferred for angular output |
| SAM C20 / C21 / D20 / D21 | QDEC_SAMx | ChangeNotification | TC-based quadrature mode |
| PIC24 | ChangeNotification | - | No dedicated QEI on PIC24 |
| PIC32 | ChangeNotification | - | No dedicated QEI on PIC32 |
| Encoder Speed | Recommended Approach | Maximum PPR | Block Choice |
|---|---|---|---|
| < 1000 RPM | Software or Hardware | Up to 5000 PPR | ChangeNotification or QEI |
| 1000-5000 RPM | Hardware only | Up to 2048 PPR | QEI, PDEC, QDEC_SAMx |
| 5000-10000 RPM | Hardware with filtering | Up to 1024 PPR | QEI (4x mode), PDEC |
| > 10000 RPM | Hardware only, low PPR | Up to 512 PPR | QEI with digital filter |
PPR Calculation: Maximum edge frequency = (RPM × PPR × 4) / 60
| Application | Block Choice | Why? |
|---|---|---|
| 3-Phase FOC Motor Control | QEI (dsPIC) or PDEC (SAM) | Hardware velocity measurement, zero CPU overhead |
| Servo Positioning | QEI or PDEC | Index pulse support, high-resolution position |
| Robotic Joint | PDEC or QEI | Angular position output, multi-turn tracking |
| BLDC Sensorless + Encoder Backup | QEI or PDEC | Redundant position feedback |
| Low-Cost Motor Control | QDEC_SAMx | TC-based, available on entry-level SAM |
| Legacy Device Encoder | ChangeNotification | Software decoding, no dedicated peripheral needed |
Quadrature encoder signals:
Decoding Modes:
Direction Detection:
Position:
Position (counts) = Edge_Counter / 4 (for 4x mode)
Position (mechanical degrees) = (Position_counts / PPR) × 360°
Position (electrical degrees) = Position_mechanical × Pole_Pairs
Velocity:
RPM = (Delta_Position / Delta_Time) × 60 / PPR
Example:
- PPR = 1024
- Delta_Position = 5000 counts (in 4x mode)
- Delta_Time = 10 ms (0.01 s)
- RPM = (5000 / (1024 × 4)) / 0.01 × 60 = 7324 RPM
Hardware velocity measurement (QEI, PDEC):
| Encoder Type | Outputs | Voltage | Recommended Pull | Use Case |
|---|---|---|---|---|
| Push-Pull (TTL) | Active high/low | 5V or 3.3V | None | High-speed, short cables |
| Open Collector | Open drain | 5-24V | External pull-up (2.2kΩ - 10kΩ) | Industrial, long cables |
| Differential (RS-422) | A/A-, B/B- | 5V differential | Line receiver IC | Noisy environments, long cables (>10 m) |
Digital Filter (QEI/PDEC):
Hardware Recommendations:
Check:
Check:
Check:
Check:
| Encoder Block | dsPIC30F | dsPIC33F | dsPIC33E | dsPIC33C | dsPIC33A | PIC24 | PIC32 | SAM E5x | SAM E7x | SAM C2x |
|---|---|---|---|---|---|---|---|---|---|---|
| QEI | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| PDEC | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ |
| QDEC_SAMx | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ⚠️ | ⚠️ | ✅ |
| ChangeNotification | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
Legend: ✅ Full Support | ⚠️ Available but PDEC preferred | ❌ Not Available
Related Block Categories:
Application Notes:
Example Projects:
💡 Quick Selection Guide:
Change Notification - Pin State Change Interrupts and Timing Overview The MCHP_CN block provides an interface to the Change Notification (CN) …
Read more →Position Decoder - Hall Sensors and Stepper Motor Interface Overview The MCHP_PDEC block provides an interface to the Position Decoder (PDEC) …
Read more →Quadrature Decoder Using TC Modules - SAM Device Encoder Interface Overview The MCHP_QDEC_SAMx block implements quadrature encoder decoding using the …
Read more →Quadrature Encoder Interface - Position and Velocity Measurement Overview The MCHP_QEI block provides an interface to the Quadrature Encoder …
Read more →Software-based position calibration for QDEC encoders without physical index signal Overview The QDEC Calibration (Non-Index) block provides …
Read more →