Shop OBEX P1 Docs P2 Docs Learn Events
Better way to check for inactivity? — Parallax Forums

Better way to check for inactivity?

MorrolanMorrolan Posts: 98
edited 2007-09-27 10:21 in BASIC Stamp
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)

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

  • ZootZoot Posts: 2,227
    edited 2007-09-25 12:58
    Check out this thread: http://forums.parallax.com/showthread.php?p=610791
    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
  • MorrolanMorrolan Posts: 98
    edited 2007-09-25 15:15
    That seems like a great idea, but unfortunately I don't have the PCB space - checkout my other current thread http://forums.parallax.com/showthread.php?p=677779 which is about reducing the circuit to it's smallest physically possible size - including mounting components under my Stamp.

    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.

    cry.gif

    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 Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-09-25 16:04
    Since your switch (according to your latest post in the other thread) is now commoned to Vdd, connect a .01uF cap from the input side (the side with the pulldown resistor) to ATN. This will reset the Stamp (thus waking it), whereupon you can read the switch input to see if that's what caused the reset. Of course, all your variables will have been cleared to zero, and thay may present a problem.

    -Phil
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-09-25 17:27
    I'd suggest that you switch to the BS2pe if possible. It has much much better characteristics for what you are doing.

    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
  • MorrolanMorrolan Posts: 98
    edited 2007-09-26 08:02
    Cost is a factor for me in the UK, as I pay almost double the price you can get stamps for in the US, but I do agree that a BS2pe would be more suited.

    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

    cry.gif


    Thanks all,
    Morrolan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Flying is simple. You just throw yourself at the ground and miss.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-09-26 18:18
    On the other hand, priority mail from the US to the UK is $20, and EMS express mail is $25. And your currency is stronger against the dollar now. I'm not sure about the £, but the it now takes >US$1.41 to buy a Euro.

    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
  • MorrolanMorrolan Posts: 98
    edited 2007-09-27 08:16
    Being the nice sort that they are, I'm sure Parallax don't mean for this to happen, but we get ripped off with most things over here. Costs us 25% more to buy a song from iTunes, and 15% more than the rest of europe. Same with Wii's and XBoxes and PS3's - the prices are always higher.

    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 roll.gif

    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 smilewinkgrin.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Flying is simple. You just throw yourself at the ground and miss.
  • skylightskylight Posts: 1,915
    edited 2007-09-27 10:21
    Im in the UK and agree about the costs in buying from distributors here. I've bought direct from Parallax taking advantage of the £-$ but still incur roughly £30 import duty and Vat each time on top of the order, one reason i'm not able to update my Pink module, just wish that I could get it upgraded over here.shakehead.gif
Sign In or Register to comment.