PDA

View Full Version : ADC conversion trouble



PICante
- 22nd April 2008, 18:32
Hi all,

I am trying to get a one decimal presentation to a displayed temperature value. I’m using an LM35 which delivers 10mV / C it works almost as expected without decimals. If I test it by squeezing the LM35 between my fingers it goes; 24, 25, 26, 27, 29, 30 skipping 28? When I release it, it goes; 30, 29, 27, 26 and so on? And I cannot figure it out. ??

And as mentioned; my next problem is how to get one decimal.

I am using a16F88 set to 10 bit A/D and here’s part of the code:

ADCIN 0,T

T = (T*/500)>> 2

LCDOUT $FE,1,"TEMP= ",DEC T, “C”


Any ideas?

HenrikOlsson
- 22nd April 2008, 19:54
Hi PICante,
What are you using as Vref for the ADC? If you're using your PIC supply as Vref and it is exactly 5.00V you still only get ~2counts per degree C. 5.0V divided by 1024 (10bits) makes one LSB 4,89mV.

If you aren't using an external Vref for the ADC, I'd try that and see what happens. A Vref of 1.024V in this case would let you meassure up to 102.4°C with a resolution of 0.1° - in a perfect world.

HTH
/Henrik.

PICante
- 22nd April 2008, 20:31
Hej Henrik,

I am using the supply for reference; it’s very stable and good filtered 5.01 Volts, I also realize the limitations it brings. I see your point about the resolution and I would like to try using an external reference if I just knew how. Any good links for studying the suggested solution?

BTW, do you have any clue about why it skips 28? Could it be something wrong with my math?

Thank you!
Tack!

mackrackit
- 22nd April 2008, 20:42
Use a voltage divider to set the VREF. Darrel has info here.
http://www.pbpgroup.com/modules/wfsection/article.php?articleid=25

Try reading your LM35 with a volt meter. Possible it is doing the skipping.

HenrikOlsson
- 22nd April 2008, 21:20
BTW, do you have any clue about why it skips 28? Could it be something wrong with my math?
No, not really, except from the fact that you only get two counts per degree from the ADC. You might wan't to try taking 10 or more samples and average them to filter the signal. Also it's possible that you're running into some kind of rounding error in the math due the low resolution but I haven't looked into it that much.

Regarding the external Vref I'd suggest you look at the datasheet for the particular PIC you're using regarding the ADC and its various Vref options.

Another option might be to just put an OPAMP after the sensor, boosting the signal by a factor of xx to better utilize the full range of the ADC.

mister_e
- 22nd April 2008, 21:48
A good current/temperature compensate Vref is always more than welcome... boosting the sensor output... mmmmpppppfffffff maybe not a good idea.

There's a load of great few bucks constant voltage source ICs here and there.

HenrikOlsson
- 23rd April 2008, 06:11
Hi Steve,
I agree that a temp compensated Vref source is a better solution here but would you care to explain why you think it's not a good idea to boost the signal from the sensor?

Yes, the sensor noice will be amplified too but it shouldn't be that bad. Actually, amplifying the signal or lowering Vref shouldn't make any difference, except from non linearity of the amp and possible noice added BY the amp but I don't think that would be a problem in this case.

/Henrik.

mister_e
- 23rd April 2008, 15:11
I guess it depend of the accuracy you need. If you use the internal Vref, when the PSU voltage swing, your accuracy will swing with accordingly right?

Assuming the supply never ever swing... yeah you may boost the sensor output... carefully designed it has to work. Not something i would test on a breadboard... i'm kinda noise freak ;)

HenrikOlsson
- 23rd April 2008, 17:22
I guess it depend of the accuracy you need. If you use the internal Vref, when the PSU voltage swing, your accuracy will swing with accordingly right?
Yes absolutely, but if you have 20mV noice or swing on the supply rail with a sensor output of 10mV/° you have 2° worth of noice. If you boost the signal to 100mV/° the same noice on the supply rail is now "worth" 0.2° instead.

PICante,
In a previous reply I sugested a Vref of 1.024V but after reading the 16F88 datasheet that may not have been a very good advice. Vref needs to be 2V minimum according to the datasheet so keep that in mind if you go for an external reference.

/Henrik.

PICante
- 23rd April 2008, 20:28
Thanks guys!

Yes I like to try the external reference and I need one decimal accuracy with +- 0.5C overall. Maybe it will take a high stability voltage source to reach this.

Now I will try to figure out how to connect the Vref + & Vref- also how to set the bits in ANSEL and ADCON1 perhaps even the CVRCON? Not easy being a newbie! :-)

mackrackit
- 23rd April 2008, 21:56
Not easy being a newbie! :-)
I know what you mean. But it makes for a good excuse when something does not work or the room fills with smoke!!! :eek:

mister_e
- 23rd April 2008, 22:00
But it's always fun once in a while to have a smoke show huh?

http://www.mister-e.org/Pics/error00

http://www.mister-e.org/Pics/explosion

mackrackit
- 23rd April 2008, 22:09
Then you tell the kids. "I just did that so you could see what not to do." and "Always wear your safety glasses while programming."

mister_e
- 23rd April 2008, 22:18
Don't try it at home, i'm a professional :D

PICante
- 24th April 2008, 17:50
Thanks guys, you are a lot of comfort!

Unless you see a powerful light at the horizon I’ll be back soon!

mister_e
- 24th April 2008, 19:44
mmmm... where's Sweden located from where i am????... Ah... ok i see. I'm waiting for a morse-smoke-coded message now :D

Just kidding :D

Whatever you do, have fun, and learn from it. We will be there when you will need help.

mackrackit
- 24th April 2008, 20:27
. . . _ _ _ . . . :rolleyes:

Yeah, have fun!

mister_e
- 24th April 2008, 20:34
hey that' SOS right?

mackrackit
- 24th April 2008, 20:56
That is affirmative. :)

mister_e
- 24th April 2008, 21:34
.-- .... .- - . ...- . .-. / -.-- --- ..- / -.. --- --..-- / -.. --- / .. - / .-- . .-.. .-.. / .- -. -.. / . -. .--- --- -.--
:D

PICante
- 25th April 2008, 21:02
Hello again,

No smoke… yet.

I made and plugged in a 2.000 Volt reference for Vref+.
The old brain is partially hibernating and I can’t get the decimal to appear correctly.
Some changes to the code:

ANSEL = %00001111 ‘ not sure if I need both AN2 and AN3 for Vref since I only use Vref+ on AN3.. well seems to work so far. Perhaps better to make AN3 an output?

ADCON1 = %11100000 ‘ right justify – clock/2 - use Vref+.

ADCIN 0,T

T = (T*/200)>> 2

LCDOUT $FE,1,"TEMP= ",DEC T, “.”, DEC1 T, “C”



Could use a sharper brain!

Yes, I have fun!

mister_e
- 25th April 2008, 21:53
try

LCDOUT $FE,1,"TEMP= ",DEC (T/10), ".", DEC T DIG 0, "C"

PICante
- 26th April 2008, 12:19
Thanks Steve,

However this only moved the dot so instead of 26 C I got 2.6 C!

mister_e
- 26th April 2008, 19:04
so you just need to adjust this line
T = (T*/200)>> 2
PBP works with integers only. If your result=263, you will display 26.3C with the LCDOUT line i've suggested.

PICante
- 30th April 2008, 20:42
Thanks Steve!

I removed this line entirely: “T = (T*/200)>> 2” and now it works as expected!

Thank you very much guys!