You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a need for a simple start stop button; but unlike the NIST and Toggle2NIST - it should simply stay on/off. And this seems a bit messy to do with a flipflop or the estop_latch.
Below is strawman that I am happy to clean up and submit. But am hoping for a suggestion as to how to do this easily with the existing components.
component startstop """pair of start-stop pushbuttons that control a single output
.B loadrt startstop
""";
description """This component mimics a typical 2 pushbuttons start/stop contacto; with one button r on and one button for off. E.g. to control a motor.
___ _ _
start(in): ___| |____| |_____________________| |____
__ ___
stop(in): ________________| |_______________| |___
____________
on(out): ___| |__________________________
___ __________________________
off(out): |____________|
Press the start button - and the motor starts; pressing it again does not change that.
And pressing the stop button stops it. If both are pressed - the stop button wins.
""";
pin in bit start """start signal; on a rising edge the out bit on is pulled high""";
pin in bit stop """stop signal; on a rising edge the out bit on is pulled low""";
pin out bit on """on signal; high when start was pressed""";
pin out bit off """off signal; low when start was presse, the inverse of the on output""";
variable int state;
function _;
author "Dirk-Willem van Gulik <dirkx(at)webweaving(punto)org>";
license "ASLv2"; // indicates Apache Software License v2 or later
;;
FUNCTION(_) {
// Stop button wins - so it is first.
if (stop && ( on || off == 0)) {
on = 0; off = 1;
state = 0;
} else if (start && state == 0) {
on = 1; off = 0;
state = 1;
};
}
Isn't this normally called a "set-reset latch" or "set-reset flipflop"?
There is a problem at startup where the off output is not the inverted on output. That may be a real problem. You need to set initial values of the output.
Wouldn't this do the same or am I missing something?
So my current workaround/way of doing it in 2.9 is indeed a flip-flop with an edge/xor to make sure that a rising edge on start is the only things that turns it on; not the loss of a reset when the start is still on.
If you want the rising edge of start to be effective and not the level, then you should use:
start button connected to as clk input
set data to a fixed true
stop button to reset input
Then you can only "start" on the rising edge of start button (data gets copied to out/out-not on rising edge). The stop has precedence and is level active on the reset input and will always clear out and set out-not as long as it is active.
Activity
BsAtHome commentedon Oct 30, 2026
Isn't this normally called a "set-reset latch" or "set-reset flipflop"?
There is a problem at startup where the
offoutput is not the invertedonoutput. That may be a real problem. You need to set initial values of the output.Wouldn't this do the same or am I missing something?
hansu commentedon Oct 30, 2026
I think
flipflopis doing exactly what you have shown in your timing diagram when you connect only the set and reset pins.BsAtHome commentedon Oct 30, 2026
Indeed it does. However, it too fails to initialize the out-not output correctly. Flip-flops always have opposite outputs. That should be fixed.
just like the superfluous use of the extra data struct and the proper type of local variable; ah well, so much cleaning to do ;-)
hansu commentedon Oct 30, 2026
Then we should fix that one.
But
outis an IO, so I think you can set the initial output value it that is important.#4750 😉
dirkx commentedon Oct 30, 2026
So my current workaround/way of doing it in 2.9 is indeed a flip-flop with an edge/xor to make sure that a rising edge on start is the only things that turns it on; not the loss of a reset when the start is still on.
BsAtHome commentedon Oct 30, 2026
If you want the rising edge of start to be effective and not the level, then you should use:
clkinputdatato a fixed trueresetinputThen you can only "start" on the rising edge of start button (
datagets copied toout/out-noton rising edge). The stop has precedence and is level active on theresetinput and will always clearoutand setout-notas long as it is active.