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.

Table 10-2. Differential Amplifier with Positive Inputs Connected to Device’s Pins
MUXPOSMUXNEGMUXBOTMUXWIPMUXTOP
OPnINPOUT OFFWIP0OFF
OPn+1(1)INPWIPLINKOUTSetting determines gainOUT
Table 10-3. Differential Amplifier with Positive Inputs Connected to VDD Divided by Two and Internal DAC
MUXPOSMUXNEGMUXBOTMUXWIPMUXTOP
OPnVDDDIV2OUT OFFWIP0OFF
OPn+1(1)DACWIPLINOUTSetting determines gainOUT
Note:
  1. If n = 2 then OPn+1 is OP0.
In the case of the differential amplifier, the resistor ladder multiplexer registers will be configured to 0x00 and 0xB1 for OP0 and OP1, respectively. This gives a gain of 3.
Figure 10-4. OPAMP.OPnRESMUX - Configure Resistor Ladder Multiplexer
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;
In the differential amplifier code example accompanying this document, the positive input of OP0 is connected to VDD divided by two, and OP1 is connected to the DAC.
Figure 10-5. OPAMP.OPnINMUX - Configure the Input Multiplexer
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