configuring multiple A to D Ports with the pic 18f4520

Questions and Comments on All Projects
Miguel Colmenares
Newbie Pyro
Posts: 2
Joined: Fri Dec 21, 2007 4:06 am

configuring multiple A to D Ports with the pic 18f4520

Postby Miguel Colmenares » Sat Feb 07, 2009 2:59 am

Hi Chris, I'm tryining to read in values from 2 identical pot's using the A to D on ports A0 and E0. I'm getting a max decimal vaue of around 800 for port A0 and around 550 for port E0. These values should be the same and ive tried everythig from switching ports to varying delays between each A to D initialization. I'm thinking that im either exeeding the 10 bit register or not clearing the bits before each initialization. The pot values range from 0 to 671ohm. I would be greatful if you had any advice on the matter. Here is a sample of my A/D code below............

#include <adc.h>
#include <p18f4520.h>
#include <delays.h>

int result1 = 0; // declare variable result
int result2 = 0; // declare variable result


void main(void)
{
TRISA = 0x01;
TRISC = 0x00;



while(1)
{

OpenADC(ADC_FOSC_32 & ADC_20_TAD & ADC_RIGHT_JUST, ADC_CH0 & ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS, 0);
Delay10TCYx( 50 ); // Delay for 50TCY
ConvertADC(); // Start conversion
while( BusyADC() ); // Wait for completion
result1 = ReadADC(); // Read result
CloseADC(); // Disable A/D converter

OpenADC(ADC_FOSC_32 & ADC_20_TAD & ADC_RIGHT_JUST, ADC_CH5 & ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS, 0);
Delay10TCYx( 50 ); // Delay for 50TCY
ConvertADC(); // Start conversion
while( BusyADC() ); // Wait for completion
result2 = ReadADC(); // Read result
CloseADC(); // Disable A/D converter

Delay10TCYx( 50 );
}

}

ThePyroElectro
PyroElectro Admin
Posts: 1181
Joined: Mon Nov 12, 2007 9:24 pm
Location: Earth
Contact:

Postby ThePyroElectro » Sat Feb 07, 2009 3:28 am

Hey Miguel,

A few things come to mind for this problem but my first thought is about your code.

I don't think the OpenADC function configures the TRISE bits so try configuring them properly for inputs on RE0, right now you only configure:
TRISA
TRISC

you'll also want to configure
TRISE

so that Channel 5 / AN5 / RE0 can be used as an input

Hopefully the solution is as simple as that.
Good to hear from you man! :D

andromilon3
Newbie Pyro
Posts: 1
Joined: Sat Mar 07, 2015 7:30 am

Re: configuring multiple A to D Ports with the pic 18f4520

Postby andromilon3 » Sat Mar 07, 2015 7:37 am

Most importantly,I wanted to design a countdown timer that will activates the servo control code. I have been search the web for days but hardly find any that I can understand. I knew that I will have to use the clock or timer in the chip to generate this countdown timer. Certkiller 1z0-060
Is there anyone that can help? any code sample or tutorials will help, thanks.


Return to “Projects”

Who is online

Users browsing this forum: No registered users and 2 guests