Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

problem with PIC18F4550 A/D, only reads half scale

Status
Not open for further replies.

elrayes

Full Member level 5
Joined
Jun 3, 2008
Messages
244
Helped
20
Reputation
40
Reaction score
7
Trophy points
1,298
Location
Egypt/Canada
Activity points
2,777
Hi

I'm facing very weird problem with PIC18F4550 internal 10 bits A/D, I did set the Vref and -Vref to VDD and VSS, chose channel 0, but the maximum voltage the A/D can read was 2.5 volts (code: 511), which mean half the scale expected, can anyone give me a logical reason why this happen, this is the code I used:
unsigned char low,high;

//set port A as input
TRISA = 0xFF;
//ADCON0 -> select channel AN0 and enable A/D
ADCON0 = 0b00000001;
//ADCON1 -> set Vref+ and Vref- to VDD and VSS and set AN0 only to analog input
ADCON1 = 0b00001110;
//ADCON2 -> result right justified, Acquisition time = 6TAD, sampling clock FOSC/64
ADCON2 = 0b10011000;
SetChanADC(ADC_CH0);
ConvertADC();
while(BusyADC());
PIR1bits.ADIF = 0; //clear ADC interrupt flag
low = ADRESL;
high = ADRESH;

waiting to hear from you
thanks
 

Hi,

Am not into C, but try setting Adcon1 first, then Adcon2 and Adcon0 last.
Adcon1 defines the port use which should be set before anything else, you are enabling ADC before any other ADC parameters are set

You can also check your adc parameters with this handy utility


Document Details | PICMultiCalc (Great PIC Calculator)
 

Nothing happened :(
Actually this code is embedded with USB CDC firmware from microchip, dunno either the problem is a conflict between USB and the A/D settings or whats going on....

Anyway thanks for your help.
 

Try to wait some time between selecting channel and starting AD conversion.

Basicly when you select channel, MCU connect physical input pin via internal resistor to sample capacitor.
So if next command is AD conversion then capacitor, can't have input voltage because of RC time for loading .....

Try this:

unsigned char a;
...

SetChanADC(ADC_CH0);
a = 0;
while(++a<10){
}
ConvertADC();

or any of 100 ways to wait some time before conversion.

Mr.Cube
 
Last edited:

Nothing changed, the same problem, any voltage more than 2.5v cannot be converted or read, its now working as 9 bits A/D with dynamic range 0 - 2.5v only, any voltage more than 2.5v just read it "511", if the input voltage exceeds 5v the A/D starts to give readings from "0", so far lost half of the dynamic range or something wrong with the my code.

---------- Post added at 23:10 ---------- Previous post was at 22:43 ----------

the problem was in the clock of the A/D (FOSC) value in register ADCON2, when I set it to FOSC/2, did the previous behavior I discussed, but when I changed it to less value (FOSC/32 or FOSC/64) worked fine.

Thanks all for your help and advice.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top