PDA

View Full Version : Analog port newbie questions



rngd
- 8th March 2008, 11:50
Hi guys,

Im having trouble using the analog port. Regarding the analog port A, is it supposed to output high (approx 4.8V) when its not connected to anything ? I have set trisa=%111111.

Ive programmed everything else correctly (I think), after reading some good guides on programming for port A.

The problem is I have a photodiode which has open circuit voltage of 0.25V but when I connect it to channel 0 it jumps to 0.40V for some reason. The Vref+ is set to 2.5V.

Thanks all.

edit: I suspect that something is wrong with my port A. How do i check ? Anyone have a working test code ? Im also testing it now ..

Jumper
- 8th March 2008, 12:29
Hi,

What PIC do you use? Port A usually contains a lot of stuff such as comparators and A/D and there fore requires some more registers to be set before it is working properly.

What do you have connected to your port A and what do you want it to do? Do you want all pins digital? or just some and the others A/D.

To help you we need some more info such as mentioned befoer PIC, simple circuit description, a clear idea of your expected end result and some beer.

The beer most of us already have so you just add the rest and we will see where the problem is.

/me

rngd
- 8th March 2008, 17:07
Hi jumper, these are my settings for ADC

define OSC 20
define adc_bits 10 'define number of bits in result
define adc_clock 3 'clock source3=RC
define adc_sampleus 50 'set sampling time in microsec

adc1 var word 'store adc input values, adc1=AN0/RA0
adc2 var word 'AN1/RA1
adc3 var word 'AN2/RA2
adc4 var word 'AN4/RA5

trisa = %11111111 'port A all input

adcon1 = %10000011 '1 for Result Format Selection Bit because using 10 bits
'0011 for AN4, AN2, AN1, AN0 analog port. AN3 is
'Vref+ reference voltage
pause 500 'wait .5 second


Im using the 16F877A. This is my main program and it is supposed to input 4 analog values, do some comparison and then high some ports.

Ive tried a simpler version to test out the port also,


define osc 20

define adc_bits 10 'define number of bits in result
define adc_clock 3 'clock source3=RC
define adc_sampleus 50 'set sampling time in microsec

trisa = %11111111
trisd=0
adcon1 = %10000010

pause 500

adc var word

start:

adcin 0, adc

if adc > 10 then
high portd.0

else
low portd.0

endif

pause 500

goto start



When I input 2.5V into porta.0 the LED does not turn on. If I leave the pin floating (5V) then it turns on. If I change the code to 'adc>0', it turns on.
edit: I think the port A of my PIC is fried. When power is on but nothing is connected, the port A pins are at 5V. Is this normal ? Help pls !

skimask
- 9th March 2008, 05:39
You set AN3 as Vref+. What do you have on AN3?
Try setting Vref+ to internal +5v and see what happens...

rngd
- 9th March 2008, 08:19
You set AN3 as Vref+. What do you have on AN3?
Try setting Vref+ to internal +5v and see what happens...

For the first code, I have a voltage regulator giving 2.5V to AN3.

I have tried using internal 5V Vref+ for the code below


define osc 20

define adc_bits 10 'define number of bits in result
define adc_clock 3 'clock source3=RC
define adc_sampleus 50 'set sampling time in microsec

trisa = %11111111
trisd=0
adcon1 = %10000010

pause 500

adc var word

start:

adcin 0, adc

if adc > 10 then
high portd.0

else
low portd.0

endif

pause 500

goto start

and i input the same 2.5V into channel 0, but I cannot get portd.0 to go high ? Ive also tried changing to 'define adc_clock 2' or (20Mhz which is same as my OSC freq).

skimask
- 9th March 2008, 08:30
Which version of PBP are you using?
And try
adcon0 = $c1 : adcon1 = $f0

rngd
- 9th March 2008, 15:59
Which version of PBP are you using?
And try
adcon0 = $c1 : adcon1 = $f0

Im using PBP 2.47. I tried to change adcon1 and add adcon0 but it still doesnt work. Is the problem in my code or is my port A burnt (I accidentally input ~10V for a short while into the Vref+ pin earlier) ?
Is anything wrong with the quoted code ?

Any help is appreciated.

rngd
- 9th March 2008, 20:40
OK, I found the problem, turns out the defines must be in block letters. Weird that I did not get any compile errors though.

skimask
- 9th March 2008, 22:27
OK, I found the problem, turns out the defines must be in block letters. Weird that I did not get any compile errors though.

Which is exactly what the PBP manual says will happen...

rngd
- 10th March 2008, 11:38
Which is exactly what the PBP manual says will happen...

Yeah, too bad for me, I did not not read the part about the defines