Shop OBEX P1 Docs P2 Docs Learn Events
Counter for bs2 — Parallax Forums

Counter for bs2

ArchiverArchiver Posts: 46,084
edited 2002-06-03 05:24 in General Discussion
Hi,

I am trying to count inputs for the BS2. What I need to do is
set up a timer for say 10 seconds. If the input receives say 3 low's
in 10 secconds then it sends a low to pin 4, or if it receives 5
low's in 10 seconds then it sends a low to pin 5. Can anyone help me
out with a some coding? Thanks, Chris

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-06-03 05:24
    Chris-

    This ought to get you started. Assume low level presented to IN0:

    HIGH 4
    HIGH 5

    again:
    FOR i = 1 TO whatever
    this = IN0
    counter = this ^ last * ~this + counter
    last = this
    NEXT

    OUT4 = ~( counter / 3 MAX 1 )
    OUT5 = ~( counter / 4 MAX 1 )
    GOTO again

    Set up your FOR-NEXT loop to consume 10 seconds (may need nested
    loops). Note the expression "this ^ last * ~this" will be 1 only
    upon a high-to-low transition (if my thinking cap is on straight).
    With enough tweaking, you ought to be able to get within about 1% of
    your desired 10 second period. If you need greater timer accuracy,
    you'll need an external timer of some sort.


    Regards,

    Steve

    christopher41877 wrote:

    > ...I am trying to count inputs for the BS2. What I need to do is
    > set up a timer for say 10 seconds. If the input receives say 3
    > low's in 10 secconds then it sends a low to pin 4, or if it
    > receives 5 low's in 10 seconds then it sends a low to pin 5...
Sign In or Register to comment.