hi to all
in my project im using pic16f873a,hi-tech c compiler.im reading adc value data=ADRESH;.and
i
but the
adc i/p value 2v means 2000 mv/4.88mv=adc value is 409.
im use the 409 value means im not get o/p.
Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
if(data>=409){
led=0;
led1=1;}
again i divide 4409/4=102 this value used means i get the out put in 2v.
f(data>=102){
led=0;
led1=1;}
what i mistake in my program?
pls help me .
thanks in advance
Your micro contains 10bit ADC. If PCFG3CFG0: A/D Port Configuration Control bits are supplied with 0000(ADCON1 register) then Vref+ will be connected to VDD and Vref- to Vss. Suppose the supply voltage (Vdd) is 5V DC. Now for 5 volt analog input the output will be 1024. Resolution 4.883mV. For 2 V the output will be 410(409.5).
---------- Post added at 20:30 ---------- Previous post was at 20:22 ----------
ADC output 102 means (102*5000)/1024 mV=498mV=0.5V(approx)
void main(void){
ADCON0=0b10000000;
ADCON1=0b11000000;
ADCON0.ADON=1;// turn on the A2D conversion module
Delay_ms(300);
LCD_init();while(1){
Delay_ms(300);
read_adc();------------}void read_adc(void){int result;
ADCON0.GO=1;//ADC startwhile(ADCON0.GO==1);
result=ADRESH;
result=result<<8;//shift to left for 8 bit
result=result|ADRESL;//10 bit result from ADC}
---------- Post added at 12:49 ---------- Previous post was at 12:42 ----------
The ADRESH:ADRSEL registers contain the 10 bit result of the A/D conversion.
---------- Post added at 13:32 ---------- Previous post was at 12:49 ----------
hi thanks to u
but i can't unterstaand theese lines
(result=result<<8; //shift to left for 8 bit
result=result|ADRESL; //10 bit result from ADC).pls explain
and how to use another one adc channel in this program.?
pls explain me.
thanks in advance
Suvaraj,
Hope you understand now. Vinod has given a very informative step by step description above. If you use PIC16F873A then it will be applicable to your case too. Because on the fist page of the datasheet, PIC16F87X was written.
Suvaraj,
Hope you understand now. Vinod has given a very informative step by step description above. If you use PIC16F873A then it will be applicable to your case too. Because on the fist page of the datasheet, PIC16F87X was written.
Yes it is possible to accept data from more than one channels one by one.
You can use CHS2:CHS0: Analog Channel Select bits of ADCON0 to select different values as per datasheet to select different pins as analog input (keeping in mind PCFG3CFG0: A/D Port Configuration Control bits, better set them as 0000) and accept input from that pin.
Remember :- The PIC16F873A/876A devices only implement A/D channels 0 through 4; the unimplemented selections are reserved. Do not select any unimplemented channels with these devices.
And remember, The analogue inputs have a sample and hold circuit built in, this requires an internal capacitor to charge to the incoming voltage. If the source impedance is high, this takes longer to do, so the capacitor isn't fully charged when you take your reading.
So longer time delay may be needed between to readings.
I dont have ready code but I can suggest you a pseudocode.
---------- Post added at 21:52 ---------- Previous post was at 21:42 ----------
void main(void){
ADCON0=0b10000000;//Select Channel 0 (AN0)
ADCON1=0b11000000;
ADCON0.ADON=1;// turn on the A2D conversion module
Delay_ms(300);
LCD_init();while(1){
Delay_ms(300);
read_adc();//Read from Channel 0 (AN0)-----------------
Delay_ms(300)// <- this is importent
ADCON0=0b10001000;//Select Channel 1 (AN1)
ADCON0.ADON=1;// turn on the A2D conversion module
read_adc();//Read from read_adc(); //Read from-----------------------------
Delay_ms(300)// <- this is importent if you want to change channel again(say by going to the top of the loop}void read_adc(void){int result;
ADCON0.GO=1;//ADC startwhile(ADCON0.GO==1);
result=ADRESH;
result=result<<8;//shift to left for 8 bit
result=result|ADRESL;//10 bit result from ADC}