I'm using PIC 16F73 Microcontroller and I have connected the analog input to RA2 i.e channel 2. The problem is in the examples it shows something like
ADCON1=$82 ( binary eqlnt : 10000010 )
My question is when I using channel 2 how to configure the analog inputs and digital inputs to port A. When I read the datasheet of 16f73 ( ADCON0 and ADCON1 section ). They give something like below that I cannot understand. Can anyone please explain this core thing for a begineer like me???
I have read several posts, but nothing seems to be fit for the begineer who learns Mikrobasic and Microcontroller.
ADCON0 Register:
000 = Channel 0 (RA0/AN0)
001 = Channel 1 (RA1/AN1)
010 = Channel 2 (RA2/AN2)
011 = Channel 3 (RA3/AN3)
100 = Channel 4 (RA5/AN4)
101 = Channel 5 (RE0/AN5)(1)
110 = Channel 6 (RE1/AN6)(1)
111 = Channel 7 (RE2/AN7)(1)
ADCON1 Register:
PCFG2:PCFG0 RA0 RA1 RA2 RA5 RA3 RE0(1) RE1(1) RE2(1) VREF
000 A A A A A A A A VDD
001 A A A A VREF A A A RA3
010 A A A A A D D D VDD
011 A A A A VREF D D D RA3
100 A A D D A D D D VDD
101 A A D D VREF D D D RA3
11x D D D D D D D D VDD
Need Assistance With ADCON0 and ADCON1 registers
-
- Posts: 231
- Joined: 14 Nov 2004 19:43
Please stop posting so many threads. ADCON like most the other registers you write to them a value of a byte. For example ADCON0 = %00000000 clears all the bits of the byte. Each bit of the byte controls something different to do with ADOCON0. If you want to use channel 2, you would use the bits 010 is the correct place.
the ADCON0 Register you do not need to wory about mikrobasic will take care of that
to set up the A2D mod for 2 Analog chans and the rest digital you need to look at data sheet and see what combination fits best
100 = A0 A1 A2 A3 A5
a a d a d
is the closest unless u want to loose use of A3 pin, so having cleared the PortA reg and seting the TrisA reg for i/o direction (Analog inputs need to be 1 to be inputs) you then write to ADCON1 reg to chose the pins
PORTA = 0 ' clear port latch
TRISA = %111111 ' all inputs
ADCON1 = %100 ' set AN0,AN1,AN3 Analog ,AN2 AN4 digital
x = Adc_Read(0) ' this line configures ADCON0 for you like magic
y = Adc_Read(1) ' this line configures ADCON0 for you like magic
thats about it realy hope it helps
to set up the A2D mod for 2 Analog chans and the rest digital you need to look at data sheet and see what combination fits best
100 = A0 A1 A2 A3 A5
a a d a d
is the closest unless u want to loose use of A3 pin, so having cleared the PortA reg and seting the TrisA reg for i/o direction (Analog inputs need to be 1 to be inputs) you then write to ADCON1 reg to chose the pins
PORTA = 0 ' clear port latch
TRISA = %111111 ' all inputs
ADCON1 = %100 ' set AN0,AN1,AN3 Analog ,AN2 AN4 digital
x = Adc_Read(0) ' this line configures ADCON0 for you like magic
y = Adc_Read(1) ' this line configures ADCON0 for you like magic
thats about it realy hope it helps
there are 10 types of people Those that understand binary and those that dont
hi
Thanks for your reply guys and extremly sorry for posting threads. The reason is that I'm a begineer and I'm quite curious to know what that exactly means. I posted this after I a long time since I was searching over the internet.
I'm tired of trying up with the seven segment. I tried using PIC 16F72 with the ADC on LCD example. Everything seems to be ok. But the analog voltage displayed is too low when compared with the original. i.e the voltage I read on the LCD is 1.25 but when I measure it it shows 4.xx. Is there any modifications that I do to make the program run using should 16F72 ???
-
- Posts: 573
- Joined: 25 Apr 2006 15:39
- Location: Cape Town, South Africa
Hey arunkish,
Beginners can be excused for many things, just don't act like a beginner too long
The AD part of the pic is quite accurate, but you HAVE to set up the Vref+ and Vref- in your config word.
Look at the datasheet, and you will see that you can either reference to yor supply rails, or external voltages, or both.
Your input voltage must never exceed the the reference voltage in any direction, and if you use the default supply rail as reference, and it is for argument's sake 5.5V, then you need to input 5.5V to display the correct voltage.
You can scale the reading in software, but if your intial readings are way off like yours, you have a circuit problem, configuration problem, or software problem, sorry
This is what I use on a 16F877A to set up all 8 ports as analogue....
Good Luck
Beginners can be excused for many things, just don't act like a beginner too long
The AD part of the pic is quite accurate, but you HAVE to set up the Vref+ and Vref- in your config word.
Look at the datasheet, and you will see that you can either reference to yor supply rails, or external voltages, or both.
Your input voltage must never exceed the the reference voltage in any direction, and if you use the default supply rail as reference, and it is for argument's sake 5.5V, then you need to input 5.5V to display the correct voltage.
You can scale the reading in software, but if your intial readings are way off like yours, you have a circuit problem, configuration problem, or software problem, sorry
This is what I use on a 16F877A to set up all 8 ports as analogue....
Good Luck
Code: Select all
OPTION_REG = $80
ADCON1 = $82 ' configure VDD as Vref, and analog channels
"Copy'nPaste"
-
- Posts: 573
- Joined: 25 Apr 2006 15:39
- Location: Cape Town, South Africa
hi copynpaste
I started learning some stuff long ago and I stopped it since I had some exams and I'm back to it again that's y i said that I'm a begineer.
Here is what I did
To make the adconLCD2 program in the examples folder for PIC16F877 work with PIC16F73 I modified the code as follows and it worked fine.
CurrentValue = ADC_read(2) ' get ADC value from channel No.2
if CurrentValue <> LastValue then ' perform conversion only if they are different
rrrr = CurrentValue*(20000.0/1024.0)' 5 Volts over 1024 levels (10-bit conversion)
Here is what I did
To make the adconLCD2 program in the examples folder for PIC16F877 work with PIC16F73 I modified the code as follows and it worked fine.
CurrentValue = ADC_read(2) ' get ADC value from channel No.2
if CurrentValue <> LastValue then ' perform conversion only if they are different
rrrr = CurrentValue*(20000.0/1024.0)' 5 Volts over 1024 levels (10-bit conversion)
-
- Posts: 573
- Joined: 25 Apr 2006 15:39
- Location: Cape Town, South Africa
Ok, as my sig says, I'm not really a code warrior
This is what I did to display 0 to 12V, with decimal point, with 0 to 5V in....
This is what I did to display 0 to 12V, with decimal point, with 0 to 5V in....
Code: Select all
sub procedure CnV
Lcd_Cmd(LCD_CLEAR) ' send command to LCD (clear LCD)
Lcd_Out(1,2,"Control Voltage")
Lcd_Out(2,10,"Volt")
t = ADC_read(1) ' get ADC value from 2nd channel
tlong = t*1200
t = tlong >> 10
ch = t div 1000 ' prepare value for diplay
Lcd_Chr(2,4,48+ch) ' write ASCII at 2nd row, 9th column
ch = (t div 100) mod 10
Lcd_Chr(2,5,48+ch)
Lcd_Chr(2,6,".")
ch = (t div 10) mod 10
Lcd_Chr(2,7,48+ch)
ch = t mod 10
Lcd_Chr(2,8,48+ch)
delay1S
end sub
"Copy'nPaste"
Throw away a few digits
The result I get in the LCD is something line 03535 , 02123 etc....... Since Pic has higher accuracy the last two digits varies often. I just want to remove the last two digits and make the value as 035 , 021 etc. How to do it? Will right shift work?dim rrrr as float
dim CurrentValue as float
dim text as chat[10]
CurrentValue = ADC_read(2)
rrrr = CurrentValue*(5000.0/1024.0)
CurrentValue = rrrr
wordtoStr(CurrentValue,Text)
Lcd_Out(1,1,Text)
Regards
Arun