Skip to content

start-stop button component #4747

Open
Open

Description

@dirkx

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;
        };
}

Activity

  1. BsAtHome commented on Oct 30, 2026

    @BsAtHome
    Contributor

    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?

    ...
    pin in  bool start "...";
    pin in  bool stop "...";
    pin out bool on = 0 "...";
    pin out bool off = 1 "...";
    ...
    ;;
    if(stop) {
        set_on(1);
        set_off(0);
    } else if(start) {
        set_on(0);
        set_off(1);
    }
  2. hansu commented on Oct 30, 2026

    @hansu
    Member

    I think flipflop is doing exactly what you have shown in your timing diagram when you connect only the set and reset pins.

  3. BsAtHome commented on Oct 30, 2026

    @BsAtHome
    Contributor

    I think flipflop is doing exactly what you have shown in your timing diagram when you connect only the set and reset pins.

    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 ;-)

  4. hansu commented on Oct 30, 2026

    @hansu
    Member

    Then we should fix that one.
    But out is an IO, so I think you can set the initial output value it that is important.

    #4750 😉

  5. dirkx commented on Oct 30, 2026

    @dirkx
    ContributorAuthor

    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.

  6. BsAtHome commented on Oct 30, 2026

    @BsAtHome
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions