4673 views|2 replies

6871

Posts

0

Resources
The OP

State Machine Programming Experience [Copy link]

In medium and large-scale designs , state machines are used more and more frequently. How we can write a state machine that is easy for people to understand is the most important thing at present. Let's review the classification of state machines. State machines are divided into two categories: Moore state machines and Mealy state machines. The main difference between these two types of state machines is that the output value of Moore depends only on the current state, while the Mealy state machine is not only related to the current state, but also to the input value. How to distinguish whether it is a Moore or Mealy type state machine mainly depends on the conditional transfer variable in the always statement of state transfer in the program . For example: input a,clk; input a,clk; output dout; output dout; reg dout; reg dout; parameter st0=1,st1=1,st2=2,st3=3; (Encoding method, to be discussed below) parameter st0=1,st1=1,st2=2,st3=3; (Encoding method, to be discussed below) reg [1:0] state; reg [1:0] state; always@(negedge clk) always@(negedge clk) case(state)------------(There is only state in case, but no input a, so it is a Moore state machine) case(state or a)------------(Case has both state and input a, so it is a Mealy state machine) ... ... ... ... endcase endcase endmodule endmodule Next, I will introduce what kind of encoding method we use when writing a state machine. The encoding methods of state machines mainly include binary encoding, Gray encoding and one-hot encoding. Next, I will introduce these three encodings respectively. Generally, binary coding is done in binary, such as 000, 001, 010, 111, and so on. In fact, it is encoded in the order of binary. As a simple coding, this coding method can be used, but one thing to remember is that when using this coding method, you must do a good job of burr processing, because when the state changes, the code also changes at the same time, so burrs will be generated. The main reason for the burr is that when the binary code changes, at least two bits will change at the same time, and the delay is not equal. Therefore, the binary code cannot remove the burr very well, and transient processes will occur at the same time, causing logical errors, thus causing the program to run away. Gray coding is actually a changing binary coding. The main problem it solves is to remove burrs and reduce transient processes. Improve stability. For example: a three-bit binary code (000, 001, 010, 011, 100, 101, 110, 111) becomes a Gray code (000, 001, 011, 010, 110, 111, 101, 100). When converting binary code to Gray code, remember that only one bit can change, and the other bits remain unchanged. At the same time, make sure that the higher the number of bits, the slower the change. For example, (000, 001, 101, 111, 011, 010, 110, 100) in this code, the highest bit changes at twice the rate of the original bit .











This is a bad coding method. Finally, I will talk about one-hot coding. Compared with Gray code, this coding method adds triggers, but saves combinational circuits. It improves the speed and reliability of the circuit. For example, 5-bit hot coding (5'b00001, 5'b00010, 5'b00100, 5'b01000, 5'b10000;). Like Gray code, it changes one bit at a time. The only difference is that one-hot coding does not require logical operations.
Finally, I will talk about how to write the entire state machine so that people can understand it quickly. First of all, we need to know how many parts our state machine consists of. The parts I refer to here are timing and combinational logic. Generally, state machines are composed of two parts: timing and combinational logic (only one part is not discussed here). So how should we write it so that people can understand it easily? Take the timing part of the state machine as the first part, and the combinational logic of the state machine as the second part. So what should we do in the first part? In the first part, we mainly use timing to control the synchronous description of the state machine and the initialization of the state machine. The second part can be divided into two small steps. The first step is to transfer the state of the state machine, and the second step is to describe the output of the state machine. In fact, the second part can also be divided into two small steps, but I think the program is clearer after separating them. In the second part, we can choose whether to use Moore type or Mealy type state machine.
This post is from FPGA/CPLD

Latest reply

cpc
Still very good  Details Published on 2011-11-12 09:37
Personal signature一个为理想不懈前进的人,一个永不言败人!
http://shop57496282.taobao.com/
欢迎光临网上店铺!

130

Posts

0

Resources
2
:Laugh: That makes sense
This post is from FPGA/CPLD

10

Posts

0

Resources
3
Still very good
This post is from FPGA/CPLD

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

    EEWorld
    subscription
    account

    EEWorld
    service
    account

    Automotive
    development
    circle

    Robot
    development
    community

    Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
    快速回复 返回顶部 Return list