PDA

View Full Version : 12f675 sensing temperature...



rossfree
- 5th April 2007, 22:53
Hi all,

I'm having a bit of trouble getting my a/d working just right. I have an LM34 connected to GPIO.0 and a pot feeding 2.55 volts to Vref pin GPIO.1

I am trying to turn on a relay connected to GPIO.5 based on the temperature reading.h

I don't think I have the a/d bits set correctly. It appears to still think it is 10 bit but I want it set to 8.

Can you please look at my short code and tell me where I have gone astray.

If you look at the txt file attached, you'll note that I have the relay turning on when my a/d result is > 330.

By measuring the voltages and doing some math... that's right where it would be if the A/D was 10 bit. And it does work. The relay turns on and off when I touch the temperature sensor.

Help please! :-)

Thank you!

Ross

skimask
- 5th April 2007, 23:06
Hi all,

I'm having a bit of trouble getting my a/d working just right. I have an LM34 connected to GPIO.0 and a pot feeding 2.55 volts to Vref pin GPIO.1

I am trying to turn on a relay connected to GPIO.5 based on the temperature reading.h

I don't think I have the a/d bits set correctly. It appears to still think it is 10 bit but I want it set to 8.

Can you please look at my short code and tell me where I have gone astray.

If you look at the txt file attached, you'll note that I have the relay turning on when my a/d result is > 330.

By measuring the voltages and doing some math... that's right where it would be if the A/D was 10 bit. And it does work. The relay turns on and off when I touch the temperature sensor.

Help please! :-)

Thank you!

Ross

Left justify the A/D result, use the high A/D result byte for your end result and ignore the lower 2 bits at the top of the lower A/D result byte.
You'll lose 2 bits of resolution, but you'll only deal with a single byte.

rossfree
- 5th April 2007, 23:19
Thank you skimask,

but... I kinda want that 8 bit resolution. With Vref set at 2.55 volts, and using an LM34 temperature sensor outputing .01 volts per degree F, I get a digital number that corresponds very nicely with temperature... such that .8 volts in gives me a digital 80 out... representing 80 degrees F.

Dropping off the top two digits doesn't change the resolution... it just lops off the top end.

Can you help me figure out why it doesn't accept my statement:

DEFINE ADC_BITS 8

Thank you,

Ross

skimask
- 5th April 2007, 23:40
Thank you skimask,

but... I kinda want that 8 bit resolution. With Vref set at 2.55 volts, and using an LM34 temperature sensor outputing .01 volts per degree F, I get a digital number that corresponds very nicely with temperature... such that .8 volts in gives me a digital 80 out... representing 80 degrees F.

Dropping off the top two digits doesn't change the resolution... it just lops off the top end.

Can you help me figure out why it doesn't accept my statement:

DEFINE ADC_BITS 8

Thank you,

Ross

I didn't say drop off the top 2 bits of the upper byte, I said drop the top 2 bits of the lower byte (which are actually the bottom 2 bits of the result overall).

I don't think you can have it both ways, well you can, but it's a bit more difficult.
And why is 10 bits a problem? PBP can handle 10 bits easily, even on a PIC12F.


DEFINE ADC_BITS 8 - which version of PBP are you using?

rossfree
- 6th April 2007, 00:11
Thank you Skimask...

You just asked the right question...

The define statement is a PBP statement... and I'm accessing the pic directly with adcon0... not ADCIN. The define is correct if used with ADCIN. I have used it before but forgot I used them together.

I'm using PBP ver 2.45.

I've looked at your suggestion again and it makes more since. Let me see if I got it...

By dropping the two least significant bits, I essentially divide the ten bit result by four. That gives me an eight bit result. Yes?!

It's MILLER TIME!

Ross