I need some help with data collection/conversion processes

johnmobley

New Member
I am working on a circuit for my job that will hopefully get a reading from a "General Purpose Temperature Probe" (Analog Devices AC2626) which I will then like to convert to a calculated temperature and then displayed on an LCD. I would also like the data to be logged at 5 minuet intervals for up to one hour which can later be downloaded to a computer.

I have most of the physical circuit designed but when i began to write the code I came to a brick wall. I am looking at an output from the probe circuit of between 179mV and 380mV. I have been looking at the a/d feature on several of the PICAXE chips but i am not understanding how to use it.

I would like some help interfaceing the probe to the PICAXE. I am not completely new to programming but I have never done anything like this. I may also need help with the datalogging but that is just a side feature. I really want to get the "live" meter working first.

If you need any other information, please let me know...

I will appreciate any help I can get.
 

premelec

Senior Member
Resolution? Accuracy? A/D?

The A/D function is relatively simple - read the manual - and note that the reading your PICAXCE gets is ratiometric to the power supply voltage on the PICAXE - that is when the A/D pin is at 5 volts and the power supply is also five volts the input reading will be 255 for the simple READADC command... at lower input voltages the read value will be Vin/(5/255)....

Scaling the transducer input to higher voltages to get better resolution of the A/D readings is usually done with resistors and and opperational amplifier.... in effect multiplying the input voltage from the transducer and subtracting an offset... a search of this forum should give you a lot of the necessary information.

What you do with the reading once you've read it is to further calculate with that value to get some final result which you can store in eeprom locations to later recall and down load - this is a somewhat complicated process and perhaps you can find bits of programs to patch up in completed projects listed in the forum...

Give it some more thought and also provide specifications for resolution, accuracy and timing accuracy...
 

moxhamj

New Member
Yes, what he said...

I like to build these sorts of projects in stages. Start with your sensor and a picaxe, use a 'readadc10' and then a 'debug'. That will give you a feel for the numbers you will get (which will be between 0 and 1023, with 511 for 2.5V.

Probably you will then want to increase the resolution and we can look at op amps.

But before that, you might want to then get an LCD display to display a number or two. What sort of display are you planning on using?
 

retepsnikrep

Senior Member
I found the LM335 chip quite useful it has a 10mv/degree Kelvin linear response.

Here is a link to some data/ideas

http://www.ontrak.net/LM335.htm

And my code for a very simple 0+ C sensor.

readadc10 AnalogTemp, w0 ;Read Analog Temp Sensor (0-1023 10bit)

if w0 > 558 then ;Check for Temp < 0C
b0 = w0 - 558 / 2 ;Temp over 0C so calculate Temp in C
else
b0 = 0 ;Temp <= 0C so set Temp to 0C
endif
 

BeanieBots

Moderator
The analogue out from your sensor is very low for a PICAXE to read directly.
It will almost certainly require amplification to get reasonable readings but that depends on what level of accuracy you require.
As mentioned above, the analogue readings rely on the power supply as a reference, so your supply will need to be very stable and clean.

Are you limited to that sensor?
Alternatives (eg DS18B20) might be more suitable.
 

premelec

Senior Member
1ua/K

Well, I just looked at the AC2626 spec and it's like an AD590 - 1ua per deg K so at 300deg K
with the allowed 10K resistor at PICAXE AD input that's 3 volts at room temperature and 10mv per K deg change in voltage with the 10K load... could be a direct fit depending on your needed accuracy and resolution... However you DO need a regulated power supply to the PICAXE to provide stable ref voltage for the A/D conversion... no problem :)
 

MFB

Senior Member
AD590 needs voltage overhead

As I have mentioned before, the AD590 is an excellent sensor to used for long unscreened cable runs. However, with the negative terminal of this device connected to the junction of the ADC input and a 10K to ground, the positive AD590 terminal will have to be taken a few volts higher than the PICAXE supply. This is not usually a problem because common 5V regulators need a minimum input of at least 8V. Therefore, you can power the AD590 from this unregulated input supply.
 

johnmobley

New Member
Ok so now I have the temperature sensor being read by the readadc command. It appears to be working correctly now (Number goes down when cold, up when heated). I have however come to another problem. I have not worked with analog to digital conversions before. How do I do the conversion (or relation) between the output of the probe and reading of the adc pin. (ex. I know that the voltage input at the adc pin is 2.6 volts at aproximatly 86 F and I also know that the adc reading is 135.)
 

premelec

Senior Member
The first thing is: Have you established a regulated known voltage power supply to the PICAXE? Not just approximately X volts...

That's because the PICAXE uses it's supply as a reference for measurements. Any instability in the power supply will result in measurement instability or drift...

Then assuming you've got something that varies linearly with temperature you could take a high and low temperature reading and simply divide the readings by the degree difference to get the reading change per degree - Note that the resistor that the current is going through to give the voltage input to the A/D must also be a stable unit [metal film...] 10K or less.

Is this the information you require? Seems like you are almost there!
 

moxhamj

New Member
There will be some maths involved and the tricky part is keeping the resolution while doing it in integer maths. Generally, you try to get the numbers to use most of the range of a word, ie 0 to 65535.

First steps first - I tend to calibrate the probe (if possible) with 0C in iced water, and then 100C in boiling water. Say you got lucky and measured 350 on the adc in OC and 450 at 100C, then you would subtract 450-350 and get 100/100C or 1 adc reading/C. More likely you will get a fraction, and if it was 1.45 per C, then you might multiply that by 100 to get 145 and do all the maths as integers.

There are a couple more steps to get it to a digital readout. Maybe for starters you could give us the adc readings for ice water and boiling water. Either adc 0-255 or adc10 which is 0-1023 (use the latter as more accurate). Use debug to print the numbers to the PC screen and put it in a loop.

Plus what Premelec said too.
 
Last edited:

johnmobley

New Member
OK I do have a regulated voltage of 5VDC. I also know that the probe is a linear probe. I knew that I had to do a calibration on the probe and did that so I have the data for that.

Deg C Deg F ADC Reading
04 40 131
27 80 135
61 141 141
79 175 144
(All Readings rounded to the nearest Degree.)

If I understand correctly then my differences are as follows (Between Lowest and Highest):
Deg F Difference is 135
Deg C Difference is 75
ADC Difference is 13

so again if I understand the math correctly this would give me a .1 change in ADC per degree F or a .2 change in ADC per degree C.

Does the above sound correct? If not, what am I missing? I will most likely use readadc10 in the final project but for now I just want to understand the process using readadc. (I am of course assuming that the process is the same.)

If the above is correct, where do I go from there?
 
Last edited:

hippy

Ex-Staff (retired)
That suggest F = (C*2) + N, which is approximately correct. Good enough for how I use my cooker which is in degrees F when recipes are in degrees C ( +/- fudging factor ).
 

johnmobley

New Member
Ok maybe I am now again on track...while I was working on another project it occured to me that this would be a linear equation. I therefore found the formula for the resulting line which turned out to be y = (.1 * x) + 127. The y value would be my ADC reading and the x value would be my temperature in deg F. I then rearranged the formula so that the answer would be my temperature: x = (y - 127) / .1, I then multiplied every thing by 10 to make the calculations easier. So in the end the formula I have is:

(ADC * 10) - 1270 = Degrees F

I pluged all of my known values in and with the exception of my last set of data, everything worked. (I don't know why my last set is 5 degrees off.). Is this the way to figure this out or is there a more correct way to do this conversion?

NOTE: I think i figured out why my last set is off...at the resolution that I am running with just the readadc it ends up that there is a 10 Degree difference between each adc point. (ex. 40 = 131, 50 = 132, 60 = 133, etc...) I believe that I will deffinetly have to go with readadc10 :)

So now comes another question...currently I am running the adc as a byte. Obviously I need to run it as a word to use readadc10. Which bytes are designated to which words. I am running several bytes and do not want to have a conflict here.
 
Last edited:

lbenson

Senior Member
>Which bytes are designated to which words

Download the latest manuals and check: Manual 1, page 44 and following; Manual 2, page 10 and following.
 

johnmobley

New Member
Ok the 10 degree jumps were just a little to much so I re-did the calculations using readadc10. I also figured out which "word" I could use without conflicting with my other data bytes. My priliminary data is as follows:

Deg F - ADC10 Value
44 - 524
147 - 568

Using this data I then found the equation for the resulting line. I found the slope to be .43 and the y-intercept to be 505.08 making the equation y = (.43 * x) + 505.08 (Y = ADC10 Values and X = Temperature Deg. F)

I re-arranged the formula so that the answer would result in the temperature: x = (ADC -505.08) / .43; I then multiplied everything by 100 to make things easy. My final equation came out to be:

Deg. F = ((ADC10 * 100) - 50508) / 43

When I ran the circuit from a glass of ice water to boiling water I found the range to be within +/- 5 Degrees. This is not the accuracy that I originally wanted but i am deffinetly happy with this as it will work in the application for which I am building the circuit.

I would like to know; however, is there a better way to do this that would result in a tighter tolarance for accuracy?
 
Last edited:

premelec

Senior Member
Which AC 2626?

There are several accuracy versions of the AC2626 - which do you have? It is not so easy to get very accurate reference temperatures also - the ice should at least be distilled water in distilled water and of course the boiling point must be barometric pressure compensated...
Or if you have a very accurate thermometer you can submerge it with AC2626 into a stirred bath and see what that does for you... anyhow you are learning some of the finer points of accurate thermometry - continue on! [and check your actual math stuff as well...]
 

westaust55

Moderator
You will not achieve greater accuracy without increasing the magnitude of the voltage into the PICAXE analogue input. That will involve selection of a different temp sensor chip or adding an op-amp to expand the voltage range.

Alternatively, consider the DS18B20 which has a resolution of 0.0625 degrees using the READTEMP12
 

manuka

Senior Member
Time for a DS18B20? Although reading in °C, this will make your life easier and provide superior resolution. Convert to °F by the usual F=(9/5xC)+32 formula. It's long been the preferred PICAXE temperature reading choice (thanks to inbuilt reading routines). Stan.
 

premelec

Senior Member
DS18B20 F deg

Please note that the READTEMP12 comes out with a 2s complement value which is not quite straightforward to convert - After a bit of hair pulling [and help from this forum and Peter Anderson's URL] I got 2 DS18B20s and an 08M to send Morse values of two temperatures to 1 F deg... there's a bit of discussion about this on earlier posts -

Despite Stan's long ago statement that you can never have too many thermometers it's good to note that with one thermometer you know what the temperature is - with more than one you're never sure [it's like clocks...]. But my 'solution' was to round off to 1 deg...

The DS18B20 has quite a long read time - but then the AD part you are using has a bit of thermal lag beisides - I like 'em all - yes even thermisters with their curvey characteristics!
 
Last edited:

westaust55

Moderator
Please note that the READTEMP12 comes out with a 2s complement value which is not quite straightforward to convert
Rather easy to work with:

Code:
READTEMP12 temp, degC			; read the temperature in Degrees C.


sign = plus
IF degC > 2048 THEN ; do maths if negative 
	degC = degC ^ $ffff AND 4095 + 1
	sign = minus
	degC= degC * 10 / 16		; * 10 part is to get 0.1 deg resolution
ELSE
   	degC= degC * 10 / 16		; * 10 part is to get 0.1 deg resolution
ENDIF
sure those interested can assign some SYMBOL commands for the various variables
 
Last edited:

premelec

Senior Member
Deg F?

Westy.. that's C deg - what is your solution for F deg? I know you are better at coding than I am and hope you have something more compact than I came up with... thanks...
 
Last edited:

hippy

Ex-Staff (retired)
For positive degrees C, to get degrees F to one decimal place ...

ReadTemp12 pin, degC
degF = degC * 9 / 8 + 320

degC = 100.5'C = $648 = 1608
degF = 1608 * 9 / 8 + 320 = 2129

Display as 212.9'F

To two decimal places ...

degF = degC * 45 / 4 + 3200

degC = 100.5'C = $648 = 1608
degF = 1608 * 45 / 4 + 3200 = 21290

Display as 212.90'F
 
Last edited:

premelec

Senior Member
Warm climate

Nice to know y'all live where it's above 0 degC... My unit was measuring freezer temperature however I cut off at 0 DegF - strange how 0 is a bit of a sticky point...
 

hippy

Ex-Staff (retired)
This should convert what's read by READTEMP12 to degrees F to one decimal place. 'degF' is a two's complement number ...

ReadTemp12 pin, degC
If degC < $0800 Then
degF = degC * 9 / 8 +320
Else
degF = degC ^ $0FFF + 1 * 9 / 8 ^ $FFFF + 321
End If

+100.0000 C +0212.0 F
+080.0000 C +0176.0 F
+060.0000 C +0140.0 F
+040.0000 C +0104.0 F
+020.0000 C +0068.0 F
+000.0000 C +0032.0 F
-020.0000 C -0004.0 F
-040.0000 C -0040.0 F
-060.0000 C -0076.0 F
-080.0000 C -0112.0 F
-100.0000 C -0148.0 F
 

Attachments

hippy

Ex-Staff (retired)
Aha ... ReadTemp12 returns a 16-bit two's complement number ;-)

ReadTemp12 pin, degC
If degC < $8000 Then
degF = degC * 9 / 8 +320
Else
degF = degC ^ $FFFF + 1 * 9 / 8 ^ $FFFF + 321
End If

Seems to work with DS18B20 when I put an ice pack on it. Can't reach negative degrees F though ;-)

-000.2500 C +031.55 F
-000.3125 C +031.44 F
-000.2500 C +031.55 F
+000.0000 C +032.00 F
+000.4375 C +032.78 F
+000.8125 C +033.46 F
+001.1250 C +034.02 F
+001.4375 C +034.58 F
+001.8125 C +035.26 F
+002.1875 C +035.93 F
+002.5000 C +036.50 F
 

manuka

Senior Member
Unlike time,which will be the same "all over the house", temperatures can vary greatly within just a handspan. Ambient temps. usually change quite slowly as well, so the pedestrian DS18B20 750msec reading time becomes incidental.

For fear that this turns into a "dead accurate" quest, it may be worth pointing out measurement error basics + calibration,accuracy & reliability. Back in the 1960s-70s slide rule/analog. meter days these were easier to appreciate, but with modern multi-digit LCD readouts false accuracy can now easily arise. Educators know how this goes- students may record a 12 V SLA EMF as (say) 12.345 V on their cheapie DMM,& then proceed to use that as sacred in pages of subsquent calculations.

Recording a room as having a temperature of 21.34 °C may be totally unjustified. Although fine resolutions may be handy for trend spotting, IMHO there's little merit in specifing temps to 0.01°C when calibration against a standard hasn't been made. Aging issues of course mean recalibration to ensure reliability may be needed too- especially if a wide temperature range is experienced.

Metrology issues can be enormously important (& costly -US$500 to calibrate a thermometer is typical!), but at a non professional level can be lived with by keeping things in perspective.

Stan. of "you can never have too many thermometers"...
 
Last edited:

premelec

Senior Member
salt it!

Thanks for the additional code - Hippy put some sodium chloride or calcium chloride in with the ice - or use freeze spray for -15.7 F Deg [1,1,1.2-Tetraflouroethane] - propane liquid does the job too with more flammability but less other stuff...

Stan... there's times when I want resolution rather than absolute accuracy - e.g. whilst looking for cold fusion effects in beer... :)
 
Last edited:

Dippy

Moderator
Good points Stan.

People often forget the accuracy vs precision aspect.
And they forget heat capacity and hysteresis too.

And they forget that ice direct from the freezer isn't going to be at 0oC.

And they seem to think that their 2 quid Ebay DMM is as accurate as a £200 calibrated Fluke. (It may be more precise, but...)

The DS18 is a great little device, but sometimes a digitised and well set up LM35 can give better (and certainly faster) results.

Dippy. of "you can never have too many calculators around the house"...
and "you can't have too many Physics and Electronics lessons"
and "if you want me to do your homework then it'll cost you"
and "drying my hair in a tocamac can be very quick"
and "you must always read the device data sheets even if I forget to" ;)
 
Top