8.3 Register Configuration
The previous section briefly explored an MPLAB® Mindi™ simulation of a voltage follower circuit. In this section, the relevant AVR DB OPAMP registers are configured to enable the voltage follower configuration and operation. Two options are considered:
-
Positive input of the op amp is connected to the device’s input pin
-
Positive input of the op amp is internally connected to the output of the digital-to-analog converter (DAC). This configuration is used in the accompanying code example.
MUXPOS | MUXNEG | MUXBOT | MUXWIP | MUXTOP | |
---|---|---|---|---|---|
OPn | INP | OUT | OFF | WIP0 | OFF |
MUXPOS | MUXNEG | MUXBOT | MUXWIP | MUXTOP | |
---|---|---|---|---|---|
OPn | DAC | OUT | OFF | WIP0 | OFF |
0x00
.OPAMP.OP0RESMUX = OPAMP_OP0RESMUX_MUXBOT_OFF_gc | OPAMP_OP0RESMUX_MUXWIP_WIP0_gc | OPAMP_OP0RESMUX_MUXTOP_OFF_gc;
OPAMP.OP0INMUX = OPAMP_OP0INMUX_MUXNEG_OUT_gc | OPAMP_OP0INMUX_MUXPOS_DAC_gc;
The voltage follower 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_OUT_gc | OPAMP_OP0INMUX_MUXPOS_DAC_gc;
/* Configure the Op Amp n Resistor Wiper Multiplexer */
OPAMP.OP0RESMUX = OPAMP_OP0RESMUX_MUXBOT_OFF_gc | OPAMP_OP0RESMUX_MUXWIP_WIP0_gc | OPAMP_OP0RESMUX_MUXTOP_OFF_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
voltage-follower folder in these github repositories