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.

A2D code for pic18f452

Status
Not open for further replies.

shlomo

Newbie level 3
Joined
Jun 11, 2015
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
18
Hi everyone/
I'm having a problem using A2D code with mplab c18 .

can anyone tell me if this part of example code is correct?
and if not, whats wrong?


int result;
......
......
......
result=ADRESH;
if(result==0xff)
{
PORTB=0xaa;
}
else
{
PORTB=0xbb;
}


Thanks

Shlomo
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,859
Helped
4,854
Reputation
9,726
Reaction score
4,640
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
126,485
The code isn't wrong but the 18F452 only has a 10-bit ADC. The lower 8 bits are returned in ADRESL and the upper 2 bits in ADRESH. That means ADRESH can never be equal to 0xFF. The maximum value it can hold is 0x03.

Brian.
 
  • Like
Reactions: shlomo

    shlomo

    Points: 2
    Helpful Answer Positive Rating

shlomo

Newbie level 3
Joined
Jun 11, 2015
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
18
Thank you Brian !

But I wrote in the code:

ADCON1=0x0E // ADFM (bit7)=0 ----> Left justified

Still not working.

Shlomo
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
Zip and post the complete MPLAB project files. We have to see full adc code to answer.
 

shlomo

Newbie level 3
Joined
Jun 11, 2015
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
18
Hi
I found my mistake in the a2d code.
The project is a thermometer using p18f452 and lm335,
The temperature value is sending to 2x16 lcd as string-
{"Temp -/+ xxx^C"}

I forgot to use the "#INCLUDE <STRING.H>"
:sad:

Now it's working good/

Shlomo
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top