The MCHP_PDEC block provides an interface to the Position Decoder (PDEC) peripheral on SAM E5x and E7x microcontrollers. Unlike traditional quadrature encoders, PDEC is optimized for Hall effect sensors (3-phase BLDC motors) and stepper motor position tracking, with specialized features for these applications. Key Features:
| Family | PDEC Module | Features |
|---|---|---|
| SAM E54/E53/E51 | 1 | Hall sensor, quadrature, stepper position |
| SAM E70/S70/V71 | 1 | Hall sensor, quadrature, stepper position |
| Parameter | Options | Description |
|---|---|---|
| Mode | • Quadrature Encoder | • Counter with direction |
| Parameter | Options | Description |
|---|---|---|
| Counter Output | on/off | Enable position counter output |
| Counter Datatype | unsigned/signed | Position counter sign |
| Revolution Output | on/off | Enable revolution counter |
| Revolution Datatype | unsigned/signed | Revolution counter sign |
| Counter Revolution Length | • Counter is 16-bit (9+7 bit resolution) | • Counter is 17-bit (9+8 bit resolution) |
| Parameter | Options | Description |
|---|---|---|
| Index | • Not used | • Reset counter |
| Max Counter Reset | Integer value | Modulo limit for position counter |
| Max Position Input | on/off | Enable dynamic modulo limit via block input |
| Reset Input | on/off | Enable external reset input |
| Pin | Function (Quadrature) | Function (Hall Sensor) |
|---|---|---|
| QDI0 | Phase A | Hall A |
| QDI1 | Phase B | Hall B |
| QDI2 | Index | Hall C |
| Parameter | Options | Description |
| Invert QDI0/1/2 | on/off | Invert input polarity |
| Swap Pin Phase A & B | on/off | Reverse direction (quadrature mode) |
| Auto Correction | on/off | Automatic phase error correction |
| Digital Filter | disabled or time period | Input signal filtering |
PDEC decodes 3-wire Hall sensor signals for BLDC motor position: Hall Sensor States (6-step commutation): State | Hall A | Hall B | Hall C | Sector ——-|——–|——–|——–|——– 1 | 0 | 0 | 1 | 0-60° 2 | 0 | 1 | 1 | 60-120° 3 | 0 | 1 | 0 | 120-180° 4 | 1 | 1 | 0 | 180-240° 5 | 1 | 0 | 0 | 240-300° 6 | 1 | 0 | 1 | 300-360° Valid transitions: 1→2→3→4→5→6→1 (CW) 1→6→5→4→3→2→1 (CCW)
// PDEC provides 9-bit angular resolution within each sector Angular_bits = 9; // Fixed 9-bit per sector (0-511) Sector = 0 to 5; // From Hall state// Total position = (Sector * 512) + Angular_position Counts_per_rev = 6 * 512 = 3072; // Convert to electrical angle Electrical_angle_deg = (Position_count / 3072) * 360; // For motor with 4 pole pairs: Mechanical_angle_deg = Electrical_angle_deg / 4;
// Control Register PDEC->CTRLA.bit.MODE = 0; // QDEC mode PDEC->CTRLA.bit.CONF = 1; // X4 quadrature (secure) PDEC->CTRLA.bit.PINEN = 0b111; // Enable all 3 inputs PDEC->CTRLA.bit.PINVEN = 0b000; // Invert mask PDEC->CTRLA.bit.SWAP = 0; // No pin swap PDEC->CTRLA.bit.PEREN = 1; // Enable period/modulo// Position Counter (16-bit) count = PDEC->COUNT.reg; // Current count (9-bit angular + N-bit revolution)// Angular position (9-bit within sector) angular = count & 0x1FF; // Lower 9 bits// Revolution counter (upper bits) revolution = count » 9; // Upper N bits// Period register (modulo limit) PDEC->CC[0].reg = max_position; // Position wraps at this value// Digital Filter PDEC->FILTER.bit.FILTER = filter_value; // 0=disabled, 1-255=filter clocks
Hardware: BLDC motor with 3 Hall sensors, 4 pole pairs
Configuration:
Configuration:
Configuration:
Configuration:
Causes:
Solutions:
Solution: Enable digital filter to suppress noise. Start with 1 µs filter period and increase if needed.
Solution: Enable “Swap Pin Phase A & B” to reverse counting direction.
Last Updated: 2024 | MCHP Blockset for MATLAB/Simulink