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.

How to initialize ADC for PIC18f4620?

Status
Not open for further replies.

ash_malon

Newbie level 4
Joined
Jan 19, 2012
Messages
7
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,325
how to intitialize ADC in PIC18f4620?

what is adcon1,adcon2,vref?
i'm planning to make a temperature sensor using lm35.. pls help me.. where do i start..

sorry for my english..
 

Tahmid

Advanced Member level 5
Joined
Jun 17, 2008
Messages
4,758
Helped
1,792
Reputation
3,576
Reaction score
1,651
Trophy points
1,393
Location
Silicon Valley, California, USA (from Dhaka, Bangl
Activity points
30,543

ash_malon

Newbie level 4
Joined
Jan 19, 2012
Messages
7
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,325
thank you very much..

when do i use ADCON1 or ADCON2 sir?

ADCON2 = 0x80; what is the meaning of "0x80"?

im using MikroC sir.. PIC18f4620.
 

Tahmid

Advanced Member level 5
Joined
Jun 17, 2008
Messages
4,758
Helped
1,792
Reputation
3,576
Reaction score
1,651
Trophy points
1,393
Location
Silicon Valley, California, USA (from Dhaka, Bangl
Activity points
30,543
0x80 means 80 in hexadecimal which is equal to 128 in decimal and 10000000 in binary.

I suggest you first download the datasheet for PIC 18F4620: ww1.microchip.com/downloads/en/DeviceDoc/39626b.pdf

Go to page 227 of the datasheet. There you have the ADCON2 register.
Writing 0x80 means you're commanding the ADC to display readings as right justified. Acquisition time is 0TAD, conversion clock is FOSC/2.

Go through the tutorials above and you should be able to understand everything clearly.

Hope this helps.
Tahmid.
 

ash_malon

Newbie level 4
Joined
Jan 19, 2012
Messages
7
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,325
sir can you please check what's wrong with my code?
the problem is i can't get the actual temperature.. for example The value of my LM35 is 31.0C in ISIS, but the output in virtual terminal is 31.2C..
27.0 c = 27.3 c
27.1 c = 27.3 c
27.2 c = 27.3 c
27.3 c = 27.3 c
27.4 c = 27.3 c
27.5 c = 27.8 c

void main() {
float temp,AdcTemp;
int IntegTemp1, IntegTemp2,DeciTemp;
ADCON2 = 0x82; // Configure analog inputs and Vref
TRISA = 0xFF; // PORTA is input
TRISB = 0x3F; // Pins RB7, RB6 are outputs
TRISD = 0; // PORTD is output
usart_init(9600);
delay_ms(500);


do {
AdcTemp= Adc_Read(2);
Temp = (AdcTemp*5000)/1023;
IntegTemp1 = (int) Temp*.01;
IntegTemp2 = (int) Temp*.1 - (IntegTemp1*10);
DeciTemp = (int) Temp*1 - (IntegTemp1*100+(IntegTemp2*10));

usart_write('T');
usart_write('E');
usart_write('M');
usart_write('P');
usart_write('=');
usart_write(IntegTemp1+48);
usart_write(IntegTemp2+48);
usart_write('.');
usart_write(DeciTemp+48);
usart_write(' ');
usart_write('C');
usart_write(13);
usart_write(10);
delay_ms(400);
} while(1);
}

the problem actually is the "DeciTemp". Please help sir.
 

Tahmid

Advanced Member level 5
Joined
Jun 17, 2008
Messages
4,758
Helped
1,792
Reputation
3,576
Reaction score
1,651
Trophy points
1,393
Location
Silicon Valley, California, USA (from Dhaka, Bangl
Activity points
30,543
This is because, LM35 provides an output with a guaranteed accuracy of 0.5°C. Expecting any better accuracy is useless. So, your reading has to vary by 0.5°C steps, not 0.1°C steps like your program does.

Hope this helps.
Tahmid.
 
Last edited:

ash_malon

Newbie level 4
Joined
Jan 19, 2012
Messages
7
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,325
so if i want better accuracy, i have to change my sensor(LM35)?
can you suggest other sensor for temperature sir...?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top