题解1 | #根据状态转移表实现时序电路#

根据状态转移表实现时序电路

https://www.nowcoder.com/practice/455c911bee0741bf8544a75d958425f7

不知道这么写跟写两个always块,然后把组合逻辑塞进去写时序电路的区别在哪里><

`timescale 1ns/1ns

module seq_circuit(
      input                A   ,
      input                clk ,
      input                rst_n,
 
      output   wire        Y   
);

wire q1;
wire q0;
wire d1;
wire d0;

assign d1 = A ^ q1 ^ q0;
assign d0 = ~q0;
assign Y  = q1 & q0;

d_ff c1(d1,clk,rst_n,q1);
d_ff c2(d0,clk,rst_n,q0);


endmodule

module d_ff(
    input d,
    input clk,
    input rst_n,
    output reg q
);

always @(posedge clk or negedge rst_n)
begin
if (!rst_n)
q <= 0;
else
q <= d;
end

endmodule

`timescale 1ns/1ns

module seq_circuit(
      input                A   ,
      input                clk ,
      input                rst_n,
 
      output   wire        Y   
);

reg q1;
reg q0;


always @(posedge clk or negedge rst_n)
begin
if (!rst_n)
q1 <= 0;
else
q1 <= A ^ q1 ^ q0;;
end

always @(posedge clk or negedge rst_n)
begin
if (!rst_n)
q0 <= 0;
else
q0 <= ~q0;
end

assign Y  = q1 & q0;

endmodule
全部评论

相关推荐

这一集&nbsp;硕士输的很惨
找工作ing10:就是这样不是硕士不愿意脱下长衫,是人家觉得屈才了
点赞 评论 收藏
分享
墨西哥大灰狼:如果你的校友卤馆还在的话,他肯定会给你建议的,可是卤馆注销了@ 程序员卤馆
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务