PDA

View Full Version : ADC Channels



Armando Herjim
- 12th September 2006, 17:42
Hello. I have to read an analog signal and to convert it to a digital signal, but I just canīt get to do it. I know the adc has a 10-bit resolution right? Ok, so What bits are in adresh and wich ones are in adresl, and how cad a put that info in a port, say, portb. What is justified right and justified left? What does this mean? The analog signal goes from GND to Vdd (0V - 5V). So, in the Vref+ and Vref- should I have GND and Vdd?? I made a program but it does not work... hereīs the code. Please somebody help me yeah?

osccon = $50

ADCON1 = $0E
ADCON0 = $02
ADCON2 = $03
high adcon0.0

inicio:

if (portc.1 = 1 and portc.2 = 0) then
portb.0 = adresl.4 ; is this line right? I mean, is it valid to manage
portb.1 = adresl.5 ; the data this way? If so, how can I know
portb.2 = adresl.6 ; wich adres? to use?
portb.3 = adresl.7
else
if (portc.1 = 0 and portc.2 = 1) then
portb.0 = adresl.0
portb.1 = adresl.1
portb.2 = adresl.2
portb.3 = adresl.3
endif
endif

if adcon0.1 = 0 then
high adcon0.1
endif

goto inicio

uummm so... guess thatīs it. I will apreciate a lot any comment.

Best Regards.

Armando H.

mister_e
- 12th September 2006, 22:04
That would help to know wich PIC you're using :D

also

high adcon0.0

you should write

adcon0.0=1

AND

if (portc.1 = 1 and portc.2 = 0) then

Should be

if (portc.1 = 1) and (portc.2 = 0) then

sayzer
- 13th September 2006, 09:18
In addition to mister_e's post,

If you are using 10bit resolution, "right justified" is needed.
If you are using 8bit resolution, "left justified" is needed.

Ex:
ADCON0.7 = 1 'Right justified.
ADCON0.7 = 0 'Left justified.


Also, check this :
http://www.picbasic.co.uk/forum/showthread.php?t=3711&highlight=justified

Armando Herjim
- 14th September 2006, 07:08
Well thanks both of you. The pic I use is 18F4550. Iīm going to try out your advices, but there is still one thing Iīd like to know. If I need 8 bit resolution I have to use left justified, (thanks for that!) so, where will I find the data? Will it be stored in adresL or in adresH... and, if I decided to use 10 bit resolution, which bits would be sored is adresL and which bits in adresH? I think my questions are pretty clear but if I didnīt explain myself please let me know and thank you again.

Regards.

Oh, I forgot! I need to read a signal that goes 0-5 volts... how do you think I should use the Vref+ and the Vref-??? Thank you!!

Armando H.

ErnieM
- 21st September 2006, 21:19
ADRESHI has the most signifigant bits, leaving ADRESLO with the least signifigant bits.

The data from the A2D is 10 bits wide... so the question is where to put 10 bits into 2 seperate 8 bit result registers.

If you left justify, you space everthing so the highest (most sig) data bit align with the highest (most sig) register bit.

Right justify puts the lowest data bit in line with the register's lowest bit. That means the hi register only has the top 2 sig bits.

When you left justify, as the hi register has the most sig 8 bits it also has the 8-bit (non rounded) result.

Hope this is more helpful then confusing.

amindzo
- 22nd September 2006, 15:47
Hi,
you don't need to use 10 bit A/D. you can use 8 bit , that is easier than 10 bit.
like this:

define OSC 4
TRISA = %11111111
x var byte
ADCON1 = %00000010
adcin 0,x ' 0is the channel number and x is the variable
end

you don't need to connect the Vref+ and Vref- to somewher.

if you want to use 10 bit ask me again yo tell you.