ADCs won't read above 2.5v (511 raw)

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
chico
Posts: 34
Joined: Fri Dec 26, 2008 11:30 pm
Has thanked: 12 times
Been thanked: 10 times
Contact:

ADCs won't read above 2.5v (511 raw)

Post by chico »

I feel like there's a simple explanation for this, but I'm getting dizzy trying to find it...

I have an 18F2620 with 3 ADCs. With Flowcode 7 simulation, all three ADCs read correctly from 0 volts to 5 volts using "getVoltage()" and from 0 to 1023 using "getInt()".

And when I simulate the hardware using Proteus all ADCs read correctly: 0 volts to 5 volts using "getVoltage()" and from 0 to 1023 using "getInt()".

BUT...on the actual hardware, the ADCs will only read from 0 to 2.5 volts using "getVoltage()" and from 0 to 511 using "getInt()". There's nothing connected to the pins except a test voltage source (a pot dividing 5 volts). I can measure the voltage on the input pins and the go from 0v to 5v but the processor ADCs only read the correct voltage up to 2.5 volts, then won't rise above that level.

It's not a case of the voltage being divided by 2, since the voltage reads correctly until it gets to 2.5 volts (or 511 raw)...it won't read the higher voltages, it just reads all voltages over 2.5 as exactly 2.5, or 511 using "getInt()".

Anybody know why my hardware ADC inputs won't read any higher than exactly 2.5v or 511, while the simulations work correctly?

...thanks

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: ADCs won't read above 2.5v (511 raw)

Post by Steve001 »

Hi Chico,

Can you post your flow chart and a circuit diagram so we can help you further

Steve
Success always occurs in private and failure in full view.

chico
Posts: 34
Joined: Fri Dec 26, 2008 11:30 pm
Has thanked: 12 times
Been thanked: 10 times
Contact:

Re: ADCs won't read above 2.5v (511 raw)

Post by chico »

Strange...I was prepping my project to upload as requested and it was so big (lots of macros) I decided to strip down the size...that became a hassle so I decided to just start clean with a new project using the same ADC macros, using the same hardware.

Lo and behold, the new project works as expected: all ADCs read full range, 0 to 5 volts (0 to 1023 raw).

When I load my original program, EVEN THOUGH I USE THE EXACT SAME SIMPLE TEST ROUTINE WHICH IS A LOOP EXECUTED IMMEDIATELY UPON RESTART, with no other code being executed, the ADCs only read 0 to 2.5 volts (0 to 511 raw).

So now I'm going to start stripping the original file down macro by macro and line by line and see what's the difference causing the ADCs to work correctly in one program but not the other.

I'll post results (or baffled questions) as I converge on the problem.

Weird.

chico
Posts: 34
Joined: Fri Dec 26, 2008 11:30 pm
Has thanked: 12 times
Been thanked: 10 times
Contact:

Re: ADCs won't read above 2.5v (511 raw)

Post by chico »

OK, figured it out.

Turns out the ADC components that were imported from the FC6 program had the ADC conversion speeds set at FOSC/2, which simulates correctly in Flowcode but fails as described above on actual hardware (18F2620 w/ 20 MHz xtal). Even when I replaced the FC6 components with FC7 components the FOSC/2 parameter stuck, so it still didn't work on actual hardware.

When I add a new ADC component directly from within FC7 the ADC conversion speed is set at FRC, which simulates correctly in Flowcode and also operates correctly on actual hardware.

Took me a while to notice that the parameters weren't the same in the two programs, thus I couldn't figure out why they behaved differently (doh!)

On my 20 MHz 18F2620 hardware, all conversion speeds work EXCEPT FOSC/2, which as luck would have it was the speed my ADCs were set to when I moved the program from FC6 to FC7.

Ending with a question: is there an easy way to pick ADC conversion speeds for a particular chip with a particular xtal speed? I suppose I could dig through each chip's data sheet, but is there a simple rule of thumb for this?

Thanks...

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: ADCs won't read above 2.5v (511 raw)

Post by Benj »

Hello,

Slower is usually better as long as you don't need high sample rates. If in doubt then start with a lower speed setting and if its ok then you can work your way up.

The FRC setting is actually frowned upon by Microchip as it can vary with temperature and pressure etc. It's better to use an actual divider of the input clock and this way as long as the clock remains consistent then the ADC sampling should follow.

Pre-charge is another setting that can cause ADC problems. If this is too short then this would manifest itself as ADC channels bleeding values into each other. Again it won't harm anything to be too long other than your sample rate or loop speed.

Post Reply