element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Dev Tools
  • Products
  • More
Dev Tools
Forum Latching Start Circuit using Flip Flops
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Dev Tools to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 16 replies
  • Subscribers 80 subscribers
  • Views 2364 views
  • Users 0 members are here
  • logic
  • digital
  • flip_flops
Related

Latching Start Circuit using Flip Flops

oldmanraskers
oldmanraskers over 10 years ago

I have been working on a CPLD project to run a state machine that will control a bunch of solenoids - I have mostly finished the hardware but now I'm moving onto the state machine. I can make the state machine conintually run, but what I really want is to implement a latching start/stop circuit that uses momentary pushbuttons... I want to be able to press start and have the state machine run (but I don't want to have to keep the start button pressed). I then want to press the stop button and make the state machine pause (again, i don't want to keep the stop button pressed). And finally, if I start the state machine but don't press the stop button, then I want the state machine to run to the last state and automatically stop. Thinking to years gone by, I kind of remember something about making a k-map for the start and stop inputs and building some s-r flip flop truth tables, but I can't remember and I also can't find exactly what I need on the web. I would be very grateful is someone could give me pointers on the method - I know I'm almost there image but it's years since I was taught this stuff and I simply can't remember image

Regards, MR.

  • Sign in to reply
  • Cancel

Top Replies

  • clem57
    clem57 over 10 years ago in reply to michaelkellett +1
    Did I miss something? Where is the logic for the state machine? Does it use a clock? Clem Edited: Ok see it now as attached.
  • michaelkellett
    michaelkellett over 10 years ago in reply to johnbeetem +1
    Hi John, I don't think we'll ever agree on this so I'm not trying to convert you When I design FSMs for FPGAs, I always do the state assignment (i.e., state encoding) by hand because I have no confidence…
  • clem57
    0 clem57 over 10 years ago in reply to michaelkellett

    Did I miss something? Where is the logic for the state machine? Does it use a clock?

    Clem

    Edited: Ok see it now as attached.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • johnbeetem
    0 johnbeetem over 10 years ago in reply to clem57

    Clem Martins wrote:

     

    Did I miss something? Where is the logic for the state machine? Does it use a clock?

    Clem

    Edited: Ok see it now as attached.

    I couldn't see the attachment when viewing the discussion in the "Inbox and Activity" page.  I had to open the discussion in a new tab (or window) to see the attachment.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • johnbeetem
    0 johnbeetem over 10 years ago in reply to oldmanraskers

    oldmanraskers wrote:

     

    4.) Explain why we don't need to reset the timer to zero.

    I didn't look at the code for MK's specific example, but here's a general principle:  When you design a finite state machine (FSM), it's always a good idea to have it "self-resetting", that is, if it initializes into an invalid state or somehow gets into an invalid state due to gremlins you want to be sure the state update logic quickly gets into a valid state so your design doesn't lock up and require manual reset.

     

    This may require you to do some extra analysis to make sure your invalid states don't lock up, and you may need to add some extra logic to get it to do the right thing.  When I design FSMs for FPGAs, I always do the state assignment (i.e., state encoding) by hand because I have no confidence that the synthesizer will do the right thing.  I also avoid "one hot" coding, because it's way too easy to end up with zero FFs set (not in any state) or with multiple FFs set (in several states at once).  "One hot" coding is great if you have to wire-wrap your state machine by hand using 7400-series logic.  When you have a nice synthesizer that does your logic minimization for you, dense coding works out quite nicely.

     

    Verilog lets you #define symbolic names for your states, which keeps the source code understandable.

     

    JMO/YMMV

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • michaelkellett
    0 michaelkellett over 10 years ago in reply to johnbeetem

    image

    Here's the simulation I did and the testbench that drove it. Simulation in Aldec ActiveHDL, The 1mS time was reduced to 100uS to reduce the simulation cycles.

    There is an attachment as well as the embedded picture !

     

    MK

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • michaelkellett
    0 michaelkellett over 10 years ago in reply to johnbeetem

    Hi John,

     

    I don't think we'll ever agree on this so I'm not trying to convert you image

     

    When I design FSMs for FPGAs, I always do the state assignment (i.e., state encoding) by hand because I have no confidence that the synthesizer will do the right thing.  I also avoid "one hot" coding, because it's way too easy to end up with zero FFs set (not in any state) or with multiple FFs set (in several states at once).  "One hot" coding is great if you have to wire-wrap your state machine by hand using 7400-series logic.  When you have a nice synthesizer that does your logic minimization for you, dense coding works out quite nicely.


    With the tools I use and the state machine template I prefer there is no visibility at the VHDL level of the flip flops. Synplify (for those who don't know that's the software I use to translate the VHDL into gates for an FPGA) generally uses one hot although you can force it not to. I don't because it's never failed me (in dozens of designs) yet.

    I always code to deal with the invalid states (although Synplify optimizes it out because with one-hot you can't get there) and I agree it's essential to initialize correctly.

     

    I don't have  a VHDL lint equivalent (they exist but not cheap) but I think the thing I would like most is warning about un-initialized things.

     

    MK

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • johnbeetem
    0 johnbeetem over 10 years ago in reply to michaelkellett

    Michael Kellett wrote:

     

    I don't think we'll ever agree on this so I'm not trying to convert you

    My one experience with one-hot coding was when I was first designing with FPGAs.  The particular design used a clock edge to set a flip-flop, and that clock came from a fiber optic receiver.  It simulated beautifully, except that I was aghast that simulation technology hadn't improved in the decades since I had last used someone else's simulator.

     

    When I got the board back, the FPGA worked perfectly -- at first.  Then I tried pulling and inserting the fiber optic cable a few times and found that sometimes the circuit went dead.  It turned out that sometimes when I pulled the cable I'd get a short clock pulse -- long enough to clear the hot flip-flop but too short to set the next flip-flop, so I'd end up in an invalid state that I couldn't recover from without reset.

     

    Yes, it was a clock pulse-width violation, but the simulator couldn't catch it -- a simulator only simulates the test cases you've thought of, and not the many ones you didn't think of.

     

    So I switched to a self-resetting dense coding, which also saved a bunch of LUTs.  I also decided that using other people's simulators was pretty much a waste of time and I rarely use simulation.   I don't expect anyone to agree with me on this eccentricity.  They're welcome to write test benches for my Verilog and try to find bugs I've missed.

     

    JM(eccentric)O / YM(will most likely)V

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
<
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube