jemonlemon
Newbie
Hello,
I am an ECE student working with the PIC33F and I am having some difficult getting the ADC to work. I want to read the voltage from the AN1 pin and I made sure that the AN1 pin is getting a selected voltage between 0-3.3V.
I followed the instructions on the Mircochip manual, I feel as I missed some steps as I cannot get the ADC functioning.
Here is what I have for my initialization:
Here is what is in my main.c:
While debugging, I find that when the voltage at AN1 is near 0, the ADCValue equals 32768.0. When the voltage is higher than 1, it gives 32848.0. When voltage is around 0.5, it gives 32816.0. If anyone has some insight, I greatly appreciate it.
Thank you in advance.
I am an ECE student working with the PIC33F and I am having some difficult getting the ADC to work. I want to read the voltage from the AN1 pin and I made sure that the AN1 pin is getting a selected voltage between 0-3.3V.
I followed the instructions on the Mircochip manual, I feel as I missed some steps as I cannot get the ADC functioning.
Here is what I have for my initialization:
Code:
void ADC_Init()
{
TRISAbits.TRISA1 = 1;
AD1CON1bits.ADON = 0;
AD1CON1bits.ADSIDL = 0;
AD1CON1bits.AD12B = 1;
// a) Select port pins as analog inputs
AD1PCFGL = 0;
// b) Select voltage reference source
AD1CON2bits.VCFG = 0;
// c) Select analog conversion clock
AD1CON3bits.ADCS = 0;
// d) Determine how many S/H channels is used
AD1CON2bits.CHPS = 0;
// e) Select the appropriate sample/conversion sequence
AD1CON1bits.SSRC = 0b000;
AD1CON3bits.SAMC = 0;
// f) Select how conversion results are presented in the buffer
AD1CON1bits.FORM = 0b11;
// g) Turn on ADC module
AD1CON1bits.ADON = 1;
}
Here is what is in my main.c:
Code:
int main() {
...
// Retrieve voltage
AD1CON1bits.SAMP = 1;
_delay_us(10);
AD1CON1bits.SAMP = 0;
while(!AD1CON1bits.DONE);
double ADCValue = ADC1BUF0;
...
}
While debugging, I find that when the voltage at AN1 is near 0, the ADCValue equals 32768.0. When the voltage is higher than 1, it gives 32848.0. When voltage is around 0.5, it gives 32816.0. If anyone has some insight, I greatly appreciate it.
Thank you in advance.
Last edited: