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.

Table 8-2. Voltage Follower with Positive Input Connected to Device’s Pin
MUXPOSMUXNEGMUXBOTMUXWIPMUXTOP
OPnINPOUT OFFWIP0OFF
Table 8-3. Voltage Follower with Positive Input Connected to Internal DAC
MUXPOSMUXNEGMUXBOTMUXWIPMUXTOP
OPnDACOUT OFFWIP0OFF
In the case of the Voltage follower, the resistor ladder multiplexer register will remain configured to 0x00.
Figure 8-4. OPAMP.OPnRESMUX - Configure Resistor Ladder Multiplexer
OPAMP.OP0RESMUX =  OPAMP_OP0RESMUX_MUXBOT_OFF_gc | OPAMP_OP0RESMUX_MUXWIP_WIP0_gc | OPAMP_OP0RESMUX_MUXTOP_OFF_gc;
In the voltage follower code example accompanying this document, the output of the op amp is connected to the negative input. The positive input of the op amp is internally connected to the DAC output.
Figure 8-5. OPAMP.OPnINMUX - Configure the Input Multiplexer
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