Counter for bs2
Archiver
Posts: 46,084
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
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
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...