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

相关推荐
西岸行者4 天前
学习笔记:SKILLS 能帮助更好的vibe coding
笔记·学习
ZPC82104 天前
docker 镜像备份
人工智能·算法·fpga开发·机器人
ZPC82104 天前
docker 使用GUI ROS2
人工智能·算法·fpga开发·机器人
starlaky4 天前
Django入门笔记
笔记·django
勇气要爆发4 天前
吴恩达《LangChain LLM 应用开发精读笔记》1-Introduction_介绍
笔记·langchain·吴恩达
悠哉悠哉愿意5 天前
【单片机学习笔记】串口、超声波、NE555的同时使用
笔记·单片机·学习
勇气要爆发5 天前
吴恩达《LangChain LLM 应用开发精读笔记》2-Models, Prompts and Parsers 模型、提示和解析器
android·笔记·langchain
qianshanxue115 天前
计算机操作的一些笔记标题
笔记
土拨鼠烧电路5 天前
笔记11:数据中台:不是数据仓库,是业务能力复用的引擎
数据仓库·笔记
土拨鼠烧电路5 天前
笔记14:集成与架构:连接孤岛,构建敏捷响应能力
笔记·架构