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

相关推荐
wdfk_prog5 分钟前
[Linux]学习笔记系列 -- 内存管理与访问
linux·笔记·学习
go_bai5 分钟前
Linux-网络基础
linux·开发语言·网络·笔记·学习方法·笔记总结
崎岖Qiu5 分钟前
【OS笔记38】:设备管理 - I/O 设备原理
笔记·操作系统·os·设备管理·io设备
YprgDay1 小时前
Vivado单独综合某一模块查看资源消耗
fpga开发·vivado
代码游侠1 小时前
学习笔记——HC-SR04 超声波测距传感器
开发语言·笔记·嵌入式硬件·学习
Joshua-a1 小时前
高云FPGA在线调试/逻辑分析仪简要使用流程
嵌入式硬件·fpga开发·高云
Abbylolo2 小时前
《Obsidian Excalidraw插件配置与使用指南》
笔记
@zulnger2 小时前
python 学习笔记(闭包)
笔记·python·学习
AomanHao2 小时前
【阅读笔记】Bayer阵列坏点校正-《Adaptive pixel defect correction》
图像处理·笔记·isp·坏点补偿
yewq-cn2 小时前
Joplin 客户端与服务端
笔记