PDA

View Full Version : Temperature with the LM34C



StoneColdFuzzy
- 26th January 2009, 19:16
In the project by Reynolds Electronics here (http://www.rentron.com/PicBasic/LM34.htm), what's a good size potentiometer to use for calibration?

~ Dave

Archangel
- 26th January 2009, 20:57
That is a simple voltage divider. 5v supply /5k ohm = .001 Amp
5v / 10k ohm = .0005 amp how much current do you want to waste ?
Assuming zero current flow into the PIC (impossible I know) the voltage will be linear across either one. It gets less true as the PIC begins to load the voltage divider, and as this parasitic loss increases the more suitable the lower resistance becomes.

mister_e
- 26th January 2009, 22:34
Look in your PIC datasheet in the analog to digital converter section. There you will find the maximum impedance you may use with your Specific PIC model.

Usually a simple small trim-pot (single or multi-turn) work pretty well... You could also use a already made voltage reference, this doesnt require any calibration and tend to be more stable on the long run.

StoneColdFuzzy
- 28th May 2009, 19:39
OK, I'm using a PIC16F877a instead of the PIC16F877. I have a 4 MHz ceramic osc and I'm using the direct connection as on the Rentron page. I don't know if I need to do this or not, but I have the VSS and VDD pins tied together, respectively. I checked the connections and tested the LM34 with 5 volts. The LM34 changes output voltage fine I don't know if I goofed the code up or not, but I'm getting nothing. Here's the code:


@ device pic16F877A, xt_osc, wdt_off, lvp_off, protect_off

DEFINE loader_used 1 ' Boot loader is being used
DEFINE debug_mode 1 ' Debug sending Inverted serial data
DEFINE debug_reg portc ' Debug Port = PortC
DEFINE debug_bit 6 ' Debug.bit = PortC.6
DEFINE debug_baud 9600 ' Default baud rate = 9600
DEFINE osc 4 ' We're using a 4 MHz oscillator
DEFINE ADC_BITS 8 ' Set A/D for 8-bit operation
DEFINE ADC_CLOCK 1 ' Set A/D clock Fosc/8
DEFINE ADC_SAMPLEUS 50 ' Set A/D sampling time @ 50 uS
samples VAR WORD ' Multiple A/D sample accumulator
sample VAR BYTE ' Holds number of samples to take
temp VAR BYTE ' Temperature storage
samples = 0 ' Clear samples accumulator on power-up

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %00000011 ' Set PORTA.0,1,2,5 = A/D, PortA.3 = +Vref
PAUSE 500 ' Wait .5 second

loop:
FOR sample = 1 TO 20 ' Take 20 samples
ADCIN 0, temp ' Read channel 0 into temp variable
samples = samples + temp ' Accumulate 20 samples
PAUSE 250 ' Wait approximately 1/4 seconds per loop
NEXT sample
temp = samples/20
DEBUG "Temperature is: ",DEC temp," Deg F",10,13
samples = 0 ' Clear old sample accumulator
GOTO loop ' Do it forever

END

mackrackit
- 28th May 2009, 20:47
What do you have connected to AN3? If nothing then try
ADCON1 = %00000100

StoneColdFuzzy
- 28th May 2009, 20:57
What do you have connected to AN3? If nothing then try
ADCON1 = %00000100

I have the wiper of a pot connected and set at 2.55 volts.

~ Dave

aratti
- 29th May 2009, 00:04
I don't know if I need to do this or not, but I have the VSS and VDD pins tied together, respectively.

Dave, Vss is the ground or (zero volts) and Vdd is power or (+5Volts), from what you say it seems you have a short.

Remove it and re-establish the corrected connections.

Al.

StoneColdFuzzy
- 29th May 2009, 00:07
There is no short. There are two VVS pins and two VDD pins. They are tied together respectively. In other words, the VVS pins are tied to each other; the VDD pins are also tied to each other.

~ Dave

mackrackit
- 29th May 2009, 07:04
I had to set this up myself to find the problem.

When you use "DEFINE" everything has to be upper case. It would not work until I made that change. Problem was so simple but hard to see.


<html>
<body><!--StartFragment--><pre><code><font color="#000000"> <font color="#FF0000">DEFINE </font><font color="#0000FF">OSC </font>20
@ <font color="#0000FF"><b>__config _HS_OSC </b></font>&amp; <font color="#0000FF"><b>_WDT_ON </b></font>&amp; <font color="#0000FF"><b>_LVP_OFF </b></font>&amp; <font color="#0000FF"><b>_CP_OFF
</b></font><font color="#000080"><i>'DEFINE loader_used 1 ' Boot loader is being used
</i></font><font color="#FF0000"><b>DEFINE </b></font><font color="#0000FF"><b>DEBUG_MODE </b></font>1 <font color="#000080"><i>' Debug sending INVERTED serial data
</i></font><font color="#FF0000"><b>DEFINE </b></font><font color="#0000FF"><b>DEBUG_REG PORTC </b></font><font color="#000080"><i>' Debug Port = PortC
</i></font><font color="#FF0000"><b>DEFINE </b></font><font color="#0000FF"><b>DEBUG_BIT </b></font>6 <font color="#000080"><i>' Debug.bit = PortC.6
</i></font><font color="#FF0000"><b>DEFINE </b></font><font color="#0000FF"><b>DEBUG_BAUD </b></font>9600 <font color="#000080"><i>' Default baud rate = 9600
</i></font><font color="#FF0000"><b>DEFINE </b></font><font color="#0000FF"><b>ADC_BITS </b></font>8 <font color="#000080"><i>' Set A/D for 8-bit operation
</i></font><font color="#FF0000"><b>DEFINE </b></font><font color="#0000FF"><b>ADC_CLOCK </b></font>1 <font color="#000080"><i>' Set A/D clock Fosc/8
</i></font><font color="#FF0000"><b>DEFINE </b></font><font color="#0000FF"><b>ADC_SAMPLEUS </b></font>50 <font color="#000080"><i>' Set A/D sampling time @ 50 uS
</i></font><font color="#0000FF"><b>samples </b></font><font color="#FF0000"><b>VAR WORD </b></font><font color="#000080"><i>' Multiple A/D sample accumulator
</i></font><font color="#0000FF"><b>sample </b></font><font color="#FF0000"><b>VAR BYTE </b></font><font color="#000080"><i>' Holds number of samples to take
</i></font><font color="#0000FF"><b>temp </b></font><font color="#FF0000"><b>VAR BYTE </b></font><font color="#000080"><i>' Temperature storage
</i></font><font color="#0000FF"><b>samples </b></font>= 0 <font color="#000080"><i>' Clear samples accumulator on power-up

</i></font><font color="#0000FF"><b>TRISA </b></font>= %11111111 <font color="#000080"><i>' Set PORTA to all input
</i></font><font color="#0000FF"><b>ADCON1 </b></font>= %00000011 <font color="#000080"><i>' Set PORTA.0,1,2,5 = A/D, PortA.3 = +Vref
</i></font><font color="#FF0000"><b>PAUSE </b></font>500 <font color="#000080"><i>' Wait .5 second

</i></font><font color="#0000FF"><b>loop</b></font>:
<font color="#FF0000"><b>FOR </b></font><font color="#0000FF"><b>sample </b></font>= 1 <font color="#FF0000"><b>TO </b></font>20 <font color="#000080"><i>' Take 20 samples
</i></font><font color="#FF0000"><b>ADCIN </b></font>0, <font color="#0000FF"><b>temp </b></font><font color="#000080"><i>' Read channel 0 into temp variable
</i></font><font color="#0000FF"><b>samples </b></font>= <font color="#0000FF"><b>samples </b></font>+ <font color="#0000FF"><b>temp </b></font><font color="#000080"><i>' Accumulate 20 samples
</i></font><font color="#FF0000"><b>PAUSE </b></font>250 <font color="#000080"><i>' Wait approximately 1/4 seconds per loop
</i></font><font color="#FF0000"><b>NEXT </b></font><font color="#0000FF"><b>sample
temp </b></font>= <font color="#0000FF"><b>samples</b></font>/20
<font color="#FF0000"><b>DEBUG </b></font><font color="#00FF00"><b><i>&quot;Temperature is: &quot;</i></b></font>,<font color="#FF0000"><b>DEC </b></font><font color="#0000FF"><b>temp</b></font>,<font color="#00FF00"><b><i>&quot; Deg F&quot;</i></b></font>,10,13
<font color="#0000FF"><b>samples </b></font>= 0 <font color="#000080"><i>' Clear old sample accumulator
</i></font><font color="#FF0000"><b>GOTO </b></font><font color="#0000FF"><b>loop </b></font><font color="#000080"><i>' Do it forever
</i></font><font color="#FF0000"><b>END
</b></font></code></pre><!--EndFragment--></body>
</html>

Darrel Taylor
- 29th May 2009, 11:29
When you use "DEFINE" everything has to be upper case.
That's only true when using MPASM.
Since Bruce's program had @ device, the program was written for PM.exe, and is therefore not case sensitive.

Frankly, looking for a problem with one of Bruce's programs seems futile.

There's something wrong with the hardware. Connected to the wrong pins, grounds not connected across the breadboard, etc.
<br>

mackrackit
- 29th May 2009, 14:48
That's only true when using MPASM.
Since Bruce's program had @ device, the program was written for PM.exe, and is therefore not case sensitive.
Bruce did not have @ anything, but the OP did. So yes, the OP must be using PM.


Frankly, looking for a problem with one of Bruce's programs seems futile.
Agreed!!! I was just trying to find something obvious that the OP could be doing and thought I did.


There's something wrong with the hardware. Connected to the wrong pins, grounds not connected across the breadboard, etc.
<br>Must be.

StoneColdFuzzy
- 29th May 2009, 15:06
I didn't think that I changed Bruce's code, except for direct serial, but it's good to get more than one set of eyes on it. I'll keep checking connections; it's got to be the hardware. Thanks again y'all!

~ Dave

Bruce
- 29th May 2009, 15:39
Dave,

Are you getting anything from DEBUG, or is it just not showing any change in temp?

If DEBUG is showing a fixed value even when the temp changes, the sensor may be wired
wrong.

If you're using a boot-loader;

1. It most likely has the USART enabled, so you may need to disable the USART to use the
USART TX pin with DEBUG.

2. If your serial connection is through a MAX232 inverter, then you need to use mode 0
with DEBUG for non-inverted serial.

3. Most boot-loaders don't allow you to change config settings, so embedding them in your
code isn't necessary. And the loader might have some config settings different than what
you expect.

StoneColdFuzzy
- 29th May 2009, 16:41
Hi Bruce, no, I'm getting no DEBUG from the board.

I'm connected to the serial port through a 1k resistor which is why I have debug mode at 1.

How do I disable USART? TXSTA=0?

Bruce
- 29th May 2009, 16:53
RCSTA = 0 should do it. You just need to clear RCSTA.7 (SPEN) to disable the USART.

With a direct connection, make sure you have a common ground connection between your
board & the PC serial port.

StoneColdFuzzy
- 29th May 2009, 20:01
No change when USART disabled.

I'm pretty sure that it's a connection. I tried the code straight up except for debug mode at 1 and received 7 lines of temperature in Hyper Terminal, then it stopped.

Going back to double check everything.

~ Dave

Bruce
- 29th May 2009, 22:49
Darrel most likely hit the nail on the head. Sounds like some odd hardware problem, or a
bad connection.

Troubleshoot things one-at-a-time, and just setup a simple loop shooting serial data to
your PC serial port until you get the serial com thing working.

If it goes-like-splat, then you know there's a bad connection - or maybe even a problem
with your PC serial port.

Note: It might even be a problem with the PIC itself if the A/D is foo-bar. The ADCIN library
function is a blocking type with;

adcinloop
btfsc ADCON0, GO_DONE ; Wait for conversion to complete
goto adcinloop

If ADCON0, GO_DONE never gets cleared, it's a sit & spin function call...;o}

StoneColdFuzzy
- 30th May 2009, 00:47
Darrel most likely hit the nail on the head. Sounds like some odd hardware problem, or a
bad connection.

Troubleshoot things one-at-a-time, and just setup a simple loop shooting serial data to
your PC serial port until you get the serial com thing working.

If it goes-like-splat, then you know there's a bad connection - or maybe even a problem
with your PC serial port.

I have no idea how to begin setting up a loop like this.


Note: It might even be a problem with the PIC itself if the A/D is foo-bar. The ADCIN library
function is a blocking type with;

adcinloop
btfsc ADCON0, GO_DONE ; Wait for conversion to complete
goto adcinloop

If ADCON0, GO_DONE never gets cleared, it's a sit & spin function call...;o}

I have no idea what the above means either.

~ Dave

Archangel
- 30th May 2009, 01:43
I have no idea how to begin setting up a loop like this.Dave Just make a short loop sending out some text strings over and over, while you wiggle wires and such.




I have no idea what the above means either.

~ Dave Cause he misspeller foo bar, wich is an ackronym which I misspelled, FUBAR is the proper spelling you guess what the first 2 letters spell, the BAR means Beyond All Repair. It's like it's cousin SNAFU, Situation Normal All . . . .

Bruce
- 30th May 2009, 01:51
X VAR BYTE

Main:
FOR X = "A" TO "Z"
DEBUG X,10,13
PAUSE 500
NEXT X
GOTO Main
END

StoneColdFuzzy
- 1st June 2009, 18:42
Joe, Bruce,

Thanks!

Still nothing. I'm going to make up some new cables with fresh contacts and I might even try a different computer.

For the loop program; should I use config bits?

~ Dave

Bruce
- 1st June 2009, 20:17
Use the same config settings you used before.

StoneColdFuzzy
- 1st June 2009, 20:26
Solved! Bad number 2 contact on my 9 position D-sub connector. Thanks for all of the help!

Bruce
- 1st June 2009, 23:48
Per Darrel
There's something wrong with the hardware
Like always - Darrel nails it...;o}

StoneColdFuzzy
- 2nd June 2009, 13:44
Per Darrel
Like always - Darrel nails it...;o}

Yup, thanks again!

~ Dave

Darrel Taylor
- 3rd June 2009, 00:32
All I did was bet on a sure thing. (Bruce's code) :)

Although I did take in a big GASP when bruce said the bootloader may have left the USART ON.
That could have been it, and I'd have been bummed. :o

All's well that ends well.