9.3 Register Configuration
The previous section briefly explored an MPLAB® Mindi™ simulation of a non-inverting programmable gain amplifier circuit. In this section, the relevant AVR DB OPAMP registers are configured to enable the non-inverting PGA configuration and operation as follows:
-
Positive input of the op amp is connected to the output of the internal digital to analog converter (DAC)
-
Negative input of the op amp is connected to the wiper position of the internal resistor ladder
-
Bottom part of the resistor ladder is connected to ground. The wiper position determines the gain, and the top part of the resistor ladder is connected to the output of the op amp.
Table 9-1 summarizes the necessary settings to set one of the internal op amps in a non-inverting PGA configuration.
MUXPOS | MUXNEG | MUXBOT | MUXWIP | MUXTOP | |
---|---|---|---|---|---|
OPn | DAC | WIP | GND | Setting determines gain | OUT |
0x75
.OPAMP.OP0RESMUX = OPAMP_OP0RESMUX_MUXBOT_GND_gc | OPAMP_OP0RESMUX_MUXWIP_WIP3_gc | OPAMP_OP0RESMUX_MUXTOP_OUT_gc;
OPAMP.OP0INMUX = OPAMP_OP0INMUX_MUXNEG_WIP_gc | OPAMP_OP0INMUX_MUXPOS_DAC_gc;
The non-inverting PGA initialization code will look as follows:
void OPAMP0_init (void)
{
/* Configure the Timebase */
OPAMP.TIMEBASE = OPAMP_TIMEBASE_US;
/* Configure the voltage input range */
OPAMP.PWRCTRL = OPAMP_PWRCTRL_IRSEL_FULL_gc;
/* Configure the Op Amp n Control A */
OPAMP.OP0CTRLA = OPAMP_OP0CTRLA_OUTMODE_NORMAL_gc | OPAMP_ALWAYSON_bm;
/* Configure the Op Amp n Input Multiplexer */
OPAMP.OP0INMUX = OPAMP_OP0INMUX_MUXNEG_WIP_gc | OPAMP_OP0INMUX_MUXPOS_DAC_gc;
/* Configure the Op Amp n Resistor Wiper Multiplexer */
/* WIP3 => R1 = 8R, R2 = 8R */
/* Gain = 1 + R2/R1 = 2 */
OPAMP.OP0RESMUX = OPAMP_OP0RESMUX_MUXBOT_GND_gc | OPAMP_OP0RESMUX_MUXWIP_WIP3_gc | OPAMP_OP0RESMUX_MUXTOP_OUT_gc;
/* Configure the Op Amp n Settle Time*/
OPAMP.OP0SETTLE = 0x7F;
/* Enable OPAMP peripheral */
OPAMP.CTRLA = OPAMP_ENABLE_bm;
/* Wait for the operational amplifiers to settle */
while (OPAMP.OP0STATUS & OPAMP_SETTLED_bm)
{
;
}
}
The code for this example is available in the
non-inverting-pga folder in these github repositories