Better way to check for inactivity?
Morrolan
Posts: 98
Hi, at the moment I have some code (see below) which waits for 2 seconds, and then increments a counter by 1. Once the counter reaches 15 (30 seconds), it triggers a subroutine to enable a low power mode for some external devices.
I can think of various ways of achieving this, but the problem is, I want the system to wake up ASAP when something is pressed, so the 2 second wait is unacceptable really (it was OK for testing).
I can use a word if need-be to get a larger counter, but I was trying to be economical on memory usage. Also, I don't want to write to a variable every cycle, as this would dramatically reduce it's lifespan I think.
(Yes and No are constants, 1, or 0 respectively - I think it makes for easier code reading, and as constants are compiled at tokenization, you don't waste RAM either)
Any ideas would be most welcome!
Morrolan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Flying is simple. You just throw yourself at the ground and miss.
Post Edited (Morrolan) : 9/25/2007 12:57:27 PM GMT
I can think of various ways of achieving this, but the problem is, I want the system to wake up ASAP when something is pressed, so the 2 second wait is unacceptable really (it was OK for testing).
I can use a word if need-be to get a larger counter, but I was trying to be economical on memory usage. Also, I don't want to write to a variable every cycle, as this would dramatically reduce it's lifespan I think.
(Yes and No are constants, 1, or 0 respectively - I think it makes for easier code reading, and as constants are compiled at tokenization, you don't waste RAM either)
Hold: DEBUG "LPM: ", LowPowerMode, "Counter: ", Counter, CR PAUSE 3000 IF LowPowerMode = No THEN IF Counter = 15 THEN PowerDown ENDIF IF (Contract = No) AND (Extend = No) THEN Counter = Counter + 1 GOTO Hold ENDIF IF (Contract = Yes) OR (Extend = Yes) THEN LowPowerMode = 0 GOTO Start ENDIF
Any ideas would be most welcome!
Morrolan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Flying is simple. You just throw yourself at the ground and miss.
Post Edited (Morrolan) : 9/25/2007 12:57:27 PM GMT
Comments
Beau Schwabe posted a circuit that lets you power down a Stamp, but have it "wake up" instantly when triggered by a button or other pulse.
Schematic: http://forums.parallax.com/attachment.php?attachmentid=38912
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
I've looked at sleep, and I think that the 18ms input/output switch would be fine, but that way it can theoretically take upto 2.3 seconds for it to respond after a press, and that is unacceptable.
At the moment the circuit is powered by a BS2e, so it would draw 4 times as much as a stock BS2 (plans to purchase an extra BS2 when I can afford it) whilst asleep, and it draws 8 times as much current during run.
I've since changed it to nap 4 (about 288ms) and use a byte for counter storage, but I still don't like it [noparse]:([/noparse]
On the plus side - with the BS2e i can write the counter to EEPROM, but on the downside, the current draw is much higher.
Would it make more sense to eliminate the counter, and simply use NAP on a short interval, so 1/4 or 1/2 second intervals?
Thanks,
Morrolan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Flying is simple. You just throw yourself at the ground and miss.
-Phil
For one thing, each time it wakes up from a nap or sleep, its activation time is a fraction of a millisecond instead of greater than 15 milliseconds like all the other stamps. That in itself saves a lot of power, because it can already run 70 or 80 instructions during the time that it would take for the other Stamps to even begin running code. It can wake up, increment a counter, test and go to sleep during an interval where the other Stamps would still be yawning in bed.
Another thing, the BS2pe has the POLLWAIT instructions, which allow the Stamp to wake up conditionally on the state of input pins. So you can have an 15 millisecond latency period for response to input changes and still draw minimal current. If you have an RTC with a heartbeat output, that can be one of the inputs to wake up the 'pe on the second every second.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
In the US, you pay $54 for a BS2e. In the UK, the cheapest parralax approved distributor sells it for £47 inc VAT. Converted back, that's $94.83 for a BS2e...
On a similar pricing structure, a BS2pe is $75 in the US, or £37 converted. If we estimate based the same profit/cost margin, then a BS2pe would cost me the equivalent of $135 approx - almost twice the US price.
Downside is, ordering them directly from Parallax makes minimal difference due to shipping costs.
From the Parallax website:
(BS2pe)
Sub Total: $75.00
UPS WorldWide Express (sm): $78.73
Grand Total: $153.73
So, kinda stuffed on costs, but hey, that's the rip-off that is the UK for you!
I think cost wise, I'll have to go with a BS2, as it's current draw isn't much more than a BS2pe, it just doesn't have POLLWAIT, so I'll just have to find another way arou nd it until I become rich
Thanks all,
Morrolan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Flying is simple. You just throw yourself at the ground and miss.
On the other hand, the BS2 would do just fine with NAPs to achieve lower current and also better response. Say,
NAP 3 to get about 0.1 second response time. That's the sort of thing I did with my data loggers before the BS2pe came along.
If you are storing your counter in a RAM variable, there is no concern about "reducing its lifespan". That is only a concern when writing to eeprom. Maybe I misunderstood that comment. Are you powering down the BASIC Stamp itself?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
The reason I'm using a BS2e is that it is the only available Stamp in my workshop at the moment! I suppose the best way for me to solve my supply issue would be to put a large order in directly with Parallax, and try and reduce costs that way. ( There sell LOADS of stuff I want...)
I have 2 projects going on at the moment - one is a remotely controlled paintball turret, with encrypted keyfob security (switches between disabled/semi/full-auto for safety) along with wireless camera etc. It uses 2 BS2's, one either end of an RF link, and I'm hoping to use a Playstation controller idea from a Nuts & Volts article - hopefully I'll be demo'ing this in May at Europes largest annual paintball game
The second project I'm not ready to release many details about yet unfortunately (possible money-making opportunity) and this is the minimal physical design, minimal power project I've mentioned above. I'm only prototyping at the moment, as if I did make it work, i'd buy OEM kits to further reduce the physical footprint.
Would napping for such a short period (150ms) really make that much savings in power terms, what with constantly having to wake from the nap, have a look around, then go back to napping? I'm eager for any savings really, i'm just shopping for peoples best ideas but I think a BS2pe is ideally the way forward. To answer your question about power, No, I haven't yet considered powering down the basic stamp, as so far I could either use sleep or use Beau's circuit above, but that involves more physical components which I don't really have room for without going to SMT components.
Ignore my last comment about the counter, it was late and I was tired and I wasn't thinking what I was saying! That's another problem with being in the UK - I post a comment on here in UK time, then have to wait pretty much 24 hours to check my response as I have to wait for you lot on the other side of the atlantic to wake up
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Flying is simple. You just throw yourself at the ground and miss.