Need Assistance With ADCON0 and ADCON1 registers

General discussion on mikroBasic.
Post Reply
Author
Message
arunkish
Posts: 40
Joined: 03 Sep 2006 05:43
Contact:

Need Assistance With ADCON0 and ADCON1 registers

#1 Post by arunkish » 13 Jun 2007 05:17

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

trust issues
Posts: 231
Joined: 14 Nov 2004 19:43

#2 Post by trust issues » 13 Jun 2007 06:27

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.

p3t3rv
Posts: 268
Joined: 14 Apr 2005 09:33
Location: Doncaster UK

#3 Post by p3t3rv » 13 Jun 2007 10:02

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
there are 10 types of people Those that understand binary and those that dont

xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

#4 Post by xor » 13 Jun 2007 11:00

[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]

arunkish
Posts: 40
Joined: 03 Sep 2006 05:43
Contact:

hi

#5 Post by arunkish » 13 Jun 2007 13:18

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.

arunkish
Posts: 40
Joined: 03 Sep 2006 05:43
Contact:

#6 Post by arunkish » 13 Jun 2007 16:11

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 ???

Copy'nPaste
Posts: 573
Joined: 25 Apr 2006 15:39
Location: Cape Town, South Africa

#7 Post by Copy'nPaste » 13 Jun 2007 16:38

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 :twisted:
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"

Copy'nPaste
Posts: 573
Joined: 25 Apr 2006 15:39
Location: Cape Town, South Africa

#8 Post by Copy'nPaste » 13 Jun 2007 16:50

That should be all 8 pins on port A :oops:
"Copy'nPaste"

arunkish
Posts: 40
Joined: 03 Sep 2006 05:43
Contact:

hi copynpaste

#9 Post by arunkish » 14 Jun 2007 04:09

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. :D

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)

Copy'nPaste
Posts: 573
Joined: 25 Apr 2006 15:39
Location: Cape Town, South Africa

#10 Post by Copy'nPaste » 14 Jun 2007 06:28

Ok, as my sig says, I'm not really a code warrior :oops:
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"

p3t3rv
Posts: 268
Joined: 14 Apr 2005 09:33
Location: Doncaster UK

#11 Post by p3t3rv » 14 Jun 2007 10:17

The 16F73 has an 8 bit AD not 10 bit :)
there are 10 types of people Those that understand binary and those that dont

arunkish
Posts: 40
Joined: 03 Sep 2006 05:43
Contact:

Throw away a few digits

#12 Post by arunkish » 15 Jun 2007 04:22

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)
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?

Regards
Arun

p3t3rv
Posts: 268
Joined: 14 Apr 2005 09:33
Location: Doncaster UK

#13 Post by p3t3rv » 15 Jun 2007 08:23

again
its because you are aplying a 10 bit math to an 8 bit result

hint: 10 bit is 1024, 8 bits is 255

The 16F73 has an 8 bit AD not 10 bit


:roll: :wink:
there are 10 types of people Those that understand binary and those that dont

Post Reply

Return to “mikroBasic General”