11.3 Register Configuration

The previous section briefly explored an MPLAB® Mindi™ simulation of an instrumentation amplifier circuit. In this section, the relevant AVR DB OPAMP peripheral registers are configured to enable the instrumentation amplifier topology and operation as follows:

  • OP0 op amp is set up as a voltage follower, with the positive input is connected internally to VDD/2. The top side of the resistor ladder is connected to the output of the op amp, the bottom side to ground, and the wiper position is selected accordingly to the Table   1.
  • OP1 op amp is constructed as a voltage follower, with the positive input internally connected to the on-board DAC. The resistor ladder is not used.
  • OP2 op amp is set up to have as positive input the wiper connection from the OP0 resistor ladder and as negative input the wiper position of its resistor ladder. The topside of the resistor ladder is connected to the output of the op amp, the bottom side to the OP1 op amp and the wiper position is selected accordingly to Table   1.

Table 11-2 summarizes the necessary settings to set the three internal op amps in an instrumentation amplifier configuration.

Table 11-2. Instrumentation Amplifier Connected to Internal DAC
MUXPOSMUXNEGMUXBOTMUXWIPMUXTOP
OP0VDD/2OUT GNDSee the table belowOUT
OP1DACOUTOFFWIP0OFF
OP2LINKWIP (OP0WIP)WIPLINKOUT (OP1OUT)See the table belowOUT

In the case of the instrumentation amplifier, the resistor ladder multiplexer register will be configured separately for each amplifier.
Figure 11-5. OPAMP.OPnRESMUX - Configure Resistor Ladder Multiplexer
OPAMP.OP0RESMUX =  OPAMP_OP0RESMUX_MUXBOT_GND_gc | OPAMP_OP0RESMUX_MUXWIP_WIP2_gc | OPAMP_OP0RESMUX_MUXTOP_OUT_gc;
OPAMP.OP1RESMUX = OPAMP_OP1RESMUX_MUXBOT_OFF_gc | OPAMP_OP1RESMUX_MUXWIP_WIP0_gc | OPAMP_OP1RESMUX_MUXTOP_OFF_gc;
OPAMP.OP2RESMUX = OPAMP_OP2RESMUX_MUXBOT_LINKOUT_gc | OPAMP_OP2RESMUX_MUXWIP_WIP5_gc | OPAMP_OP2RESMUX_MUXTOP_OUT_gc;
The same goes for the positive and negative inputs for each amplifier. They need to be separately configured, as outlined in Table 11-2.
Figure 11-6. OPAMP.OPnINMUX - Configure the Input Multiplexer
OPAMP.OP0INMUX = OPAMP_OP0INMUX_MUXNEG_OUT_gc | OPAMP_OP0INMUX_MUXPOS_VDDDIV2_gc;
OPAMP.OP1INMUX = OPAMP_OP1INMUX_MUXNEG_OUT_gc | OPAMP_OP1INMUX_MUXPOS_DAC_gc;
OPAMP.OP2INMUX = OPAMP_OP2INMUX_MUXNEG_WIP_gc | OPAMP_OP2INMUX_MUXPOS_LINKWIP_gc;

The instrumentation amplifier initialization code will look as follows:

void OPAMP_init (void)
{
    /* 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_GND_gc | OPAMP_OP0RESMUX_MUXWIP_WIP2_gc | OPAMP_OP0RESMUX_MUXTOP_OUT_gc;
    OPAMP.OP0SETTLE = 0x7F;

    /* Configure the OP1*/
    OPAMP.OP1CTRLA = OPAMP_OP1CTRLA_OUTMODE_NORMAL_gc | OPAMP_ALWAYSON_bm;
    OPAMP.OP1INMUX = OPAMP_OP1INMUX_MUXNEG_OUT_gc | OPAMP_OP1INMUX_MUXPOS_DAC_gc;
    OPAMP.OP1RESMUX = OPAMP_OP1RESMUX_MUXBOT_OFF_gc | OPAMP_OP1RESMUX_MUXWIP_WIP0_gc | OPAMP_OP1RESMUX_MUXTOP_OFF_gc;
    OPAMP.OP1SETTLE = 0x7F;

    /* Configure the OP2*/
    OPAMP.OP2CTRLA = OPAMP_OP2CTRLA_OUTMODE_NORMAL_gc | OPAMP_ALWAYSON_bm;
    OPAMP.OP2INMUX = OPAMP_OP2INMUX_MUXNEG_WIP_gc | OPAMP_OP2INMUX_MUXPOS_LINKWIP_gc;
    OPAMP.OP2RESMUX = OPAMP_OP2RESMUX_MUXBOT_LINKOUT_gc | OPAMP_OP2RESMUX_MUXWIP_WIP5_gc | OPAMP_OP2RESMUX_MUXTOP_OUT_gc;
    OPAMP.OP2SETTLE = 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) && 
            (OPAMP.OP2STATUS & OPAMP_SETTLED_bm))
    {
        ;
    }
}

The code for this example is available in the instrumentation-amplifier folder in these github repositories