High speed and temperature measurement.

rgooge

Member
Hi all,

I'm running a 20X2 at 64MHz, but need to make a DS18B20 temperature measurement on a regular basis. From what I can see this needs to be done at the standard clock speed of 4MHz for the 20X2 and I should be able to do a Setfreq M64 command right after the Readtemp command.

It doesn't appear to work, if the code has the Readtemp command active - the clock speed stays at 4MHz. Have tried Setfreq m4 before the Readtemp as well, no luck.

Once the Readtemp command is commented out, everything is back to running flatout, I might need to go the thermistor route, the temperature value is not critical.

The code goes like this..

- Loop -
..
Readtemp b.7,b21
Setfreq m64
..
..
..
- Go to Loop -

Any clues?

Thanks,

Rob.
 

BeanieBots

Moderator
I can't help with your exact question, however:-
I'm sure you are aware that the ReadTemp command can take up to 750mS to process.
If you use the one-wire commands, you could start a conversion, then do up to 750mS worth of code execution (which is quite a lot even at 4Mhz) and then read the temperature.

That would save you 750mS in your total loop time which may well more than compensate for running a slower clock speed.
 

Dippy

Moderator
I can't help with your exact question either.
The DS18B20 is an excellent device but not really appropriate in a high speed device.

Thermistors are good but require linearisation for accuracy - this can be code-consuming for anything half decent and Steinhart will be a struggle. (I have heard that a bodge with a paralleled resistor can help... never tried it)

A popular (and cheaper) option is the LM35 -
http://uk.farnell.com/national-semiconductor/lm35dz-nopb/temp-sensor-30v/dp/1469236

http://www.farnell.com/datasheets/7423.pdf

- though you will have to read the Data Sheet if envisaging lower temperatures.
 

hippy

Ex-Staff (retired)
You need a SETFREQ M8 before the ReadTemp. This works for me ...

#Picaxe 20X2
#Terminal 76800
#No_Data
#No_Table
Do
SetFreq M8
ReadTemp C.0, b0
SetFreq M64
Pause 1600
SerTxd( "b0 = ",#b0, CR, LF )
Loop

The SERTXD operates at 76800 baud so the switch to 64MHz is occuring. A PAUSE may be needed to give the PICAXE time to ramp up to correct speed ( may not be needed if SERTXD doesn't immediately follow the SETFREQ ) and there may be an issue with ProgEdit Terminal at 76800 baud; worked fine with a Terminal emulator.
 

westaust55

Moderator
Maybe I am about to learn something new here (learning keeps me out of that wooden box :) ),

I can't help with your exact question, however:-
I'm sure you are aware that the ReadTemp command can take up to 750mS to process.
If you use the one-wire commands, you could start a conversion, then do up to 750mS worth of code execution (which is quite a lot even at 4Mhz) and then read the temperature.

That would save you 750mS in your total loop time which may well more than compensate for running a slower clock speed.

I thought that when the READTEMP command was started, that the PICAXE waited until the conversion was completed.
How does one make the PICAXE achive other actions in the emantime or is this just an X2 capability?



You need a SETFREQ M8 before the ReadTemp. This works for me ...
Manual 2 states:
Affect of increased clock speed:
This command only functions at 4MHz. X1 and X2 parts automatically use the
internal 4MHz resonator for this command.
So:
- why use the SETFREQ at all before the READTEMP ?
- why use 8MHz rather than 4MHz ?
 

Dippy

Moderator
BB was referring to the One Wire commands.

I've never tried it but, on the face of it sounds a nice solution.
Not sure how you get the reply at the right time but I get the drift.
 

BeanieBots

Moderator
I was referring to the one wire commands.
ReadTemp does wait until the conversion is complete.

By using the one wire commands, you can tell the DS18B20 to start a temperature conversion and then carry on about your business while it does it. It does however mean that you MUST wait the required time for the conversion to complete before reading.

I have used this method within a one second loop.
Readtemp left me with 250mS to do all the required processing in the loop.
The one wire commands gave me almost the full one second.

Never tried it, but the one commands can be used to poll the DS18B20 to see if it is ready before making a read after a conversion has been started.
 

westaust55

Moderator
One wire - noted

I guess I have considered the READTEMP(12) as a specific one-wire command and not picked up on the OWIN / OWOUT (and related) commands
 

hippy

Ex-Staff (retired)
- why use the SETFREQ at all before the READTEMP ?
- why use 8MHz rather than 4MHz ?
I'll blame it on being Sunday morning for not reading the manual :)

M8 was chosen as that's the default X2 operating frequency so assumed that was what would be required, forgetting that READTEMP sorts itself out.

You and the manual are right, READTEMP does drop frequency to ensure the DS18B20 can be read then returns to its previous frequency. This works for me, serial always coming out at 76800 baud ...

#Picaxe 20X2
#Terminal 76800
#No_Data
#No_Table
SetFreq M64
Do
ReadTemp C.0, b0
Pause 1600
SerTxd( "b0 = ",#b0, CR, LF )
Loop
 

rgooge

Member
Ahh, The 750ms delay is the thing, funny I just jumped to the conclusion that 'it only takes a few clock cycles...' (must read the manual more closely).

But in this case, this is too much of a hassle. In my application I need a result that 'it's cool in here (<18-20C) or 'it's warm in here (> 28-30C)', so I'll whack a thermistor in there.

Thanks very much for all your responses.

- Rob.
 

hippy

Ex-Staff (retired)
That's one way to do it. Alternatives also include off-loading the temperature reading to an 08M and only reading the 08M when it's got a new reading. In most cases it's not necessary to read an ambient temperature every few microseconds and using the OWIN/OWOUT command could probably handle the DS18B20 as a background task; start a conversion, one second later read what it was, in the meantime use whatever the last temperature reading was as it's unlikely to have changed.

Thermistor is probably the simplest solution though.
 

Dippy

Moderator
Yes, for a thing where it's just a 'thermostat' ,which you will calibrate, the thermistor is the easiest solution. But jot down LM35 for future options.
 
Top