powernap (version 30)
Pretty accurate-ish timing in python
Python's time.sleep() is rather bad for accurate timing.
It can sleep for less time than requested, if there's an interrupt.
Or longer, depending on what the scheduler is up to.
The rtc is set to block reads until divisions of 1/2048 seconds (default).
Repeated reading allows accurate "sleeping", although since this is really
repeated locking, it's called "napping", here.
nap(seconds) simply naps for the given period
rnap(seconds) is a padding nap. This for ensuring that the time between
two calls to rnap will be at least "seconds" long. I say at least, because
it could have been longer than the interval since the last call, in which case
there is no nap.
#Simply sleep for a given time
#Low accuracy, low priority setup
#Nap for 1 second
#the rest of your code
#A timing loop that pads to create a fixed length cycle
#Default frequency(2048) and priority (50)
#Do some stuff
#Then make sure that the cycle takes at least 1.5s
/** powernap - accurate sleeping for python
* Copyright (C) 2006 James Shuttleworth
* Contact: email@example.com
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|__all__ = ['rtc_on', 'rtc_off', 'nap', 'rnap']|
__author__ = 'James Shuttleworth'
__version__ = '$Revision: 30 $'