Button with timed output - flipflop and time delay
22 Aug 2014 21:48 - 22 Aug 2014 21:50 #50186
by green751
Button with timed output - flipflop and time delay was created by green751
Hello -
I'm trying to set up a button for a duration limited action. Specifically, when I press the button what I want to happen is that an output fires for some amount of time (say a second) and then shuts off again.
What I'm using to implement this currently is as follows:
Note: input.X and output.X are hardware pins, input and output only respectively.
loadrt flipflop
loadrt timedelay
net redbutton input.0 timedelay.0.in flipflop.0.set
setp timedelay.0.on-delay 0
setp timedelay.0.off-delay 1
net redbuttonrst timedelay.0.out flipflop.0.reset
net redbuttonoutput flipflop.0.out output.0
addf timedelay.0 servo-thread
addf flipflop.0 servo-thread
What I see happen is that the button input is caught, the time delay is set, it fires off the reset line 1 second later... and then the flipflop does nothing.
From looking at the flipflop man page, I see it has a "clk" or clock parameter. That's literally all I see, as the man page is quite sparse I suspect whomever wrote it uses flipflops a great deal and assumed that anyone reading it would understand what the clock was for and when and how to use it.
I've searched for examples of using the flipflop component... some of them (very old style examples) also set the tmax parameter, and I found two that show the clk parameter being connected to an input. However, I haven't found a canonical discussion of when and how to use clk or whether it's needed (some flipflop examples don't use it).
So... what is the appropriate way to use this component? It's looking like I need to supply clk with an input to make the component evaluate itself (in addition to tying it to a thread) and I could tie it to "set" or "reset", but to get it to re-evaluate itself whenever something changes I'd have to use an or there as well. Is there a way to make it operate whenever an input changes?
Also, is there a better component to do this with? In C, I'd just write something like:
if (inputBit(0) == 1)
{
outputBit(0,1);
sleep(delay);
outputBit(0,0);
}
... so it seems like this should be a simple thing to do.
Erik
I'm trying to set up a button for a duration limited action. Specifically, when I press the button what I want to happen is that an output fires for some amount of time (say a second) and then shuts off again.
What I'm using to implement this currently is as follows:
Note: input.X and output.X are hardware pins, input and output only respectively.
loadrt flipflop
loadrt timedelay
net redbutton input.0 timedelay.0.in flipflop.0.set
setp timedelay.0.on-delay 0
setp timedelay.0.off-delay 1
net redbuttonrst timedelay.0.out flipflop.0.reset
net redbuttonoutput flipflop.0.out output.0
addf timedelay.0 servo-thread
addf flipflop.0 servo-thread
What I see happen is that the button input is caught, the time delay is set, it fires off the reset line 1 second later... and then the flipflop does nothing.
From looking at the flipflop man page, I see it has a "clk" or clock parameter. That's literally all I see, as the man page is quite sparse I suspect whomever wrote it uses flipflops a great deal and assumed that anyone reading it would understand what the clock was for and when and how to use it.
I've searched for examples of using the flipflop component... some of them (very old style examples) also set the tmax parameter, and I found two that show the clk parameter being connected to an input. However, I haven't found a canonical discussion of when and how to use clk or whether it's needed (some flipflop examples don't use it).
So... what is the appropriate way to use this component? It's looking like I need to supply clk with an input to make the component evaluate itself (in addition to tying it to a thread) and I could tie it to "set" or "reset", but to get it to re-evaluate itself whenever something changes I'd have to use an or there as well. Is there a way to make it operate whenever an input changes?
Also, is there a better component to do this with? In C, I'd just write something like:
if (inputBit(0) == 1)
{
outputBit(0,1);
sleep(delay);
outputBit(0,0);
}
... so it seems like this should be a simple thing to do.
Erik
Last edit: 22 Aug 2014 21:50 by green751. Reason: removed junk text at bottom
Please Log in or Create an account to join the conversation.
22 Aug 2014 22:04 - 22 Aug 2014 22:13 #50188
by cncbasher
Replied by cncbasher on topic Button with timed output - flipflop and time delay
loadrt oneshot count = 1
addf oneshot.1 servo-thread
#set one shot timer in sec
setp oneshot.1.width 6
setp oneshot.0.retriggerable 0
setp oneshot.0.rising 1
net <input> => oneshot.1.in
net temp1 <= oneshot.1.out
net temp1 => <output>
replace < input> & <output> with approprate pins
width 6 = 6 sec so this will actuate for 6 sec then switch back , this is your timer value
addf oneshot.1 servo-thread
#set one shot timer in sec
setp oneshot.1.width 6
setp oneshot.0.retriggerable 0
setp oneshot.0.rising 1
net <input> => oneshot.1.in
net temp1 <= oneshot.1.out
net temp1 => <output>
replace < input> & <output> with approprate pins
width 6 = 6 sec so this will actuate for 6 sec then switch back , this is your timer value
Last edit: 22 Aug 2014 22:13 by cncbasher.
Please Log in or Create an account to join the conversation.
23 Aug 2014 01:59 #50195
by green751
Replied by green751 on topic Button with timed output - flipflop and time delay
Okay, thanks. I'll give that a (one) shot.
In case I want to try using the flipflop for something else, do you know how it's supposed to work?
Erik
In case I want to try using the flipflop for something else, do you know how it's supposed to work?
Erik
Please Log in or Create an account to join the conversation.
23 Aug 2014 02:40 #50196
by cncbasher
Replied by cncbasher on topic Button with timed output - flipflop and time delay
yea sure , i found the best example here on JT'S examples page
gnipsel.com/linuxcnc/examples.html
gnipsel.com/linuxcnc/examples.html
The following user(s) said Thank You: green751
Please Log in or Create an account to join the conversation.
25 Aug 2014 21:08 #50269
by green751
Replied by green751 on topic Button with timed output - flipflop and time delay
Okay, that clears it up.
It does seem rather more complicated than I would have expected.
It's kind of like assembling a lego car then discovering one of the blocks is in fact play-doh, which will work for the job intended but requires different techniques for use.
Erik
It does seem rather more complicated than I would have expected.
It's kind of like assembling a lego car then discovering one of the blocks is in fact play-doh, which will work for the job intended but requires different techniques for use.
Erik
Please Log in or Create an account to join the conversation.
Time to create page: 0.060 seconds