Circuits--Sequential--FSM--q5b~q3a

  1. q5b

    module top_module (
    input clk,
    input areset,
    input x,
    output z
    );

    复制代码
     parameter A = 1'b0;
     parameter B = 1'b1;
     
     reg[1:0] state;
     reg[1:0] next_state;
    
     
     always@(*)
         begin
             case(state)
                 A:
                     if(x) next_state = B;
                 	else  next_state = A;
                 B:
                     next_state = B;
             endcase
         end
     
     always@(posedge clk or posedge areset)
         begin
             if(areset)
                 state = A;
             else
                 state = next_state;
         end
     
     always@(*)
         begin
             if(state == A)
                 begin
                     if(x)  z = 1'b1;
                     else   z = 1'b0;
                 end
                 
             else
                 begin
                   	if(x) z = 1'b0;
                   	else z = 1'b1;
               	end
         end

    endmodule

  2. q3a

    module top_module(
    input clk,
    input reset,
    input s,
    input w,
    output z
    );

    复制代码
     parameter A = 1'd0;
     parameter B = 1'd1;
     reg[1:0] state;
     reg[1:0] next_state;
     reg[1:0] count;
     reg[1:0] num;
    
     always @(*) begin
         case(state)
             A:
                 begin
                     if(s) next_state = B;
                     else  next_state = A;
                 end
             B:
                 begin
                     next_state = B;
                 end
            
         endcase
     end
    
     always @(posedge clk) begin
         if(reset)
             state <= A;
         else
             state <= next_state;
     end
    
     always @(posedge clk) begin
         if(reset)
             count <= 2'd0;
         else if(count == 2'd2)
             count <= 2'd0;
         else if(state == B)
             count <= count + 1'b1;
     end
    
     always @(posedge clk) begin
         if(reset)
             num <= 1'b0;
         else
             begin
                 if(count == 2'd0)
                     begin
                         if(w) num <= 1'b1;
                         else num <= 1'b0;
                     end 
                 else if(state == B)
                     begin 
                         if(w) num <= num + 1'b1;
                         else  num <= num;
                     end
    
             end
     end
     assign z = (state == B && num == 2'd2 && count == 2'd0);

    endmodule

相关推荐
遇印记2 小时前
大二java学习笔记:二维数组
java·笔记·学习
bnsarocket3 小时前
Verilog和FPGA的自学笔记6——计数器(D触发器同步+异步方案)
笔记·fpga开发·verilog·自学·硬件编程
博览鸿蒙3 小时前
FPGA职位经典笔/面试题(附答案与解析)
fpga开发
LK_074 小时前
【Open3D】Ch.3:顶点法向量估计 | Python
开发语言·笔记·python
li星野5 小时前
打工人日报#20251011
笔记·程序人生·fpga开发·学习方法
摇滚侠5 小时前
Spring Boot 3零基础教程,yml配置文件,笔记13
spring boot·redis·笔记
QT 小鲜肉5 小时前
【个人成长笔记】在Ubuntu中的Linux系统安装 anaconda 及其相关终端命令行
linux·笔记·深度学习·学习·ubuntu·学习方法
尤老师FPGA5 小时前
LVDS系列31:Xilinx 7系 ADC LVDS接口参考设计(二)
fpga开发
QT 小鲜肉5 小时前
【个人成长笔记】在Ubuntu中的Linux系统安装实验室WIFI驱动安装(Driver for Linux RTL8188GU)
linux·笔记·学习·ubuntu·学习方法
急急黄豆5 小时前
MADDPG学习笔记
笔记·学习