Hi everyone. I have been trying to figure this one out for a while now and searches on the forum have not provided an help unfortunately.
Basically I am using a PIC18F26K22 microcontroller and am using four of the ADC pins, namely:
PORTA.5 = ADC.4
PORTC.2 = ADC.14
PORTC.6 = ADC.18
PORTC.7 = ADC.19
Now there is no problem with reading from PORTA.5 and PORTC.2 however I have not been able to get a reading from PORTC.6 or PORTC.7
I have ensured that ADC is enabled, I have made sure that the respective TRIS bits have been set, I have made sure that the respective ANSELA and ANSELC bits have been set. I have also checked to see if I need to disable any of the other features of those port pins but it seems that everything that I have done should be correct.
Has anyone had any issues with using PORTC.6 and PORTC.7 as ADC pins before? Can anyone shed any light on this issue?
Thank you in advance.
-Brad
Problems with ADC on PORTC.6 and PORTC.7
Moderators: David Barker, Jerry Messina
-
- Posts: 28
- Joined: Thu Nov 29, 2012 12:29 am
- Location: Australia
-
- Swordfish Developer
- Posts: 1473
- Joined: Fri Jan 30, 2009 6:27 pm
- Location: US
Re: Problems with ADC on PORTC.6 and PORTC.7
The ADC library hasn't been modified for all the channels that the K22 supports... it only allows for 16 channels.
Try this:
Try this:
Code: Select all
// adc read for 26K22
public function Read(pChannel as byte) as word
// set channel...
ADCON0 = (ADCON0 and $03) or (pChannel << 2)
// read ADC...
if FAcquisitionTime = 0 then
Enabled = true
Convert = true
else
Enabled = true
delayus(FAcquisitionTime)
Convert = true
endif
// wait for completion, then disable ADC...
while Convert
wend
Enabled = false
Result = ADResult
end function
-
- Posts: 28
- Joined: Thu Nov 29, 2012 12:29 am
- Location: Australia
Re: Problems with ADC on PORTC.6 and PORTC.7
Thank you Jerry, that fixed it up.
I didn't even think at looking at the ADC library, perhaps if I did I would have spotted the problem!
I didn't even think at looking at the ADC library, perhaps if I did I would have spotted the problem!