5.2.1 Non-Inverting Amplifier Setup

Non-Inverting Amplifier Setup

void NonInvertingSetup(void)
{
    OPA1CON0 = 0x00;
    OPA1CON1 = 0x00;
    OPA1CON1bits.RESON = 1;
    OPA1CON1bits.GSEL = 0b011;  //Gain of 2
    
    //Ground the resistor ladder
    OPA1CON1bits.NSS = 0b111;
    
    OPA1CON2 = 0x00;
    
    //Connect the inverting input to the resistor ladder
    OPA1CON2bits.NCH = 0b001; 
    
    //Connect the Non-inverting input to OPA1IN+
    OPA1CON2bits.PCH = 0b010;
    
    OPA1CON3 = 0x00;
    
    //Select OPA1IN0+ as the input
    OPA1CON3bits.PSS = 0b00;
    
    //Use internal feedback
    OPA1CON3bits.FMS = 0b10;
    
    //Enable the Module
    OPA1CON0bits.EN = 1;
}