Introduction to FPGA Part 5 - Finite State Machines | Digi-Key Electronics

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ธ.ค. 2021
  • A field-programmable gate array (FPGA) is an integrated circuit (IC) that lets you implement custom digital circuits. You can use an FPGA to create optimized digital logic for things like digital signal processing (DSP), machine learning, and cryptocurrency mining. Because of the FPGA’s flexibility, you can often implement entire processors using its digital logic. You can find FPGAs in consumer electronics, satellites, and in servers used to perform specialized calculations.
    In this series, we will see how an FPGA works and demonstrate how to create custom digital logic using the Verilog hardware description language (HDL).
    Previously, we demonstrated procedural assignments and how to feed a clock signal to such statements ( • Introduction to FPGA P... ). In this episode, we show how to create finite state machines (FSMs) in Verilog.
    The solution to the challenge at the end of the episode can be found here: www.digikey.com/en/maker/proj...
    All code examples and solutions for this series can be found here: github.com/ShawnHymel/introdu...
    A finite state machine (FSM or sometimes just “state machine”) is a mathematical model used to express how something (e.g. an abstract “machine”) can move sequentially through a series of states to tackle various problems. FSMs are used often in software, and we can create FSMs in hardware logic circuits.
    While many problems can be tackled without the use of an FSM, they provide a wonderful way to organize code (whether that’s hardware or software).
    A machine (or process) takes on certain properties when in a particular state, which often includes changing some kind of output. Such output might be toggling a bit, incrementing a counter, or opening a network connection. The machine moves to another state when certain criteria are met (known as the “inputs”). For example, a button might be pressed, a timer might expire, or a client might close the network connection, which will cause the state machine to move to a different state.
    State machines are often depicted in diagram form as a series of connected circles or rectangles. The arrows show how the machine moves between states and list the input criteria required for the transition.
    A Moore state machine has its outputs associated with each state. As a result, a Moore FSM must change states in order to change its outputs.
    A Mealy state machine, on the other hand, associates its outputs with states and inputs. This means the outputs in a Mealy state machine may change on the transition. While a Mealy state machine may be harder to understand at times, they often have fewer states than the equivalent Moore FSM (thus saving you precious logic cells or code space).
    Your challenge is to create a state machine that debounces a button to fix the counter from the previous episode. Instead of skipping counts on some button presses, the counter should increment by 1 (and only 1) each time you press the INCREMENT button. You are welcome to use a Mealy or a Moore machine.
    Product Links:
    www.digikey.com/en/products/d...
    Related Videos:
    • Cyclone® III FPGA
    • Power Management: Powe...
    • FPGA's: Low-Cost, High...
    Related Project Links:
    www.digikey.com/en/maker/proj...
    Related Articles:
    www.digikey.com/en/pdf/r/rene...
    www.digikey.com/en/videos/d/d...
    forum.digikey.com/t/debounce-...
    Learn more:
    Maker.io - www.digikey.com/en/maker
    Digi-Key’s Blog - TheCircuit www.digikey.com/en/blog
    Connect with Digi-Key on Facebook / digikey.electronics
    And follow us on Twitter / digikey
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 44

  • @AhmadAsmndr
    @AhmadAsmndr 2 ปีที่แล้ว +2

    I just entered the 2022 watching your video and I want to wish you a happy new year. One of my main goals for the new year is to learn FPGA, and I am going to achieve it with your help. From all my heart, thank you.

  • @ibrahimalikadawa5011
    @ibrahimalikadawa5011 2 ปีที่แล้ว +5

    Very good job, Shawn. You have done it so much that we have to say thanks! The series is found very helpful. Keep it up please.

    • @ShawnHymel
      @ShawnHymel 2 ปีที่แล้ว +1

      Thank you! I'm really glad you are enjoying the series!

  • @TinLethax
    @TinLethax 2 ปีที่แล้ว +1

    Great video Shawn !

  • @vaniaeli4392
    @vaniaeli4392 4 หลายเดือนก่อน

    Muito Obrigado por democratizar esse conhecimento ❤

  • @0LoneTech
    @0LoneTech 2 ปีที่แล้ว +6

    When using non-blocking assignment, you do know that whatever value you read within that always block is the old value (or rather, current; the assigned value appears in the future). If using blocking assignment it will read sequentially within that block, much like in common (sequential imperative) programming languages, but it's easier to lose track of what the actual logic is then (longer sequential code can create complex deep logic).

    • @ShawnHymel
      @ShawnHymel 2 ปีที่แล้ว +2

      Thanks for the heads up! I did my best to give examples of blocking vs. non-blocking assignments at 13:16.

  • @rjordans
    @rjordans 2 ปีที่แล้ว +1

    Another thing to note for the mealy machine is that the outputs can sometimes show glitches when the output is triggered upon entering the state even though the input value changes and the next state doesn't go along the edge that had the outfit value specified that you saw

  • @alexandrsavochkin9442
    @alexandrsavochkin9442 ปีที่แล้ว

    Thanks, Shawn, for the great job, your tutorials helped me to start with FPGAs.
    I am wondering if the behavior described is well defined:
    There are 2 always blocks triggered by positive clk edge, so I assume they are executed simultaneously. One block increments clk_count and another block compares it with MAX_CLK_COUNT. Can we do it simultaneously and is it well defined behavior? Are there any chances that comparison will happen before increment in one clc cycle and after increment in the next cycle so we will miss the MAX_CLK_COUNT condition?

  • @seankayll9017
    @seankayll9017 2 ปีที่แล้ว +3

    This is a great series, thanks for making these. Just a quick question if I may, at 16:38 could one also write "always @ ( state ) begin" to make it more obvious which signal was the trigger?
    ed. Yes I know a good teacher would say "try it and see" but I haven't had the chance to set up my shiny new IceStick yet!

    • @ShawnHymel
      @ShawnHymel 2 ปีที่แล้ว +2

      Yes, the ( * ) sensitivity list should tell the synthesis tool to run that always block when (state) changes.

  • @matthewprater7892
    @matthewprater7892 2 ปีที่แล้ว

    Great video! When I run verify, i get an error with the done_sig both times they are used in the code (fsm-moore.v:115: error: done_sig is not a valid l-value in fsm_moore.) for both moore and mealy approaches but the error goes away for the build and it uploads fine. Also, unlike file names, verilog does not like dashes (-) in module names

  • @katemoon7476
    @katemoon7476 2 ปีที่แล้ว

    This probably isn't the right place to ask, but does anyone know of any expos, conferences or trade shows for embedded systems in the US for 2022? Anything regarding the PI, Beaglebone, embedded systems, PCB's, hardware or similar.

  • @byronwatkins2565
    @byronwatkins2565 2 ปีที่แล้ว +3

    At 22:20, one bit can have only two values, so you don't need a default either.

    • @ShawnHymel
      @ShawnHymel 2 ปีที่แล้ว +1

      Good catch, thanks! I have a habit of always putting default cases, even if the state can't ever physically get there :)

    • @byronwatkins2565
      @byronwatkins2565 2 ปีที่แล้ว +2

      @@ShawnHymel That is a good habit and the compiler probably would generate no extra code.

    • @MR-fs2pc
      @MR-fs2pc 2 ปีที่แล้ว

      Out of interest, would default catch the X initial value of state? It seems to in simulation, but I am not sure if it would in reality.

    • @byronwatkins2565
      @byronwatkins2565 2 ปีที่แล้ว +1

      @@MR-fs2pc Real bits are 1, 0, or in transition. The simulation you mention is not synthesizable.

  • @RebelCoderX
    @RebelCoderX 4 หลายเดือนก่อน

    Challenge SPOILER: I made the debouncer using only 2 states, but I'm using the delay counter itself as a kind of sub state.. Only when it reached the maximum value, I test for the button input value, when that is high while the current state is "released" then I reset the delay counter, increase the ledCounter output and change the state to "pressed". Then when pressed is the current state, I test if the button input is 0 when the counter has reached the maximum value. In both states, when the counter has not reached the maximum value, I just increase the delayCounter value by one.

  • @JeffreyBaker-es3ej
    @JeffreyBaker-es3ej ปีที่แล้ว

    Hi y'all! I can't get apio to recognize the device "ftdi_usb_get_strings failed: -4 (libusb_open() failed)". I've followed the instructions to the letter, tried changing to the libusbK drivers to no avail. The default FTDIBUS drivers also failed. Also, the device added to the device manager isn't as shown, it pops up as Dual RS232-HS (Interface 0) and Dual RS232-HS (Interface 1). Changing one or the other, or both to libusbK fails any which way. HELP or I'll just forget this toolchain and tutorial. ):

  • @razvanvlad607
    @razvanvlad607 ปีที่แล้ว

    Can anybody help me? I'm a beginner and I'm looking for a FPGA board to start with. I don't know which board is the most suitable for me. Nexys A7 is way too expensive. My options for the time being are: Basys 3 artix-7, Arty A7/S7 or Cmod A7/S7 (breadboardable). I need a good price quality ratio. And also I don't know if the breadboardable boards are enough powerful and capable. Are they worth it? Or the extra money for the other boards like Basys and Arty is worth it more? Thank you very much!

  • @fredkilner2299
    @fredkilner2299 2 ปีที่แล้ว

    Hey was anybody at the first West Coast Computer Faire at the SF Civic Auditorium in 1977? Did anybody see me? I was starving and I saw a hotdog for 45 or so cents. Crazy!!! Next time I was there I saw U2 in high school. A few years later I was at a West Coat Computer Faire at the Moscone Center. There was a guy who had red hair who came in to Computer Land of Los Altos in a wheel chair and I saw him up there at the Computer Faire. Apple ][ was my favorite! Woz's integer basic was fast enough for vid games. I wrote a lo-res graphics missile command game which was fine but Microcraps Floating Basic was so slow it sucks slowly. At Computer Land they put the Apple ][ where the Compu Color used to sit. Yesterday I wore my ASR-35 teletype shirt at Cosco and the guy who always asked us if we were a super member or something thought he had been tortured by those. As a super youngling one of my friends brought me to some room full of those and he showed he had turned off the echo or something to save it printing. He told me I got him into computers and I can't remember why but I always loved computers but my generation had the most brain dead adults because it was always going against the grain. As a kid it was good there were so many Chinese, Vietnamese and others who were normal, because there were so many I dunno what they were lazy people who wouldn't do their math or anything work.

  • @b213videoz
    @b213videoz 3 หลายเดือนก่อน

    9:13 Hey man, Python doesn't have SWITCH/CASE statement though 😁🤣

  • @embeddedbastler6406
    @embeddedbastler6406 2 ปีที่แล้ว +1

    Hmm, one should really not use an output of a flip flop as a clock for another flip flop, as this can cause some nasty timing errors. You should use a clock enable signal instead.

    • @ShawnHymel
      @ShawnHymel 2 ปีที่แล้ว +1

      Now that I'm looking into metastability and cross-clock domains, I can see why this might be an issue. However, all of the resources I come across for creating a "clock divider" use the output of one flip-flop to clock other flip-flops. Do you have any suggestions or resources that show how to create better clock dividers?

    • @embeddedbastler6406
      @embeddedbastler6406 2 ปีที่แล้ว +2

      @@ShawnHymel I think nandland explains it well in this video @ 9:30 th-cam.com/video/htwlb-DuEK8/w-d-xo.html

    • @ShawnHymel
      @ShawnHymel 2 ปีที่แล้ว +1

      @@embeddedbastler6406 Thanks! It seems that using the output of a FF as a clock signal is a naive approach that's used in a lot of books, content, etc. While it makes sense for beginners, I can see why it could cause issues. I plan to mention this in a future episode (along with why it's bad) and offer a better clock divider example.

  • @surflaweb
    @surflaweb 2 ปีที่แล้ว +1

    This is NASA code.

    • @rjordans
      @rjordans 2 ปีที่แล้ว +3

      NASA would probably use VHDL though

  • @Jkauppa
    @Jkauppa 2 ปีที่แล้ว

    prioritized tasks, as you dont need to do work that is not needed, better have food than have nothing served

    • @Jkauppa
      @Jkauppa 2 ปีที่แล้ว

      language makes things very hard

    • @Jkauppa
      @Jkauppa 2 ปีที่แล้ว

      its not very efficient in delivering the intent of your design, its tech talk

    • @Jkauppa
      @Jkauppa 2 ปีที่แล้ว

      it should be "do this" instead of "you need to do this and this and this and this"

    • @Jkauppa
      @Jkauppa 2 ปีที่แล้ว

      your unnecessary complication hides the thing its doing, you cant see the forest from the trees (statements), and documentation is a chore, not a blessing, make it simpler to both convey the meaning, intent and the implementation in same package, visually

    • @Jkauppa
      @Jkauppa 2 ปีที่แล้ว

      for "gods sake" have it at least object oriented, not this statement litany

  • @mofear4874
    @mofear4874 11 หลายเดือนก่อน

    all wrong