TA的每日心情 | 开心 2016-9-21 20:33 |
---|
签到天数: 29 天 连续签到: 1 天 [LV.4]偶尔看看III
|
从零开始学FPGA我的第6个实验理解状态机记录一下
状态机:有一段式。二段式。三段式(效率高,时序收敛信好)现在还不知道怎么让他们之间进行转换。
下面是一个检查一个数据流(eeboard )的状态机
代码:- module hello(Clk,Rst_n,data,led);
- input Clk;//50M
- input Rst_n;//低电平复位
-
- input [7:0]data;
-
- output reg led;
-
- localparam
- CHECK_e1 = 7'b000_0001,
- CHECK_e2 = 7'b000_0010,
- CHECK_b = 7'b000_0100,
- CHECK_o = 7'b000_1000,
- CHECK_a = 7'b001_0000,
- CHECK_r = 7'b010_0000,
- CHECK_d = 7'b100_0000;
-
- reg[6:0]state;
-
- always@(posedge Clk or negedge Rst_n)
- if(!Rst_n)begin
- led <= 1'b1;
- state <= CHECK_e1;
- end
- else begin
- case(state)
- CHECK_e1:
- if(data == "e")
- state <= CHECK_e2;
- else
- state <= CHECK_e1;
-
- CHECK_e2:
- if(data == "e")
- state <= CHECK_b;
- else
- state <= CHECK_e1;
-
- CHECK_b:
- if(data == "b")
- state <= CHECK_o;
- else
- state <= CHECK_e1;
-
- CHECK_o:
- if(data == "o")
- state <= CHECK_a;
- else
- state <= CHECK_e1;
-
- CHECK_a:
- if(data == "a")
- state <= CHECK_r;
- else
- state <= CHECK_e1;
-
- CHECK_r:
- if(data == "r")
- state <= CHECK_d;
- else
- state <= CHECK_e1;
-
- CHECK_d:
- begin
- state <= CHECK_e1;
- if(data == "d")
- led <= ~led;
- else
- led <= led;
- end
-
- default:state <= CHECK_e1;
- endcase
- end
- endmodule
复制代码 测试代码testbeavh- `timescale 1ns/1ns
- `define clock_period 20
- module hello_tb;
-
- reg Clk;
- reg Rst_n;
- reg [7:0]ASCII;
-
- wire led;
-
- hello hello0(
- .Clk(Clk),
- .Rst_n(Rst_n),
- .data(ASCII),
- .led(led)
- );
-
- initial Clk = 1;
- always#(`clock_period/2)Clk = ~Clk;
-
- initial begin
- Rst_n = 0;
- ASCII = 0;
- #(`clock_period*200);
- Rst_n = 1;
- #(`clock_period*200 + 1);
- forever begin
- #(`clock_period);
- ASCII = "e";
- #(`clock_period);
- ASCII = "e";
- #(`clock_period);
- ASCII = "b";
-
- #(`clock_period);
- ASCII = "o";
- #(`clock_period);
- ASCII = "a";
- #(`clock_period);
- ASCII = "r";
- #(`clock_period);
- ASCII = "d";
- #(`clock_period);
-
- end
- end
- endmodule
复制代码 RTL测试:
待续。。。。。。
|
|