Simple thermometer...

Hi my name is Robert Johnson... Bought a Picaxe 40X2 Kit from RK Education, a RKPT40 seems to work and I wanted to use it as a master controller...
So I wrote a bit of code for a test. The code worked and then I modified it to get a more usable A/D value for scaling to the correct value.
The Code is as follows:
Code:
'****************************************************************************************************************
'		 Simple Temperature Monitor With an LM34 and a Serial LCD as a test for later code			     :
'		 25-2-2012 for use with 4 X 16 line display to display Raw ADC Data on ADC 
'
'****************************************************************************************************************				
'	
'
#picaxe 40X2                                              ; Define for 40X2 Chip
#no_table							; Define for No Lookup Tables
#no_data							; Define for No Data Tables
'								; Blank Line
fvrsetup FVR1024						; set FVR as 1.024V makes 4 MV per step @ 256 steps
adcconfig %1000						; set FVR as ADC Vref+, 0V Vref- (%1000) page 28 picaxe manual 2								;
main:								; Every Program has a Main
'								; White Space							
do								; All Set, begin loop
	low b.1						; Led on Port b.1, Start of Data Out (everyone loves blinking lights)
	readadc 0,b0					; Get the Analog Voltage on ADC 0						
	serout b.0,N2400,("Temp ",#b0,13,10)	; transmit Label "Temp " and raw ADC data to Serial LCD Display
	wait 1						; Wait long enough to read Serial LCD Display
High b.1							; Led Off Port b.1, End of Data Out
'								; More white space
loop								; Go do some more
' 
#rem
; I am a Nooob with the Picaxe but I have used the Parallax devices and Basic both commercially and for my own uses
; Since the Late '90's. I am a retired engineer with no small experience. The supply is bypassed at the device.
; Note the device (40X2) is powered from a 5.00V PSU from an old cell phone, 40X2 Vcc is 4.47Vdc
; (The cell phone chargers make great little sources for 4-6 VDC @ 100 - 500 Ma)
; If I remove lines 10&11 the device works as normal The Vcc is 4.47V so 4.47/256 = .0174 V per step and the value
; displayed (W/o lines 10&11) is 42 - 44 changeing slowly as the ambient temp changes.
; When I enable (remove the comment) the first value is correct for a reference of 4.5 V (42-44) 43 *.0174 = .753V
; that is corrrect as my room temp and the measured voltage at the LM34 agree @ 75.3 Deg F.(measures .753 Volts)
; all the rest of the data is 255 and unchanging. Where is my error?
#endrem
What did I do incorrectly?
 
Last edited by a moderator:

SAborn

Senior Member
Your code is a mess to read and you should use the code tags when posting code as it helps to keep it in a readable format.

Not sure on what you are doing 100% but i think you need to use Readadc10 command and not readadc, as readadc will only give a byte value (0 to 255) and readadc10 will give a word value (0 to 1024)
 

nick12ab

Senior Member
I think the problem is in the FVRsetup command, which turns off after each use
PICAXE Manual 2 p68 said:
To reduce power use the FVR module is also automatically disabled after a readadc command, so reissue the fvrsetup command again after the readadc if that feature is still required.
The FVR resetting will cause the next ADC reading to grossly differ from what you were expecting.

As SABorn has stated, you need to use the proper code tags as described in the 'Read me first' sticky thread when posting code to keep white spacing and improve readability - with Programming Editor now featuring a 'Copy for forum' option on the Edit menu (and the editor context menu which is exactly the same) which adds those tags for you. You can also type the tags manually or use the [#] toolbar button (not keyboard key) after clicking 'Go Advanced'.
 

manuka

Senior Member
Code:
The Code is as follows:

'************************************************* ************************************************** *************
' Simple Temperature Monitor With an LM34 and a Serial LCD as a test for later code :
' 25-2-2012 for use with 4 X 16 line display to display Raw ADC Data on ADC
'
'************************************************* ************************************************** *************
'
'
#picaxe 40X2 ; Define for 40X2 Chip
#no_table ; Define for No Lookup Tables
#no_data ; Define for No Data Tables
' ; Blank Line
fvrsetup FVR1024 ; set FVR as 1.024V makes 4 MV per step @ 256 steps
adcconfig %1000 ; set FVR as ADC Vref+, 0V Vref- (%1000) page 28 picaxe manual 2 ;
main: ; Every Program has a Main
' ; White Space
do ; All Set, begin loop
low b.1 ; Led on Port b.1, Start of Data Out (everyone loves blinking lights)
readadc 0,b0 ; Get the Analog Voltage on ADC 0
serout b.0,N2400,("Temp ",#b0,13,10) ; transmit Label "Temp " and raw ADC data to Serial LCD Display
wait 1 ; Wait long enough to read Serial LCD Display
High b.1 ; Led Off Port b.1, End of Data Out
' ; More white space
loop ; Go do some more
'
#rem
; I am a Nooob with the Picaxe but I have used the Parallax devices and Basic both commercially and for my own uses
; Since the Late '90's. I am a retired engineer with no small experience. The supply is bypassed at the device.
; Note the device (40X2) is powered from a 5.00V PSU from an old cell phone, 40X2 Vcc is 4.47Vdc
; (The cell phone chargers make great little sources for 4-6 VDC @ 100 - 500 Ma)
; If I remove lines 10&11 the device works as normal The Vcc is 4.47V so 4.47/256 = .0174 V per step and the value
; displayed (W/o lines 10&11) is 42 - 44 changeing slowly as the ambient temp changes.
; When I enable (remove the comment) the first value is correct for a reference of 4.5 V (42-44) 43 *.0174 = .753V
; that is corrrect as my room temp and the measured voltage at the LM34 agree @ 75.3 Deg F.(measures .753 Volts)
; all the rest of the data is 255 and unchanging. Where is my error?
#endrem
Robert: Et voila! Linear LM34 & 35 are traditional electronic devices (with outputs of 10mV per degree),but use of Maxim's digital DS18B20 is now the preferred PICAXE approach. Simply use the PICAXE "READTEMP" command, with syntax READTEMP pin,variable- refer manual for the simple hookup details. It's possible,given your Parallax background,that you may not have been aware of this?

As a non metric US citizen,perhaps the DS18B20's only downside is that readings are in °Celsius! Relax-it's easy enough to rustle up a °F conversion however with the usual F= 9/5 x C +32 formula in your code.
 
Yes however I had an LM34 from a job I did many years ago... And with the right setup this was what got me started with my thoughts described below. by multiplying the adc output by four and some cosmetics I have a thermometer with measurement accuracy better than the temp sense IC (the LM34) Analog is fun and easy one must match the application to the capabilities of the hardware, however.


Thank You one and all, and particular thank you for the info on resetting the FVR... for that matter and the purpose of this experiment which was how close can I come to 12 bit accuracy in 8 bits... I resolved that 4 mv was easily attained and muhs easier to process than dealing with 10 bits. and by extension at a hundred to one input division the accuracy becomes limited by the quality of the divider resistors (based on +/- bit noise count jitter) at 100/1 input attenuation 1 count is 0.4V... Not too Shabby.... Just got back from testing the 're'set the FVR and Thank You AGAIN SIR's one and ALL... IT WORKS
Robert K. Johnson Sr.
 
Rick, Thank You Personally that worked... I did leave a rather long note at the bottom as to my intent in this excercise, I do hope I wasn't too mush a 'smart alecky' kinda guy
Robert K. Johnson Sr.
 
Thank You and the Fix

Hello... It's Me...
fvrsetup FVR1024 : Reset FVR after conversion
let w4 = 4 * b0 ; Convert temp @ 4mv/step
let b6 = w4/10:let b7 = w1//100 ; parse temp whole and fractional numbers
serout b.0,N2400,("Temp ",#b6,".",#b7," Deg F.",13,10) ; transmit Label "Temp " and scaled/parsed data to Serial LCD Display

RE issuing the FVRsetup command fixed my real quandary, had I only read the whole page 'stead of the config and sample code...
That and the two lines that begin with equates form a Nice Accurate Fahrenheit Thermometer, Thus completing my first minor PicAxe
project.
Btw I found DS18B20-22? albeit with cables for a min of $2.95 free shipping, three LM35's or 35's for my European Cousins... are available
for 1.99 or so on Ebay, and as my code sample shows the whole thing is rather simple... too.
Robert K. Johnson Sr.
 

mrburnette

Senior Member
...by multiplying the adc output by four and some cosmetics I have a thermometer with measurement accuracy better than the temp sense IC (the LM34)...
Robert K. Johnson Sr.
Robert, your statement is confusing to me; I fully understand that you can display to a finer decimal resolution (stepped value) but my belief is that accuracy can never be greater than the accuracy of the LM34
National:

The LM34 does not require any external calibration or trimming to provide typical accuracies of ±½°F at room temperature and ±1½°F over a full -50 to +300°F temperature range. Low cost is assured by trimming and calibration at the wafer level.
...
But I have been having a particularly 'bad run of it' with forum dialog over the past 18 hours so I'm going to be a bit sheepish with this response.

- Ray
 
Sorry Gents the code intended to not in any way degrade the sensor, therefore, had to be better than the sensor and the issue wasn't the sensor but how I could use the code to my best advantage.
I thought this code was clever enough to post (the concept not my quirky? implementation) in measurement the granularity should be about n/2 where n is the smallest expected change, 1 deg in this case.
The decimal fraction stuff is cute but really wasted unless the general trend is of interest as well and my 'n' in this case is .4% equal to if not better than the sensor.
R. K. Johnson Sr
 

mrburnette

Senior Member
Don't use 'sorry' Robert or we'll all have a cry-in and short something!
I just wanted to ensure I had not missed anything... it happen and is more often of late. I was remarking to an old friend at dinner recently that I had forgotten more than I had ever learned... fortunately, he is worst off than I and it was lost on him.

You may find this link interesting: http://www.phanderson.com/picaxe/picaxe_thermistor.html

- Ray

PS... we in the forum usually recommend against full email addresses as "handles" just to keep junk mail down. Your choice however.
 
It turns out that the 'cute demo code' Has one Major restriction... With FVR set at 1.024 v the Max measurable temp is 102.4 degrees and setting FVR to 2048 will cause the step size to be 8 mv, still under 1% but not as cute. readadc10 would be as advised, a better choice if greater accuracy is needed and the line that ends in let b7 = w4//100 should have :let b7 = b7/10 added to the end... sorry about working out the code snippet here, It does work rather nicely though.
R. K. Johnson Sr. (yes there is a Jr.)
 
Excellent and most typical of Anderson, Thorough accurate and concise... However I am lazy and if I can buy it in a can I will not make it. Changing the FVR value in my 'little' piece of code to 2048... Still leaves the 'code' I wrote to about 1/4 of the size of Mr. Anderson's data table.
As to dinner, I forgot how to do that trick (thermistor) long ago... It was a basic engineering problem I had to solve for the copper in series with the thermistor... 1 Km... Not my orders they fired the guy that implemented the 'sensor' in a 'difficult' 1Kw radio transmitter. the changing copper was playing havoc with temp readings... some several years after the 'sensor' was put in place the power transformer for the transmitter failed due to lateral ground fault currents during a lightening strike(pole "Ground" and Shack "Ground at tremendous potential difference) at any rate someone noticed that the temp swung more with the transmitter dead than powered up and operating at full power level... the fix turned out to put the data on the 'orderwire' (unit to unit yoice channe)l of the Microwave link (a 10 Khz freq mod subcarrier... LM567's on both ends) and I will fix the email, generally if I don't know the person I either spam filter it or just trash it, Never open 'em.
R. K. Johnson Sr.
 
Top