5.1.1 Inverting Amplifier Setup

Inverting Amplifier Setup

void InvertingSetup(void)
{
    OPA1CON0 = 0x00;
    OPA1CON1 = 0x00;
    
    OPA1CON1bits.RESON = 1;
    OPA1CON1bits.GSEL = 0b101;  //Gain of 3
    
    //Select OPA1IN0- as the input
    OPA1CON1bits.NSS = 0b000;   
    
    OPA1CON2 = 0x00;
    
    //Connect the inverting input to the resistor ladder
    OPA1CON2bits.NCH = 0b001;   
    
    //Connect the non-inverting input to Vdd/2
    OPA1CON2bits.PCH = 0b011;
    
    OPA1CON3 = 0x00;
    
    //Enable internal feedback
    OPA1CON3bits.FMS = 0b10;
    
    //Enable the Module
    OPA1CON0bits.EN = 1;
}