Timing and DS18B20

ArnieW

Senior Member
I'm working on a project that requires a picaxe 'scan' inputs on a regular loop. I want it to respond quickly to buttons being pressed, and for it to read a couple of temperatures.

I'm aware that the DS18B20s take 750mS to complete a read, but was wondering what happens during that time. Does the picaxe wait until the variable is filled with the read value, or does it continue through commands and fill the value when it arrives?

If the picaxe does wait for 750mS, are there any clever workarounds that people have come across?

Thanks in advance, Arnie
 

BeanieBots

Moderator
Unfortunately it waits the full 750mS and interrupts are missed while it waits.
I am currently working on a project that requires 3 DS18B20s to be polled frequently and also respond to interrupts for user buttons. The method I am exploring is to use two 28Xs. One handles the DS18B20s and the other controls the interrupts and LCD display. They communicate by a shared I2C bus and I2C RAM. The temperature is placed in RAM and can be read whenever when required.
I have chosen this method over serial comms because serial also has the problem that it cannot be interrupted.
 
Suggest a slow background task to read the temps and update a temperature holding register.

When the button is pressed then just spit out the most recent reading... Immediately.

There are few temperature situations where temperature changes rapidly so this should work in most cases.

I setup I tinkered with used polled / slaved 08M doing Multi DS18B20 reads under the control of another 08M via a serial handshake.

After each serial handshake between 08M's the slave 08M set about going around the DS18B20's and gathering another round of readings. (which takes several seconds)

I set up the master 08M that sent RF serial data direct into XL live (via another 08M RF Rx!) This cycle repeated approx every 1 minute but this could be altered depending on the need for speed sample rate and amount of data needed in XL. The master would even send out a refresh of the readings within the 1 minute if needed.

The fun challenge was to get word variable resolution data transferred between 08M's.

- Andrew
 

Michael 2727

Senior Member
This will read a single DS chip using an 08M
It should be able to read 3 or 4 using an 18X.(Not all at once mind you)
<A href='http://www.siliconchip.com.au/cms/A_105849/article.html' Target=_Blank>External Web Link</a>
Its not LCD based, just another way to approach Temperature readings.
 

BeanieBots

Moderator
I have just tried something which might act as a compromise. You have not stated if your inputs simply need to be read frequently or if they could drive interrupts. If they can be used to drive interrupts then the following might also work for you.
Have your normal loop that reads temperature and does whatever it needs to do.
When a button is pressed, set a flag that can be read in the main loop.
Assuming the button is used to set some parameter, make the first press (which might have to wait 750mS to be recognised) simply enter the &quot;Setting&quot; state. (first level of a state engine).
The main loop now reads the flag and ignores any DS18B20 reads and uses the last value instead.
Thus, the 'control' loop keeps going but subsequent button presses are processed immediately without the occaisional annoying wait caused by the readtemp command.
For safety, I also incorporated a timeout in the state engine.
This may or may not be applicable to your application but it has worked quite well in mine which is a PID temp controller with the ability to change all paremeters, set points and RTC via 3 interrupt driven buttons. Only fresh temperature readings are lost during a new setup, the control loop keeps going.
 

hippy

Ex-Staff (retired)
Using Reset itself might also work. On some PICAXE's I believe that SFR at $C0 upwards isn't cleared on reset so could be used to hold last values read etc across resets.

This could be handy for slaves reading DS18B20's. Although there will need to be a delay for reset, it will be far less than the 750mS worst case response. A checksum on SFR values would allow the PICAXE to determine if it has read valid data already or not and a stored value can be used to ensure multiple DS18B20's are read cyclicly.
 

BeanieBots

Moderator
Hippy, nice idea.
Reset takes around 75mS plus a little extra for it work out what's going on so quite a viable option.
 

ArnieW

Senior Member
There are some great ideas in this thread so thanks to all who have contributed.

I'm actually after a tight timed loop because I would like to control a heater and vary the power on it by increments of about 5%. So 10 to 20mS loops would be ideal in my application.

A quick loop means quick scanning of press button inputs as well.

I think at this stage a slave picaxe that does the temperature work and has a variable ready when the master wants it is probably the solution.

I'll do some more reading on i2c as well before I work out how I will address the issue.

It explains why my current picaxe &quot;misses&quot; serial comms at times.

Arnie
 

BeanieBots

Moderator
I wonder if Technical would consider an extra command for the DS18B20?
StartConversion &amp; ReadResult.
The user could then put the 750mS to good use.
 

ArnieW

Senior Member
BeanieBots,
that is an excellent idea. Please technical ...

And LM35 - wow, not something I've thought about for a long time, but it takes me full circle - my machine began as an all analog device, and I'm now so in love with things digital that I'd all but forgotten about them. ;-)
 
Top