Retriggerable One Shot.......
Is there A way I can program, A Retriggerable One Shot, on the Propeller Chip? So I can adjust the RC Time. To turn on A Led, for A given time, and if the input pin is
still pressed (on and off) the led will stay on.
still pressed (on and off) the led will stay on.
Comments
Read push button input pin
if button pressed turn led on
else turn led off
wait retrigger_time
repeat
dira[noparse][[/noparse]6] := 1
dira[noparse][[/noparse]21] := 0
outa[noparse][[/noparse]6] := ina[noparse][[/noparse]21]
waitcnt(clkfreq/4 + cnt)
with the program
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
*Peter*
the hence retriggerable?
I have A Attachment on the circuit.....
Loop:
Read push button input pin
if button pressed timeout = retrigger_time + cnt
led = on
if cnt > timeout
led = off
All you need to do is translate that to spin or pasm.
The problem I have with your question is that on the one hand it is very simple yet on the other it depends how you want it to integrate into your program, there are so many ways and we don't have any details of your program.
I personally would not have a program stop just to handle a button but with so many cogs that might be ok for some.
What I normally do for these types of inputs and timing functions is simply to have a Spin/PASM function running in it's own cog that does nothing else but maintain some software timers, both countdown to zero and countup, The function usually handles specials as well as such things as button inputs and so on. Implementing a one-shot here is nothing more than reloading a countdown timer on a condition, while the counter is non-zero the output is true.
A code snippet for detecting that the button "is" pressed and retriggering the "one-shot" (the functions repeat loop cycles through the soft timers and decrements those that are non-zero)
and a snippet as to how the led would work in the timer function so that it would light while the "one-shot" was active.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
*Peter*
I want to use (Pin23, as the Input switch) and (pin15 of the led)
PUB Led Retriggerabel One Shot
ifnot ina[noparse][[/noparse]23] ' is button input low? (same as saying "if ina[noparse][[/noparse]button] == 0")
timer[noparse][[/noparse]0] := 500 ' reload timer 0 for 500ms
repeat
outa[noparse][[/noparse]15] := !timer[noparse][[/noparse]0] ' turn on active-low led if timer 0 is non-zero
I am bad, I CANT' REMEMBER HOW TO WRITE A EASY PROGRAM........
OBJ
timing : "background"
pub main
background.start ' startup background timing functions
So with this object you should never have to stop and wait for any events as long as you use the various timers all you need to do is load them up with an appropriate delay and then poll them for when they are zero, much like the example in the user processes section of the object itself.
If this looks a bit daunting then maybe you should post your code so I can show you how to incorporate it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
*Peter*
http://forums.parallax.com/showthread.php?p=617192
PS..Stop with the capital "A", it's annoying.
PPS..If you keep the thread in one place it might get answered more often.
to the Program, so I can adjust the Time.