Wrong counts from ADC?
Moderator: Benj
-
- Flowcode v5 User
- Posts: 273
- Joined: Thu Apr 17, 2008 9:59 am
- Has thanked: 19 times
- Been thanked: 16 times
- Contact:
Wrong counts from ADC?
Hello,
I am using the AN9 ADC input on a PIC16F886 to read a DC voltage. For some reason, I don't get what I expect, so either I do something wrong or my expectation is wrong . Can anyone help?
I am sending a DC voltage of 1.000VDC into pin 25. Reference is set to 'Ref+pin', that pin is at 4.102 (a nominal 4.096 ref.). The ADC zero ref pin is at 0.25mV.
My expectation: since 10 bits = 1024 counts, and the ref is 4.096V (nom), one count = 4mV.
A 1V input should thus give 250 counts.
However, I see a consistently low value of 239/240 counts. What's wong?
Jan Didden
Linear Audio
I am using the AN9 ADC input on a PIC16F886 to read a DC voltage. For some reason, I don't get what I expect, so either I do something wrong or my expectation is wrong . Can anyone help?
I am sending a DC voltage of 1.000VDC into pin 25. Reference is set to 'Ref+pin', that pin is at 4.102 (a nominal 4.096 ref.). The ADC zero ref pin is at 0.25mV.
My expectation: since 10 bits = 1024 counts, and the ref is 4.096V (nom), one count = 4mV.
A 1V input should thus give 250 counts.
However, I see a consistently low value of 239/240 counts. What's wong?
Jan Didden
Linear Audio
Last edited by jadiflow on Mon Apr 29, 2019 12:55 pm, edited 1 time in total.
-
- Flowcode v5 User
- Posts: 273
- Joined: Thu Apr 17, 2008 9:59 am
- Has thanked: 19 times
- Been thanked: 16 times
- Contact:
Re: Wrong counts from ADC?
Did some further tests:
Tried a different chip (same type), changed between ADC sample clock Focs/8 to Fosc/32. Also changed software to loop 8 times sampling integer, adding them all up then shift right 3 places. In all cases I see exactly the same result, 239/240/241
I changed the ADC read to Byte, because the value I expect is less than 255. What do you know: with 1V input, and 4.1V ref, the Byte Read gives me a value of 59/60. What is this? Does the Byte Read not read the 8 LSB's from the ADC result?
This result is just 1/4 of the result I received from a full 10 bit read, which suggests a 2-bit right shift. Does that make any sense?
Then changed the component from a 'pot' type ADC device to a basic ADC_base1. No change.
Then changed the ADC Ref voltage in the component dialog to Vdd (which is 5V). The actual input voltage still 1V. Returned value is 193, should have been 204/205. The ratio of the returned 193 at 5V ref to the 240 at 4.1V ref seems correct, so that part appears to work correctly. Still the riddle why the returned value is so low.
Anybody? This is holding up my whole project. Somebody must have some idea of what is wrong or what I am missing??
Tried a different chip (same type), changed between ADC sample clock Focs/8 to Fosc/32. Also changed software to loop 8 times sampling integer, adding them all up then shift right 3 places. In all cases I see exactly the same result, 239/240/241
I changed the ADC read to Byte, because the value I expect is less than 255. What do you know: with 1V input, and 4.1V ref, the Byte Read gives me a value of 59/60. What is this? Does the Byte Read not read the 8 LSB's from the ADC result?
This result is just 1/4 of the result I received from a full 10 bit read, which suggests a 2-bit right shift. Does that make any sense?
Then changed the component from a 'pot' type ADC device to a basic ADC_base1. No change.
Then changed the ADC Ref voltage in the component dialog to Vdd (which is 5V). The actual input voltage still 1V. Returned value is 193, should have been 204/205. The ratio of the returned 193 at 5V ref to the 240 at 4.1V ref seems correct, so that part appears to work correctly. Still the riddle why the returned value is so low.
Anybody? This is holding up my whole project. Somebody must have some idea of what is wrong or what I am missing??
Last edited by jadiflow on Mon Apr 29, 2019 1:24 pm, edited 1 time in total.
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: Wrong counts from ADC?
Yes, the 8 bit read returns the most significant 8 bits (returning the lower 8 bits would not make any sense)This result is just 1/4 of the result I received from a full 10 bit read, which suggests a 2-bit right shift. Does that make any sense?
What's the impedance of the 1V into the device?
Is it from a high resistance potentiometer for example?
Could the voltage be dropping when it is sampled by the ADC?
-
- Flowcode v5 User
- Posts: 273
- Joined: Thu Apr 17, 2008 9:59 am
- Has thanked: 19 times
- Been thanked: 16 times
- Contact:
Re: Wrong counts from ADC?
Hi Leigh,
I looked at that earlier, the 1V comes from a very low Zout (0.5R nominal) from an RMS-DC converter (AD536), then into the PIC via 499R. Should be OK, no?
Jan
I looked at that earlier, the 1V comes from a very low Zout (0.5R nominal) from an RMS-DC converter (AD536), then into the PIC via 499R. Should be OK, no?
Jan
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: Wrong counts from ADC?
Hi Jan,
Yes, that should be OK.
Maybe try a range of input values and see if it gives any clues?
e.g. is it a linear or an offset problem
Yes, that should be OK.
Maybe try a range of input values and see if it gives any clues?
e.g. is it a linear or an offset problem
-
- Flowcode v5 User
- Posts: 273
- Joined: Thu Apr 17, 2008 9:59 am
- Has thanked: 19 times
- Been thanked: 16 times
- Contact:
Re: Wrong counts from ADC?
OK, went back and inserted 1.006V DC, on a 6.5 digit DMM, directly at the an9 pin on the pic, from a DC power supply. That does make a difference, count is now 243. Still 7 counts (28mV) missing.
Jan
Jan
-
- Flowcode v5 User
- Posts: 273
- Joined: Thu Apr 17, 2008 9:59 am
- Has thanked: 19 times
- Been thanked: 16 times
- Contact:
Re: Wrong counts from ADC?
Not clear what type of error it is:
Vin exp.cnts act.cnts error
2.076 504 499 5 1%
1.499 375 363 12 3%
0.974 243 231 12 5%
0.497 124 115 9 7%
I did experiment with the sample clock settings and the delay between sampling in the macro, but that doesn't seem to make any difference. Is there a recommended setting for those?
Jan
Vin exp.cnts act.cnts error
2.076 504 499 5 1%
1.499 375 363 12 3%
0.974 243 231 12 5%
0.497 124 115 9 7%
I did experiment with the sample clock settings and the delay between sampling in the macro, but that doesn't seem to make any difference. Is there a recommended setting for those?
Jan
-
- Flowcode v5 User
- Posts: 273
- Joined: Thu Apr 17, 2008 9:59 am
- Has thanked: 19 times
- Been thanked: 16 times
- Contact:
Re: Wrong counts from ADC?
Hung a cap on that an9 pin, as well as a scope probe. See some switching noise but not more than +/-4mV peak.
-
- Flowcode v5 User
- Posts: 273
- Joined: Thu Apr 17, 2008 9:59 am
- Has thanked: 19 times
- Been thanked: 16 times
- Contact:
Re: Wrong counts from ADC Q to Leigh
Hi Leigh,
Flowcode offers me a selection of ADC ref voltages, either Vdd or 'Vref-pin'. However the chip itself also offers the selection of the 0V ref for the ADC, either Vss or the -Vref pin.
I am returning the gnd of the voltage to be converted to this pin, but if the chip configuration has been set for Vss, there would be a deviation.
Is there an option in FC to set the -Vref pin to the dedicated pin (pin 4 on the 16F886) or should that be done with an assembly- or C-block? What is the default setting of the 0V reference when you select +Vref-pin as ADC reference in the component properties?
Jan
Flowcode offers me a selection of ADC ref voltages, either Vdd or 'Vref-pin'. However the chip itself also offers the selection of the 0V ref for the ADC, either Vss or the -Vref pin.
I am returning the gnd of the voltage to be converted to this pin, but if the chip configuration has been set for Vss, there would be a deviation.
Is there an option in FC to set the -Vref pin to the dedicated pin (pin 4 on the 16F886) or should that be done with an assembly- or C-block? What is the default setting of the 0V reference when you select +Vref-pin as ADC reference in the component properties?
Jan
-
- Flowcode v5 User
- Posts: 273
- Joined: Thu Apr 17, 2008 9:59 am
- Has thanked: 19 times
- Been thanked: 16 times
- Contact:
Re: Wrong counts from ADC?
Set ADCON1 register bit 5 should switch the 0V ref to the '-Ref' pin. No change.
-
- Flowcode v5 User
- Posts: 273
- Joined: Thu Apr 17, 2008 9:59 am
- Has thanked: 19 times
- Been thanked: 16 times
- Contact:
Re: Wrong counts from 16F886 ADC? - work-around
Finally compiled the software to another PIC, a 16F1788. Same hardware prototype. This is a 12 bit ADC, so for a 1V input and 4.096 ref I should get a count of 1000, I get 997. Good enough for government work. Actually the ref is 4.102V so that narrows the gap further.
Conclusions:
- Nothing wrong with my hardware (phew!);
- Apparently a systematic issue in the 16F886, at least in the batch I got.
You live and learn ...
Jan Didden
Linear Audio
Conclusions:
- Nothing wrong with my hardware (phew!);
- Apparently a systematic issue in the 16F886, at least in the batch I got.
You live and learn ...
Jan Didden
Linear Audio