Page 1 of 1

Analogue input always reading 255

Posted: Wed Sep 11, 2019 11:39 am
by Dave Squibb
Hi all,
I am trying to read an analogue input on AN3 on a PIC18F45K22 .
Whatever voltage I put on the input, 0 to 5 V, always reads 255.
(Macro "initialise" is part of a larger project but this bit won't work at all without it)
I've tried a new PIC.
Can someone have a look please?
Thanks,
Dave.
ADC.fcfx
(73.54 KiB) Downloaded 232 times
(sorry, forgot file!)

Re: Analogue input always reading 255

Posted: Wed Sep 11, 2019 12:12 pm
by Benj
Hi Dave,

I've just looked at the code for the ADC on the K22 devices and it looks to be ok. The ADC component in your project is pointed to AN0 though I'm guessing this isn't the cause of the issue.

Maybe try a conversion rate other then the FRC setting.

Might also be worth getting rid of the C code ADCON and ANSEL bits, the ADC component should take care of all this for you.

Re: Analogue input always reading 255

Posted: Wed Sep 11, 2019 12:32 pm
by Dave Squibb
Hi Benj,
I've spent hours on this, adding bits in like the ADCON and ANSEL bits, trying to get it to work. It was definately pointing to AN3 originally.
I removed the ADCON and ANSEL bits, pointed it back to AN3 and it all works!
I'll add it back to the original program very carefully.
Thanks for your help.
Dave