View previous topic :: View next topic |
Author |
Message |
tolliug
Joined: 09 Aug 2018 Posts: 15
|
Analog input AN9 pin_B4 drives high (pic18f46k80) |
Posted: Wed Mar 13, 2019 10:34 am |
|
|
Hi Everyone,
On our last project, we want to use pin_B4 as analog input. ADC is configured as:
Code: |
setup_adc( ADC_CLOCK_INTERNAL );
setup_adc_ports( sAN1 | sAN4 | sAN6 | sAN7 | sAN9);
enable interrupts( INT_AD);
|
However the pin B4 is at 5V like if it was pulled up and therefore measurement is wrong.
If I erase the device pin_B4 is at 0V. Any idea on how to debug this?
Last edited by tolliug on Wed Mar 13, 2019 10:47 am; edited 1 time in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Wed Mar 13, 2019 10:45 am |
|
|
re:
1st comment:
Quote: | setup_adc( ADC_CLOCK_INTERNAL );
| Usually 'ADC_CLOCK_INTERNAL' is for slow clocked PICs, and only when asleep, so checke the datasheet, adc section for a chart of legal adc clock config.
2nd comment:
Quote: | setup_adc_ports(sAN1 | sAN4 | sAN6 | sAN7 sAN9);
| I don't see a '|' between sAN7 and sAN9
check for proper syntax..
3rd comment
Quote: | enable interrupts(INT_AD);
| Be sure you have an interrupt handler (function) as enabling an interrupt without will cause the PIC to crash... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 13, 2019 11:24 am |
|
|
Post more of your program. Show us the code where you select aN9 as
the current channel to read. Show us the code in the read_adc() section
of your program. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Wed Mar 13, 2019 11:30 am |
|
|
and (of course) there is absolutely no reason to use INT_AD, unless
you are starting the ADC conversion with perhaps a CCP. Otherwise
it takes longer to get into and out of an interrupt handler than it takes
to simply perform the conversion 'in line'.
Also, on the problem, I think there is a CTMU output on this pin. Any
configuration lines for this peripheral?.
Any code accessing the pull-ups?.
Everything that accesses TRISB, LATB, PORTB?. |
|
|
|