The MCHP_PGA block provides access to the Programmable Gain Amplifier (PGA) peripheral available in select dsPIC33C, dsPIC33CH, and dsPIC33CK devices. The PGA offers digitally-controlled gain settings with calibration capabilities, enabling precision signal conditioning for sensor inputs and ADC front-end applications.
Software-configurable gain: 1×, 2×, 4×, 8×, 16×, 32× (device-dependent)
Runtime gain adjustment via block input or register write
Offset and gain calibration registers for precision measurements
Direct connection to DACOUT pins or internal ADC inputs
Single-ended or differential input modes
Eliminates external amplifier circuits and reduces BOM cost
| Family | DOS Module | PGA Instances | Gain Range | Output Options |
|---|---|---|---|---|
| dsPIC33C/CH/CK | DOS_02291_PGA | 2 PGA channels | 1×, 2×, 4×, 8×, 16×, 32× | DACOUT1, DACOUT2, Internal |
Output Routing: PGA outputs can be routed to DACOUT pins (for external ADC or monitoring) or kept internal (for direct connection to on-chip ADC). The block automatically configures pin assignments based on your selection.
Configuration:
Configuration:
Configuration:
| Parameter | Options | Description |
|---|---|---|
| PGA1Gain | • Disabled | • Gain 1 (2⁰) |
| PGA1N_pin | • Ground (Single-Ended mode) | • PGA1N1 / Port / Pin[xx] |
| PGA1P_pin | • PGA1P1 / Port / Pin[xx] | • PGA1P2 / Port / Pin[xx] |
| PGA1Output | • on (Connect to DACOUT pin) | • off (Internal only) |
| PGA1Gain_BlockInput | • on (Dynamic gain control) | • off (Fixed gain) |
| PGA2Gain | (Same options as PGA1Gain) | Configuration for second PGA channel (PGA2). Independent gain control allows simultaneous processing of two sensor channels or cascaded gain stages. |
| PGA2N_pin, PGA2P_pin | (Similar to PGA1 pins) | Input pin selection for PGA2. Pin options are device-specific and displayed dynamically based on available hardware resources. |
| PGA2Output | • on (Connect to DACOUT pin) | • off (Internal only) |
| PGA2Gain_BlockInput | • on | • off |
| Fuse_FDEVOPT_DBCC | • on (Bridge mode) | • off (Independent) |
// PGA Control Register PGAxCON = (PGAEN « 15) | // PGA Enable (1 = enabled) (PGOEN « 14) | // Output Enable (1 = connect to DACOUTx) (SELPI « 11) | // Positive Input Select [2:0] (SELNI « 8) | // Negative Input Select [2:0] (GAIN « 0); // Gain Select [2:0] (0=1×, 1=2×, 2=4×, 3=8×, 4=16×, 5=32×) // Example: PGA1 with 8× gain, differential input, output enabled PGA1CON = 0x8B18; // 1000_1011_0001_1000 // Bit 15 (PGAEN) = 1 → PGA enabled // Bit 14 (PGOEN) = 0 → Output to DACOUT1 // Bits 13:11 (SELPI) = 001 → Positive input PGA1P1 // Bits 10:8 (SELNI) = 011 → Negative input PGA1N3 // Bits 2:0 (GAIN) = 011 → Gain = 2³ = 8×
Application: Temperature sensor with 0-100mV output // Configuration: // - PGA1Gain = “Gain 16 (2⁴)” // - PGA1P_pin = “PGA1P1 / RA0 / Pin[2]” (sensor output) // - PGA1N_pin = “Ground (Single-Ended mode)” // - PGA1Output = “off” (internal to ADC) // - PGA1Gain_BlockInput = “off” (fixed gain) // Hardware connections: // - Temperature sensor output (0-100mV) → PGA1P1 (RA0) // - PGA1 output (internal) → ADC_CH1 // Register configuration: PGA1CONbits.PGAEN = 1; // Enable PGA1 PGA1CONbits.PGOEN = 0; // Internal output only PGA1CONbits.SELPI = 1; // PGA1P1 selected PGA1CONbits.SELNI = 0; // Grounded (single-ended) PGA1CONbits.GAIN = 4; // 2⁴ = 16× gain // Signal chain: // Sensor: 0-100mV → PGA (16×) → 0-1.6V → ADC → Digital value // Full sensor range maps to 0-1.6V ADC input (within 0-3.3V range)
Application: Motor current measurement via shunt resistor // Configuration: // - PGA1Gain = “Gain 32 (2⁵)” (maximum amplification) // - PGA1P_pin = “PGA1P1 / RA0 / Pin[2]” (shunt high side) // - PGA1N_pin = “PGA1N1 / RA1 / Pin[3]” (shunt low side) // - PGA1Output = “off” (internal to ADC) // - PGA1Gain_BlockInput = “off” // Hardware: // - Motor → 0.01Ω shunt → Motor_GND // - Shunt voltage: 10A × 0.01Ω = 100mV (differential) // - PGA1P (high side) and PGA1N (low side) measure shunt voltage // Register configuration: PGA1CONbits.PGAEN = 1; // Enable PGA1 PGA1CONbits.PGOEN = 0; // Internal output PGA1CONbits.SELPI = 1; // PGA1P1 (shunt high) PGA1CONbits.SELNI = 1; // PGA1N1 (shunt low) PGA1CONbits.GAIN = 5; // 2⁵ = 32× gain // Current measurement: // Motor current: 10A → Shunt: 100mV → PGA: 3.2V → ADC // ADC reading × (3.3V/4096) / 32 / 0.01Ω = Motor current // Synchronization with PWM: // - Trigger ADC from PWM event // - Sample during PWM off-time for clean measurement // - Provides real-time current feedback for FOC algorithm
Application: Piezoelectric sensor with μV output // Configuration: // - PGA1: Gain 32× (first stage) // - PGA2: Gain 32× (second stage) // - Total gain: 32 × 32 = 1024× // PGA1 Configuration: // - PGA1Gain = “Gain 32 (2⁵)” // - PGA1P_pin = “PGA1P1 / RA0” (piezo sensor) // - PGA1N_pin = “Ground (Single-Ended mode)” // - PGA1Output = “on” → DACOUT1 (external connection to PGA2) // PGA2 Configuration: // - PGA2Gain = “Gain 32 (2⁵)” // - PGA2P_pin = “PGA2P1 / RB0” (connected to DACOUT1) // - PGA2N_pin = “Ground (Single-Ended mode)” // - PGA2Output = “off” (internal to ADC) // External connection: // DACOUT1 (PGA1 output) → PGA2P1 (wire or PCB trace) // Signal chain: // Piezo: 3mV → PGA1 (32×) → 96mV → PGA2 (32×) → 3.072V → ADC // Total gain: 1024× (60dB) // Note: Watch for noise pickup on DACOUT1 → PGA2P1 connection // Use short trace, ground plane, and decoupling capacitor
// Two-point calibration for PGA accuracy // Step 1: Zero-point calibration (offset correction) // Apply 0V to both PGA inputs (short P and N to ground) ADC_offset = ADC_Read(); // Measure output with 0V input // Store offset for subtraction during measurement // Step 2: Full-scale calibration (gain correction) // Apply known reference voltage (e.g., 1.000V from precision source) ADC_fullscale = ADC_Read(); // Measure output with known input gain_error = (ADC_fullscale - ADC_offset) / Expected_Value; // Store gain error for multiplication correction // Step 3: Apply calibration to measurements ADC_raw = ADC_Read(); ADC_calibrated = (ADC_raw - ADC_offset) / gain_error; Voltage_actual = ADC_calibrated × (Vref / 4096) / PGA_Gain;
Perform calibration at operating temperature for best accuracy
Store calibration data in EEPROM or Flash for persistence across power cycles
Re-calibrate periodically if drift is significant (e.g., every hour or temperature change)
Use high-precision reference voltage source for gain calibration (better than 0.1% accuracy)
Gain Selection Guidelines:
| Output Mode | Advantages | Disadvantages | Use Cases |
|---|---|---|---|
| Internal Only | (PGOEN = 0) | • Saves pins | • Lower noise |
| DACOUT Pin | (PGOEN = 1) | • External monitoring | • Drive external ADC |
| Issue | Possible Causes | Solution |
|---|---|---|
| No output signal | • PGAEN not set | • Incorrect pin selection |
| Output saturated (clipped) | • Gain too high | • Input signal too large |
| Incorrect gain | • Wrong GAIN bits | • Dynamic gain input error |
| Excessive noise | • High gain amplifying noise | • Poor PCB layout |
| DC offset error | • Input offset voltage | • No calibration |
| DACOUT1/2 conflict | • DBCC bridge enabled | • Both outputs trying to drive pin |