Shop OBEX P1 Docs P2 Docs Learn Events
how do I quickly respond when system is "active", but also go to sleep when sys — Parallax Forums

how do I quickly respond when system is "active", but also go to sleep when sys

wheelguywheelguy Posts: 4
edited 2007-07-27 16:43 in BASIC Stamp
First timer here - this forum is amazing! I·looked at the most recent 400 posts, and searched, but didn't see anything like the following problem...

I plan to use the BS2pe to perform round counting·in an M16 type weapon. First, a nice paint job - then smartify it with some software control scool.gif

So, I·need for the system to respond to·roughly 1 millisecond events (detecting bolt·movement and trigger status), so am using
POLLWAIT 8 'dont sleep while I wait for a button to be pressed
To wait for any one of·8 inputs to happen, then I take the appropriate action.

That part of the system works well, but I also need to put the system to sleep if it hasn't seen any events for a period of 5-99 minutes (configurable). However POLLWAIT will simply wait forever - what I need it to do is wait until either an event is detected OR a time period has elapsed - then I could loop in order to count the number of "timeouts".

Is there a way of doing this purely in software - perhaps making use of the WatchDog timer or oscillator that is built into the Stamp? I shouldn't use an I/O pin for this feature, because they are all spoken for. Guess I am hoping for a behavior tweek to POLLWAIT, but any software solution would be wonderful.

If it is just not possible otherwise, then any suggestions on a simple external timer·that I can attach to one precious I/O pin·cry.gif·? It doesn't have to be accurate, should activate the pin about every 100ms,·require no ongoing software overhead (such as charging an RC circuit), and no additional circuitry beyond the chip except wiring.

Sorry if this question has been asked before·blush.gif

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Be safe, help others.

Post Edited (wheelguy) : 7/26/2007 8:01:50 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-26 20:23
    There isn't a simple way to have a Stamp respond to either a signal change or an elapsed time and most external timers need at least two pins to access (start interval and sense end). The BS2pe could use a DS2415 which is a 1 second resolution timer that uses the 1-wire protocol and would only need one I/O pin.

    Counting or timing multiple events on the order of 1ms with a Stamp is always difficult since you can't execute many statements in that interval. Maybe you could use some external hardware to help out like some set/reset flipflops

    The WatchDog timer is used already internally for the SLEEP and NAP statements and there isn't any other access to a timer other than as part of various statements.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-07-26 21:50
    Anything you do is going to require a at least some software overhead, but not much.

    An RC timer on a free pin would not take much overhead at all. When an event on that pin is detected, simply increment your seconds counter, recharge the capacitor, and go back to POLLWAIT 8.

    You could possibly avoid using another pin by multiplexing the wakeup into one of your existing POLLIN pins by use of a diode or transistor. One thing that comes to mind is a 555 timer set to generate very narrow pulses (just a few microseconds). The pulse would be so narrow that it disappears by the time the interpreter gets around to looking at the input state. If it sees no change in state, that means ~0.1 second has passed. A lot depends on how long the natural button events are and how you set up the POLLing. Are you using POLLMODE 10?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • wheelguywheelguy Posts: 4
    edited 2007-07-27 00:46
    Thanks for the great advice gents - that is exactly the info I needed smile.gif . Fortunately, only 1 pin requires high speed - the·one that is sensing the weapon's bolt. All of the other·inputs are in human time scales. So,·I'll forget about the software route, and try multiplexing this task using·the good old RC approach·on an existing input. Initial testing shows that 0.1 seconds of charging a 0.1uf capacitor across a 700k resistor gives me about 0.12 seconds of delay -·before the Input event wakes·it up from POLLWAIT 8. Figured out a way to do the capacitor charging while in the "human timescale" part of the code so that I won't miss a round count - sweet!

    You guys totally rock!!!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Be safe, help others.

    Post Edited (wheelguy) : 7/27/2007 5:16:50 PM GMT
  • wheelguywheelguy Posts: 4
    edited 2007-07-27 16:43
    Correction - I ended up using a 10Meg ohm resistor in parallel with a 0.1uf capacitor to give a time delay of 0.833 seconds using the following test code. Zero extra Pause time delay is needed to charge the capacitor due to its small size yeah.gif

    TestRcTimeout:
    DO
    ·OUTPUT rcSleepTimerPin
    ·rcSleepTimer = 1
    ·'PAUSE 600 'wait to charge capacitor
    ·w = 0
    ·INPUT rcSleepTimerPin
    ·DO
    · w=w+1
    · IF rcSleepTimerPin = 0 THEN EXIT
    ·LOOP
    ·DEBUG "Loops=",DEC5 w,CR
    ·PAUSE 1000
    LOOP
    END


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Be safe, help others.

    Post Edited (wheelguy) : 7/27/2007 5:16:29 PM GMT
Sign In or Register to comment.