31kHz speed & once-a-minute wakeup-08M

lbenson

Senior Member
I'm wondering what is the relationship between low speed on an 08M (& others) using "poke $8F,%00000000" to set the speed to 31kHz, and the use of the timer1 timer routines of hippy, Brian Lavery, Jeremy Leach, kranenborg, and others to time intervals. Specifically, I would like to run mostly at 31kHz, but wake up approximately once a minute to switch to 4mHz to read a sensor and do something if necessary. The 08M must also be in a mode where it can respond to an interrupt.

No very great degree of accuracy is required--I just want to read the sensors about once a minute, and if the sensors are read because of an interrupt, the minute clock can restart after the program responds and reenters 31kHz mode.
 

manuka

Senior Member
Aside from timing issues,why such a low speed? If trying to trim average current,consider enabling BOD (on more recent 08Ms),as this cuts SLEEP drain to µA.

However you specify the need for interrupts ...

Edited by - manuka on 19/08/2007 01:44:35
 

lbenson

Senior Member
The low speed was to trim battery drain. I had understood that switching off BOD could enable the picaxe to run at very low voltages, but I need to read DS18B20 temperature sensors which, I thought required voltages above the BOD cutoff level. But would shutting off BOD and running at a slow speed give the best battery usage?
 

lbenson

Senior Member
Do I understand correctly that the pause command allows interrupts to occur, and that when the chip is run at 31kHz the pause stepsize is increased by the ratio by which the speed is decreased, i.e. 128, so that a pause period of 468 would give a pause of about a minute? So that the following code would do what I want? Would battery performance be increased by adding disablebod? I will probably be using 14Ms instead of 08Ms, and will switch on power to the DS18B20s before reading them.
<code><pre><font size=2 face='Courier'>
mainloop:
Do
setint %00001000,%00001000 ' interrupt on pin3 going high
poke $8F,%00000000 ' = 31 kHz
pause 468
SetFreq M4 ' = 4 mHz--per hippy
setint off
' now do something
Loop

Interrupt:
SetFreq M4 ' = 4 mHz
setint off
' now do something
setint %00001000,%00001000 ' interrupt on pin3 going high
poke $8F,%00000000 ' = 31 kHz
return
</font></pre></code>
Edited to go to 4mHz upon entering interrupt. Also, thanks to hippy replaced poke of $8F with SETFREQ M4 and, (&quot;GOTO deprecated&quot;), replaced goto with DO ... LOOP.
Edited by - lbenson on 19/08/2007 03:07:49

Edited by - lbenson on 19/08/2007 03:17:57

Edited by - lbenson on 19/08/2007 14:28:00
 

hippy

Technical Support
Staff member
Yes, by dropping to 31kHz everything just runs slower, pauses take longer but interrupts still work, providing the signal goes high and stays high long enough for it to be seen.

I've no idea about BOD, but to minimise current draw, you want to be at 31kHz as much as possible. You can rely on the interrupt fore-shortening Pause so you don't have to do a lot in there. &quot;SetFreq M4&quot; may be best for returning to 4MHz because I believe it checks the oscillator is stable before continuing...<code><pre><font size=2 face='Courier'>ReBoot:
Do
Poke $8F,%00000000 ' = 31 kHz
SetInt %00001000,%00001000 ' interrupt on pin3 going high
Pause 468
Poke $8F,%01100000 ' = 4 MHz
' Read sensors etc
Loop

Interrupt:
Return </font></pre></code>

Edited by - hippy on 19/08/2007 04:29:10
 

manuka

Senior Member
Yes- my experiences follow this proportionality too. THOUGHT:Guess you already know that even though DS18B20s draw ~8mA in their own right,they can be powered via a Picaxe pin HIGH as needed? Allow approx 1 sec. settling time before reading the temp value. I've found this energy saving a big help on small PV/coin cell powered dataloggers. Stan
 

lbenson

Senior Member
Stan--yes, I had planned to turn on the DS18B20s with a picaxe pin. I had hoped to read three of them, but on the 08M, that doesn't leave an output pin available for the turn-on (pin 0--serout; pins 1,2,4 DS18B20; pin three can't be used for DS18B20 because it is input only). What is the situation on reading DS18B20s with the 14M--may all the input pins be used?
 

lbenson

Senior Member
Just ran these in the simulator:
<code><pre><font size=2 face='Courier'>
#picaxe 14M ' compiles when &quot;readtemp 3, b1 is commented out

do
readtemp 1, b1
readtemp 2, b1
' readtemp 3, b1 ' when uncommented, gets &quot;Error: Invalid readtemp pin
readtemp 4, b1
readtemp 5, b1
loop

------

#picaxe 08M ' compiles when &quot;readtemp 3, b1 is commented out

do
readtemp 1, b1
readtemp 2, b1
' readtemp 3, b1 ' when uncommented, gets &quot;Error: Pin 3 cannot be used with this command
readtemp 4, b1
loop
</font></pre></code>
I don't have my 14Ms yet, but it looks like it could read 4 DS18B20s and use a spare output pin to switch them all on (via a transistor) when the program comes out of low speed mode.
 

hippy

Technical Support
Staff member
Pin 3 is the MCLR pin on the PICmicro so is read-only even though available as a digital input. The DS18B20 is a one-wire device and needs bi-directional comms, hence Pin 3 cannot be used.
 
Top