I am trying to amplify an input signal of 500 uV Vp-p and when i saw the output it was generating a spike going from 65000 and 0. The output looks how an unstable amplifier behaves. This happens even if I don't apply the signals. This is the code I have used to make the PGA work. Also I don't have good idea on how to select the Vref for the PGA. As of now my ADC0 is connected to external Vref.
This is done to enable the PGA
ADC0_PGA = 0x960000;
// intialise the adc0
SIM_SCGC6 |= SIM_SCGC6_ADC0_MASK; //Gives clock to ADC0
ADC0_CFG1 = (ADC_CFG1_MODE(3) | ADC_CFG1_ADIV(2)); //16bit mode
ADC0_SC1A = ADC_SC1_ADCH(31); //disable module
/* Configure ADC pins as ADC Inputs manually */
/*In Kinetis the ADC pins are ADC inputs by default */
// Function used to get the adc value
unsigned short ADC0_Read16b(unsigned char channelNumber)
ADC0_SC1A = 0x22; /* Write to ADCSC1 to start conversion */
while (!(ADC0_SC1A & 0xA2)); /* Wait until the conversion is complete */
Input is connected to PGA0_DP0 and PGA0_DM0 is connected to ground. ADC0 channel 2 is used to capture the signal .
Help me out with this one. Thanks in advance.