View Full Version : Sleep modes
danny.galyean
02-28-2008, 10:52 AM
I understand in Pro that there are 2 methods for sleeping. Can you explain the difference and lenghts of time that can be accomodated by each.
kbanks
02-28-2008, 11:04 AM
The SNAPpy function sleep(mode, ticks) takes two parameters.
Mode is either 0 or 1.
Mode 0 is less accurate, but can accept a larger ticks value. Each tick represents 1.024 seconds in mode 0, and you can sleep for up to 32767 ticks. Since the mode 0 clock is not very acurate (+/- 30%), the actual total sleep time is between 9 and 10 hours.
Mode 1 is more accurate, but only allows tick values of 1073 or less. So the maximum you can sleep is 17 minutes 53 seconds.
If you want to sleep for approx. 1.024 seconds, then mode 0 will use less power while sleeping.
If you want to sleep for more than a single tick, then mode 0 actually uses more power than mode 1.
Also keep in mind that in mode 1 you can work around the 1073 ticks restriction by doing multiple sleep command back-to-back.
sleep(1,1073) # sleep maximum number of ticks
sleep(1,1073) # immediately go back and sleep some more
Kevin Banks
martinnossel
09-23-2008, 03:03 PM
This seams the most relevant thread for this question.
the manual states "radio stays awake just enough to "count down" ... "
what does "count down" mean?
Martin
msellers
09-23-2008, 03:18 PM
If you tell a board to sleep for 60 ticks, it has to remain barely awake enough to count down those ticks and wake back up. Mode 1 and Mode 0 are implemented in different parts of the hardware which causes the difference in accuracy and current.
martinnossel
09-23-2008, 04:35 PM
Thaks for the fast answer!
Now where do I find info on "wake on pin" mentioned in another part of the forum. Also the reference manual refers to a Section TODO to find using hooks etc. Is this a TODO list that has to still be written, or a TODO list for me make up and ask?:)
I want the device to sleep say 5 minutes, wake up, read temperatures display them etc, (easy I hope). Then get specific data (hopefully) stored on powered nodes one hop away (routers in other systems), Data like new set control points, messages etc. Then it should send current values and non critical data to the "router or local master". This non critical data transfer between the "portal/coordinator" and the ''local masters" will be done in a polled manner.
Now I want to wake-up the sleeping "end node" device with an alarm input, have it do some more measurements and control some mechanical stuff, it will have to get current system settings for the local node, and if necessary notify the portal of a critical problem.
So for starters how to I wake up a sleeping device with say an a hook_gpin event?
Also, because I want to start testing it, is how should I get one portal to control (log) over a 1000 nodes? using a system of "local masters" with different netid's? is this practical or feasible?
Oh yes, is there a function to control an alphanumerc LCD, in 4bit mode yet?
Thanks
Martin
msellers
09-23-2008, 05:04 PM
There is a pinWakeup.py example script you can take a look at. I can send you a draft preview version of the next manual in pdf that addresses some of the previous sections that were left TO DO. As you have figured out, you can have a unit wake after some specified delay, or wake based on an input. We also support synchronized sleeping called SleePy Mesh where everyone wakes up together, does checking, reporting, etc. and goes back to sleep, eliminating the always on coordinator requirement. Portal can talk to 1000 nodes although logging data from that many might be best done with our gateway tool and your own custom application. You can run units on different channels and network addresses but portal is only going to see the network that its bridge device is part of. Check the pinWakeup and protoSleepCaster.py example scripts to see if that gets you going. We do support I2C, SPI and CBUS in the about to be released 2.1 version for talking to LCD displays, temperature sensors, external EEPROM, etc.
martinnossel
09-23-2008, 05:54 PM
Thanks for the fast answers.
The display is only going to be used if I can find a LOW power unit (would still be 500 uA:(). But they are nice for testing, and it will be a good way to start of learning phython. Serial dispalys are expensive and power hungry.
Can you recomend an existing 'print like' function or script that I could use as a template to write my own routine? also to address the ports must I use the poke comand? or will the be a snappy function for this.... Are the ports memory mapped?.
Martin
msellers
09-23-2008, 06:01 PM
One port is byte addressable but the upcoming 2.1 release will have built-ins for configuring, reading and writing SPI, CBus and I2C interfaces using GPIO pins.
I2C and SPI example scripts are installed with the new Portal.
kbanks
09-23-2008, 06:04 PM
Oh yes, is there a function to control an alphanumerc LCD, in 4bit mode yet?
I've been sitting on a pair of example scripts to drive "parallel" LCD displays (one script for 4-bit mode, one for 8-bit mode) for a while now. (I keep meaning to write the application note to go with them).
I just now went ahead and posted the scripts (still minus the Application Note) over in the Snappy Script Exchange.
So, no there is not a built in function, but you can do it via a SNAPpy script.
kbanks
09-23-2008, 06:11 PM
also to address the ports must I use the poke comand? or will the be a snappy function for this.... Are the ports memory mapped?.
You could control a parallel LCD using multiple writePin() calls (you would control each pin individually), but the pins for GPIO11 - 18 happen to reside on the same 8-bit processor port (which is memory mapped, and therefor "pokeable").
So, your options for adding a display are:
1) "Parallel" style - see lcd8bit.py and lcd4bit.py
2) Serial displays (hook to a UART)
3) SPI displays
4) IIC displays
5) Wiggle whatever GPIO pins you need via readPin()/writePin()
Reminder - RF Engines are 3.3 volt devices, not 5 volt! Be careful how you hook things up!
martinnossel
09-23-2008, 06:14 PM
fastest service I've ever seen!!;)
The SNAPpy function sleep(mode, ticks) takes two parameters.
Mode is either 0 or 1.
Mode 0 is less accurate, but can accept a larger ticks value. Each tick represents 1.024 seconds in mode 0, and you can sleep for up to 32767 ticks. Since the mode 0 clock is not very acurate (+/- 30%), the actual total sleep time is between 9 and 10 hours.
Mode 1 is more accurate, but only allows tick values of 1073 or less. So the maximum you can sleep is 17 minutes 53 seconds.
If you want to sleep for approx. 1.024 seconds, then mode 0 will use less power while sleeping.
If you want to sleep for more than a single tick, then mode 0 actually uses more power than mode 1.
Also keep in mind that in mode 1 you can work around the 1073 ticks restriction by doing multiple sleep command back-to-back.
sleep(1,1073) # sleep maximum number of ticks
sleep(1,1073) # immediately go back and sleep some more
Kevin Banks
For CEL ZIC2410 the sleep mode should be set to 0 (according to previous posts). But what about the accuracy? Is it still +-30%? And does the above statements also apply to ZIC2410?
mgenti
10-12-2009, 10:41 AM
No, the ZIC does not have the same +-30% on sleep mode 0 as the freescale based parts do.
Edgar.Gonzalez
03-15-2011, 11:54 AM
Hello I have a question about the ZICM2410P2 module, when I use the sleep mode the 4 leds of the module are turned ON.. why??
Jheath
03-15-2011, 11:42 PM
This very much depends on the sleep mode you are using mode 1 and 2 do not maintain I/O. Sleep mode 0 does hold I/O settings. This could explain why your LEDs do not remain their state during sleep.
kaycee
03-27-2011, 04:09 AM
I've read the CEL ZIC2410 notes about how to use the sleep and also the SNAP reference manual on sleep including the notes specific to the ZIC2410.
But I can't find the power usage in the 3 different CEL modes, so how do i determine the value of each mode. 2 of the modes do a reboot, so I don't think i can use them.
Can the wakeup be from an alarm triggerd via the I2C RTC?
Jheath
03-28-2011, 09:28 AM
SNAP uses the sleep modes of the underlying hardware (in this case, the ZIC2410) the current draw and operational characteristics for each sleep mode can be found in the associated datasheet.
SNAP supports timed sleep. For the ZIC this does use the on-board RTC.
hardtootell
04-12-2011, 03:56 PM
T... We do support I2C, SPI and CBUS in the about to be released 2.1 version for talking to LCD displays, temperature sensors, external EEPROM, etc.
Hi Msellers- do you have any python code or manual reference for EEPROM support? I need i2c for the 24LC series
thanks
HHT
gvoce
04-12-2011, 05:03 PM
http://www.jcwoltz.com/
I believe he has a board with eeeprom support already on it.
From the SNAP reference manual ......
For examples of using the new SNAPpy I2C functions to interface to external devices, look at the following scripts that are bundled with Portal:
i2cTests.py – This is the overall I2C demo script
synapse.M41T81.py – Example of interfacing to a clock/calendar chip
synapse.CAT24C128.py – Example of interfacing to an external EEPROM
Script i2cTests.py imports the other two scripts, and exercises some of the functions within them.
hardtootell
04-12-2011, 05:25 PM
Thanks for the quick answer on the i2c eeprom. Here's another question that is related. Is there a way to simply store the data in NVM until the primary micro-controller wakes up and can read it from the recipient node?
thanks in advance
HHT
Jheath
04-13-2011, 01:28 AM
You do have access to a number of user defined NV parameters (ID 128-254). But there is only a limited amount of memory available (ie you can't fill all 128 slots with large strings or large amounts of hex data).
Check out the saveNvParam(id, obj) function description in the SNAP Reference Manual for details and this function's return codes (it will tell you when you have reached your limit).
hardtootell2
04-19-2011, 03:09 PM
Hi
I seem to be having code writers block, or maybe this platform/python is just too new to me, but I am having a difficult time getting what I think should be simple to work.
I have the 2100 evaluation kit. I have done all the demos 2x. They all worked and are very cool. I have read nearly every python script through many times but I cannot seem to get the sleepymesh to wake up, read a pin and transmit data then go back to sleep.
I have tried cutting and pasting from various scripts into the sleepyexample.py. I have also tried it the other way around- pasting bits of sleep code into scripts like manymeter.py. (I have taken due care with the indentation etc that python calls for and spent 3 days on tutorials to try to make sure)
The scripts compile but either don't sleep or don't read the pin. Nothing seems to work.
Also, I am having a difficult time reading the UART via a 3.3V FTDI to USB. (I need this in order to allow my microprocessor to do something with the data). I am getting something but no matter what baud rates I try it still looks wrong
Any help would be very much appreciated.:confused:
Jheath
04-21-2011, 06:50 PM
A nice straight-forward example script that utilize sleep is protoSleepCaster.py that should be installed with Portal.
This script is very much like the mcastCounter script in the EK2100/Ek2500 demo kits, but sleeps in between button presses.
Pgelose
07-27-2011, 11:56 AM
Hello,
im currently working on a EK2100 board and im attempting to do something similar to something that was posted earlier in this post. I have a thermistor that I want to report to me every 15 min and sleep in between, and I would like the battery to last 3-5 years. The code does what I want it to, but it run for about a minute then stops, then picks back up a minute or two later. Also iv been testing at 10 seconds, but when ever I go over a minute the code doesn't work at all. Here is my code... I put the sleep in to 100ms event. Im just its some stupid timing issue
portalAddr = '\x00\x00\x01' # hard-coded address for Portal
NV_DEVICE_NAME_ID = 8 # The decvice name is stored at this location
OUTPUT_PIN = 12 # chosen because it was next to GPIO 11
ADC_PIN = 11 # chosen because it was the ADC pin closest to the corner
ADC_CHAN = 7
def startupEvent():
"""This is hooked into the HOOK_STARTUP event"""
global secondCounter, photoVal, requiredRange, buzzerPin, buzzerThreshold, power
power = 0
txPwr(power)
secondCounter = 0 # Used by the system for one second count
buzzerThreshold = 25
# Setup the buzzer
buzzerPin = 9
writePin(buzzerPin, False)
setPinDir(buzzerPin, True)
setPinDir(ADC_PIN, False) # NOT an output
setPinDir(OUTPUT_PIN, True) # IS an output
writePin(OUTPUT_PIN, True) # default to powering the circuit
initProtoHw() # Intialize the proto board
def timer100msEvent(currentMs):
"""Hooked into the HOOK_100MS event. Called every 100ms"""
global secondCounter, lqSum
secondCounter += 1
lqSum += getPercentLq() # get the link Quality every 100ms
if secondCounter >= 10:
sleep(1,10)
updateTempSensor()
outOfRange()
secondCounter = 0
batteryX10 = readBattery()
print 'battery=',batteryX10 / 10,'.',batteryX10 % 10
lqSum = 0 # reset the link quality sum after updating
def updateLinkQuality():
"""Send the current link quality back to Portal for logging"""
global lqSum, theLqAvg, secondCounter
theLqAvg = (lqSum / secondCounter) # calc the avg to send
# Send the data to the Portal node
eventString = "The link quality reading is " + str(theLqAvg)
rpc(portalAddr, "logEvent", eventString)
def updateTempSensor():
"""Send the current temperature back to Portal for logging"""
global curRawTemp
curRawTemp = tempRead() # Read the current value
# Send the data to the Portal node
eventString = "The raw thermistor reading is " + str(curRawTemp)
rpc(portalAddr, "logEvent", eventString)
def tempRead():
"""Read the current temperature from the sensor"""
# For this simple example we will not calculate the actual temperature in degrees
return readAdc(0) # Read Adc on GPIO 18
def getPercentLq():
"""Calculate the Link Quality as a percentage"""
maxDbm = 18
minDbm = 95
percent = 100 - ((getLq() - maxDbm) * 100) / (minDbm - maxDbm)
return percent
def outOfRange():
"""Sound the alarm if temp probe is out of range"""
if getPercentLq() < buzzerThreshold:
soundTheAlarm()
def getbuzzerThreshold():
"""Gets the current buzzer threshold"""
return buzzerThreshold
def setbuzzerThreshold(newThreshold):
"""Sets the current buzzer threshold"""
global buzzerThreshold
buzzerThreshold = newThreshold
def soundTheAlarm():
"""Sound the alarm"""
global countdown, buzzerPin
pulsePin(buzzerPin, 3500, True) # buzzer
def powerUpVoltageMonitor():
"""Power up the voltage monitoring circuit"""
writePin(OUTPUT_PIN, True)
def getPower():
"""Get the power lever of the radio"""
return power
def setPower(newPower):
"""Sets the power level (0-17)"""
global power
power = newPower
def powerDownVoltageMonitor():
"""Power down the circuit. Reported values are bogus"""
writePin(OUTPUT_PIN, False)
def readBattery():
"""returns battery voltage in .1 volt increments, assuming circuit is powered"""
refAdc = readAdc(ADC_CHAN)
battery = (10240 / refAdc) + 1 # + 1 to compensate for truncation effects
return battery
# hook up event handlers
snappyGen.setHook(SnapConstants.HOOK_STARTUP, startupEvent)
snappyGen.setHook(SnapConstants.HOOK_100MS, timer100msEvent)
Jheath
07-27-2011, 12:52 PM
Doesn't sound like you want the sleep call to happen within the tick then.
The way you have this it will wake, then immediately sleep 1 second later. I also do not see any reference to a 15 minute timer.
A couple things to note:
- SNAP has a 1 second hook if you need
- Sleep will happen immediately. If you have outstanding UART or radio communications, these might get delay until after you awake
- Execution of the script begins immediately after the sleep call once the device awakes. It will finish the function in which it was called, then the system will move on to the next event (be it a tick or other hook event).
- If you require accurate timing for sleep intervals, you might want to look into using an external RTC
Pgelose
07-28-2011, 09:36 AM
I edited my code to this...
def timer1SEvent(currentS):
"""Hooked into the HOOK_1S event. Called every 1s"""
global lqSum
lqSum += getPercentLq() # get the link Quality every 1s
sleep(1,9)
updateTempSensor()
outOfRange()
lqSum = 0
The Hook gets called every one second then it sleeps for nine. During that one sound it prints out "The raw thermistor reading is ###" when running with sleep(1,9) the number prints out every ten seconds but skips the number it started after a minuet on then every minuet after it skips the next increasing time increment. If I try and make it sleep any longer the timing gets screwed up. If i try sleep(1, 19), it prints the number every forty seconds. But if I watch the current it still sleeps for 19 and wakes for one second. It just doesn't print my reading.
Jheath
07-28-2011, 07:22 PM
Correct.
Note: Sleep will happen immediately. If you have outstanding UART or radio communications, these might get delay until after you awake
The RPC_SENT hook and STDOUT hook will provide a definitive indicator that the task has taken place and you are free to sleep without worrying about the data being held within hardware buffers.
Pgelose
08-01-2011, 10:47 AM
HI, Thanks for your help.
Im also working on a project for a door sensor (Reed switch). I wrote my code so that when the door is open it prints that it is open and vise versa. However I want it to sleep when the door is open or shut for long periods of time. I feel like I need to have a sleeping interrupt. My code looks somthing like this...
doorVal == doorRead()
if door == lastDoor:
return
elif door != lastDoor:
lastDoor = door
Print "The door is " + str(door)
doorRead() just tells if the door is open or closed and returns door.
Id like to have it sleep after the if door == lastDoor line untill that statement is false. Can I do this?
Jheath
08-01-2011, 02:16 PM
You can use certain pins on each RF Engine as interrupts from sleep (some MCUs refer to these as keyboard interrupts or KBI pins).
Check out the pinWakeUp files in Portal. Each platform has their own version specific to that particular MCU.
Note: The sleep() function is executed immediately. If you have outstanding radio or UART communications (waiting in the queue to be transmitted), these will be held until the device awakes.
Check out the RPC_SENT and STDOUT hooks for the ability to wait until data has definitely been sent before sleeping.
vBulletin® v3.8.0, Copyright ©2000-2012, Jelsoft Enterprises Ltd.