#include<adc.h> //utilize adc peripheral library
void initAdc1(void)
{
//Using the adc peripheral library, configure ADC1 as follows:
// 12-bit
// sample off of AN0
// Use dedicated ADC RC oscillator
// Automatically start new conversion after previous
// Use Avdd and Avss as reference levels
OpenADC1(
ADC_MODULE_OFF & ADC_AD12B_12BIT & ADC_FORMAT_INTG & ADC_CLK_AUTO & ADC_AUTO_SAMPLING_ON,
ADC_VREF_AVDD_AVSS & ADC_SCAN_OFF,
ADC_SAMPLE_TIME_31 & ADC_CONV_CLK_INTERNAL_RC,
ADC_DMA_BUF_LOC_1,
ENABLE_AN0_ANA,
ENABLE_ALL_DIG_16_31,
0,
0);
AD1CON1bits.ADON = 1; //Turn on ADC
}
void calc_Vout(void)
{
//Using a 5Vdd and the ADC in 12-bit mode, gives us a 3.3/4096 = around 806uV/step
Vout = ReadADC1(0)*0.0008056640625;
}