FPGA入门练习
+ -

一段状态机示例

2025-03-02 27 0
  1. `timescale 1ns / 1ps
  2. module mystate(input clk,input rst,output [2:0] out);
  3. reg[2:0] state;
  4. always@(posedge clk)
  5. begin
  6. if(!rst)
  7. state <= 2'b00;
  8. else if(state == 2'b00)
  9. state <= 2'b01;
  10. else if(state == 2'b01)
  11. state <= 2'b10;
  12. else if(state == 2'b10)
  13. state <= 2'b11;
  14. else
  15. state <= 2'b00;
  16. end
  17. assign out = state;
  18. endmodule

测试示例:

  1. `timescale 1ns / 1ps
  2. module Hellotmystate();
  3. wire[2:0] myout;
  4. reg rst;
  5. reg clk;
  6. mystate myinstance(
  7. .clk(clk),
  8. .rst(rst),
  9. .out(myout)
  10. );
  11. initial begin
  12. rst = 0;
  13. clk = 0;
  14. #10
  15. rst = 1;
  16. end
  17. always #5 clk =~clk;
  18. endmodule

仿真结果:
16181524716

输出为reg类型:

  1. module mystate(input clk,input rst,output reg[10:0] count );
  2. always@(posedge clk)
  3. begin
  4. if(!rst)
  5. count<=10'b0;
  6. else
  7. count<= count+3;
  8. end
  9. endmodule

0 篇笔记 写笔记

关注公众号
取消
感谢您的支持,我会继续努力的!
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

您的支持,是我们前进的动力!