View previous topic :: View next topic |
Author |
Message |
Foppie
Joined: 16 Sep 2005 Posts: 138 Location: The Netherlands
|
A/D Pin A5 always high? |
Posted: Thu Oct 06, 2005 7:05 am |
|
|
Hello,
when I run a Analog/Digital test on my PIC16F877A with the pins A0, A1, A2, A5 and pin A3 as Vref all works but pin A5. Pin A5 always gives 1023, no matter what voltage I put on it's line.
i use following the following code to initialize the AD ports:
Code: | setup_adc_ports(A_ANALOG_RA3_REF); //sets A0, A1, A2 and A5 to analog and A3 to Vref
setup_adc(ADC_CLOCK_DIV_32); // define clock settings |
Since the other pins work I guess and the hardware on all ports is the same I think I forgot to initialize something in my software. But I cannot find anything on the Datasheet
Can someone help me? |
|
|
Ttelmah Guest
|
|
Posted: Thu Oct 06, 2005 7:14 am |
|
|
Have you looked carefully at the pin diagrams. 'AN5', is not on pin 'A5', but on E0. AN4, is actually on pin A5. So you need to setlect the analog channel '4', to actually read a voltage on 'A5' (confusing...).
Best Wishes |
|
|
Foppie
Joined: 16 Sep 2005 Posts: 138 Location: The Netherlands
|
|
Posted: Thu Oct 06, 2005 7:29 am |
|
|
Ttelmah wrote: | Have you looked carefully at the pin diagrams. 'AN5', is not on pin 'A5', but on E0. AN4, is actually on pin A5. So you need to setlect the analog channel '4', to actually read a voltage on 'A5' (confusing...). |
This did it! Thanks.
Now do I have another question: how do I define RA4, since RA5 is AN4? |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Oct 06, 2005 9:01 am |
|
|
Foppie wrote: | Ttelmah wrote: | Have you looked carefully at the pin diagrams. 'AN5', is not on pin 'A5', but on E0. AN4, is actually on pin A5. So you need to setlect the analog channel '4', to actually read a voltage on 'A5' (confusing...). |
This did it! Thanks.
Now do I have another question: how do I define RA4, since RA5 is AN4? |
Define RA4 as what??????
Do you mean where is AN5? If so, its on E0. |
|
|
Foppie
Joined: 16 Sep 2005 Posts: 138 Location: The Netherlands
|
|
Posted: Fri Oct 07, 2005 12:44 am |
|
|
Mark wrote: | Define RA4 as what??????
Do you mean where is AN5? If so, its on E0. |
I first defined pin RA5/AN4 as PIN_A5, but as Ttelmah said I should define it as PIN_A4. Now My question is, how should I define pin RA4/TOCKl (I first thaught I should define it as PIN_A4 but since that is another pin I don't know how to define it)?
P.S.
I do not use Timer0 |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Oct 07, 2005 7:16 am |
|
|
NO! RA5 is PIN_A5! But RA5 is AN4. RA4 is PIN_A4, confused yet |
|
|
Foppie
Joined: 16 Sep 2005 Posts: 138 Location: The Netherlands
|
|
Posted: Fri Oct 07, 2005 7:41 am |
|
|
Mark wrote: | NO! RA5 is PIN_A5! But RA5 is AN4. RA4 is PIN_A4, confused yet |
huh?
I first defined RA5/AN4 as PIN_A5 but that didn't work. Now I defined RA5/AN4 as PIN_A4 and it is working...
But now you say my non-working code should be working an dmy working code should not???
I am getting very, very confused here
(probably end-of-the-week meltdown....)
I will test it monday all over again and post my results...
thanks for your help! |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Oct 07, 2005 7:58 am |
|
|
Ttelmah wrote: | Have you looked carefully at the pin diagrams. 'AN5', is not on pin 'A5', but on E0. AN4, is actually on pin A5. So you need to setlect the analog channel '4', to actually read a voltage on 'A5' (confusing...).
Best Wishes |
RJ never said anything about defining something as PIN_A4. He said that RA5 (PIN_A4) is analog channel 4. When you set the adc channels, you do not use PIN_Ax. You use a number instead. |
|
|
Foppie
Joined: 16 Sep 2005 Posts: 138 Location: The Netherlands
|
|
Posted: Mon Oct 10, 2005 12:33 am |
|
|
Mark wrote: | RJ never said anything about defining something as PIN_A4. He said that RA5 (PIN_A4) is analog channel 4. When you set the adc channels, you do not use PIN_Ax. You use a number instead. |
I finally understand now! Thank you very much |
|
|
|