Stamp basic 'PAUSE' statements to allow 'stabilization', 'settling', 'device ta
plankton
Posts: 18
Here are typical program fragment where the author adds a pause or timeout to 'allow to stablize'
or for the conversion of temperature (DS1820), or for an LCD module to store and display characters.
Question for the experts is how are these timeouts calculated and is there a provision in stamp programming language to fork off that subtask and come back later when the task is complete, so I can go on to the next task and either get interrupted when the subtask is complete or just the retun value of the command to see if it has completed yet?
In the case below we wait an entire second 'pause 1000' for the direction of two pins to stablize.·
In the other case we wait 750ms for the DS18S20 to do the 12 bit temperature conversion. [noparse][[/noparse]Looking at the DS18B20 which allows you to choose 9, 10, 11 bits and trade off accuracy for speed]· But, what I'd really like to do is issue the command then check later to see if the device has completed it's task.
Thanks in advance.
· DIR7 = 0················ ' serial input
· DIR8 = 1················ ' serial output
· OUT8 = 0················ ' be sure SerOut pin is stable at zero
· PAUSE 1000·············· ' allow to stabilize
· 'SEROUT LCD, 84, [noparse][[/noparse]"?B7E"]········· '50% baclight
··· PAUSE 200····················· ' pause to allow LCD EEPROM to program
· SEROUT LCD, BaudMode, [noparse][[/noparse]"?y0?x00"]···· ' cursor at line 0, col 0
····· PAUSE 500
··· ' channel 0 - ambiant temperature
··· SEROUT 8, BaudMode, 10, [noparse][[/noparse]"P0", "W0cc", "S044"]·· 'perform temp measurement
····· PAUSE 1100···································· ' wait for conversion to complete
Happy Stamping.
Scott
Post Edited (plankton) : 6/18/2009 4:15:44 PM GMT
or for the conversion of temperature (DS1820), or for an LCD module to store and display characters.
Question for the experts is how are these timeouts calculated and is there a provision in stamp programming language to fork off that subtask and come back later when the task is complete, so I can go on to the next task and either get interrupted when the subtask is complete or just the retun value of the command to see if it has completed yet?
In the case below we wait an entire second 'pause 1000' for the direction of two pins to stablize.·
In the other case we wait 750ms for the DS18S20 to do the 12 bit temperature conversion. [noparse][[/noparse]Looking at the DS18B20 which allows you to choose 9, 10, 11 bits and trade off accuracy for speed]· But, what I'd really like to do is issue the command then check later to see if the device has completed it's task.
Thanks in advance.
· DIR7 = 0················ ' serial input
· DIR8 = 1················ ' serial output
· OUT8 = 0················ ' be sure SerOut pin is stable at zero
· PAUSE 1000·············· ' allow to stabilize
· 'SEROUT LCD, 84, [noparse][[/noparse]"?B7E"]········· '50% baclight
··· PAUSE 200····················· ' pause to allow LCD EEPROM to program
· SEROUT LCD, BaudMode, [noparse][[/noparse]"?y0?x00"]···· ' cursor at line 0, col 0
····· PAUSE 500
··· ' channel 0 - ambiant temperature
··· SEROUT 8, BaudMode, 10, [noparse][[/noparse]"P0", "W0cc", "S044"]·· 'perform temp measurement
····· PAUSE 1100···································· ' wait for conversion to complete
Happy Stamping.
Scott
Post Edited (plankton) : 6/18/2009 4:15:44 PM GMT
Comments
Suppose you want a delay of 1000 mSec. Instead of using the the Pause 1000 command and just waiting, write a short subroutine that has a Pause 50 in it.
Now, in your main program, call the subroutine and keep track of how many times the subroutine is called. When you've called it 20 times (more or less), you've paused 1000 mSec, but you've had 20 opportunities for the processor to do something else.
There are numerous ways to implement this "tick" checking, including a chip that generates the ticks for you, rather than a subroutine.
Cheers,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
Some devices have a status register with a "done" flag or an actual hardware pin with that function. For example, the DS18B20 command $44 to convert temperature can be followed with read time slots, which return a 0 if the device is still busy converting or a 1 if it is finished. However, the timing of the 1-wire protocol is in the microsecond range, so it is not something that can be easily done on a Stamp. When the done flag is accessible, it can often substantially speed up the process over the worst case. However, you have to watch out in some cases to avoid the possibility that the device will lock up you system if it is unplugged etc.
In any case, the program can do other tasks during the waiting time. Say it has 1100 milliseconds to kill. It can go off and execute other tasks and then come back to read the temperature. The trick is to be sure that the required time has elapsed, so you have to have a good idea how long the other tasks are going to take if there is any danger of cutting it close.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Scott
The output looks like this:
08 18 06 06:06:58
Amb Temp 76.3
Tank Temp 77.5
Post Edited (plankton) : 6/19/2009 5:02:21 AM GMT