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.

Table 9-1. Non-Inverting PGA with Positive Input Connected to Internal DAC
MUXPOSMUXNEGMUXBOTMUXWIPMUXTOP
OPnDACWIP GNDSetting determines gainOUT
In the case of the non-inverting PGA, the resistor ladder multiplexer register will be configured to 0x75.
Figure 9-3. OPAMP.OPnRESMUX - Configure Resistor Ladder Multiplexer
OPAMP.OP0RESMUX =  OPAMP_OP0RESMUX_MUXBOT_GND_gc | OPAMP_OP0RESMUX_MUXWIP_WIP3_gc | OPAMP_OP0RESMUX_MUXTOP_OUT_gc;
In the non-inverting PGA code example accompanying this document, the output of the operational amplifier is connected to the negative input via the resistor ladder. The positive input of the operational amplifier is internally connected to the DAC output.
Figure 9-4. OPAMP.OPnINMUX - Configure the Input Multiplexer
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