10.3 Register Configuration
The previous section briefly explored an MPLAB® Mindi™ simulation of a differential amplifier circuit. In this section, the relevant AVR DB OPAMP registers are configured to enable the differential amplifier configuration and operation. Two options are considered:
-
Positive inputs of the op amps are connected to the device’s input pins
-
The positive input of op amp n is connected to VDD divided by two, and op amp n+1 is connected to the DAC(1). This configuration is used in the accompanying code example.
MUXPOS | MUXNEG | MUXBOT | MUXWIP | MUXTOP | |
---|---|---|---|---|---|
OPn | INP | OUT | OFF | WIP0 | OFF |
OPn+1(1) | INP | WIP | LINKOUT | Setting determines gain | OUT |
MUXPOS | MUXNEG | MUXBOT | MUXWIP | MUXTOP | |
---|---|---|---|---|---|
OPn | VDDDIV2 | OUT | OFF | WIP0 | OFF |
OPn+1(1) | DAC | WIP | LINOUT | Setting determines gain | OUT |
- If n = 2 then OPn+1 is OP0.
0x00
and 0xB1
for OP0 and OP1,
respectively. This gives a gain of 3.OPAMP.OP0RESMUX = OPAMP_OP0RESMUX_MUXBOT_OFF_gc | OPAMP_OP0RESMUX_MUXWIP_WIP0_gc | OPAMP_OP0RESMUX_MUXTOP_OFF_gc; OPAMP.OP1RESMUX = OPAMP_OP1RESMUX_MUXBOT_LINKOUT_gc | OPAMP_OP1RESMUX_MUXWIP_WIP5_gc | OPAMP_OP1RESMUX_MUXTOP_OUT_gc;
OPAMP.OP0INMUX = OPAMP_OP0INMUX_MUXNEG_OUT_gc | OPAMP_OP0INMUX_MUXPOS_VDDDIV2_gc; OPAMP.OP1INMUX = OPAMP_OP1INMUX_MUXNEG_WIP_gc | OPAMP_OP1INMUX_MUXPOS_DAC_gc;
The voltage follower initialization code will look as follows:
void OPAMP_init () { /* Configure the Timebase */ OPAMP.TIMEBASE = OPAMP_TIMEBASE_US; /* Configure the voltage input range */ OPAMP.PWRCTRL = OPAMP_PWRCTRL_IRSEL_FULL_gc; /* Configure the OP0 */ OPAMP.OP0CTRLA = OPAMP_OP0CTRLA_OUTMODE_NORMAL_gc | OPAMP_ALWAYSON_bm; OPAMP.OP0INMUX = OPAMP_OP0INMUX_MUXNEG_OUT_gc | OPAMP_OP0INMUX_MUXPOS_VDDDIV2_gc; OPAMP.OP0RESMUX = OPAMP_OP0RESMUX_MUXBOT_OFF_gc | OPAMP_OP0RESMUX_MUXWIP_WIP0_gc | OPAMP_OP0RESMUX_MUXTOP_OFF_gc; OPAMP.OP0SETTLE = 0x7F; /* Configure the OP1*/ OPAMP.OP1CTRLA = OPAMP_OP1CTRLA_OUTMODE_NORMAL_gc | OPAMP_ALWAYSON_bm; OPAMP.OP1INMUX = OPAMP_OP1INMUX_MUXNEG_WIP_gc | OPAMP_OP1INMUX_MUXPOS_DAC_gc; OPAMP.OP1RESMUX = OPAMP_OP1RESMUX_MUXBOT_LINKOUT_gc | OPAMP_OP1RESMUX_MUXWIP_WIP5_gc | OPAMP_OP1RESMUX_MUXTOP_OUT_gc; OPAMP.OP1SETTLE = 0x7F; /* Enable OPAMP peripheral */ OPAMP.CTRLA = OPAMP_ENABLE_bm; /* Wait for the operational amplifiers to settle */ while ((OPAMP.OP0STATUS & OPAMP_SETTLED_bm) & (OPAMP.OP1STATUS & OPAMP_SETTLED_bm)) { ; } }
The code for this example is available in the differential-amplifier folder in these github repositories