Sim/circuit1
This is a combinational circuit. Read the simulation waveforms to determine what the circuit does, then implement it.
观察可以发现,这就是一个与门。
代码如下:
module top_module ( input a, input b, output q );// assign q = a & b; // Fix me endmoduleSim/circuit2
This is a combinational circuit. Read the simulation waveforms to determine what the circuit does, then implement it.
看这个waveform,看q,第一个高电平:a,b,c,d全是1;第二个高电平:a,b低电平,c,d高电平;第三个高电平:a,c -->0,b,d--->1;a,d--->0,b,c--->1;a,d-->1,好的,咱们已经发现规律了,原来这是一个同或电路,也就是0个或者2个或者4个为1的时候,输出q为1,代码如下:
module top_module ( input a, input b, input c, input d, output q );// assign q = ~a^b^c^d; // Fix me endmoduleSim/circuit3
由于上一题的经验,我想直接猜抑或,但是不然,于是观察waveform,发现 bc & bd ad ac的时候q==1,那么代码如下:
module top_module ( input a, input b, input c, input d, output q );// assign q = a&d | a&c |b&c |b&d; // Fix me endmoduleSim/circuit4
一看就是b+c,代码如下:
module top_module ( input a, input b, input c, input d, output q );// assign q = b|c; // Fix me endmoduleSim/circuit5
c是选择信号sel,sel=0,c=0选择b这样子,代码如下:
module top_module ( input [3:0] a, input [3:0] b, input [3:0] c, input [3:0] d, input [3:0] e, output [3:0] q ); always @(*) begin case (c) 4'h0: q = b; 4'h1: q = e; 4'h2: q = a; 4'h3: q = d; default: q = 4'hf; // Covers c = 4 through F endcase end endmoduleSim/circuit6
我们直接看这个电路,也是感觉和上一道题一样,a来选择q,代码如下:
module top_module ( input [2:0] a, output [15:0] q ); always @(*)begin case(a) 3'd0: q = 16'h1232; 3'd1: q = 16'haee0; 3'd2: q = 16'h27d4; 3'd3: q = 16'h5a0e; 3'd4: q = 16'h2066; 3'd5: q = 16'h64ce; 3'd6: q = 16'hc526; 3'd7: q = 16'h2f19; endcase end endmoduleSim/circuit7
这个clk开始,a上升沿q变成0,代码如下:
module top_module ( input clk, input a, output q ); always@(posedge clk)begin q <= 1; if(a)begin q <= 0; end end endmoduleSim/circuit8
First we could see p, when clk and a is true, the p is set tobe true.
q只在clock的下降沿发生变化,代码如下:
module top_module ( input clock, input a, output reg p, output reg q ); // 逻辑 p:高电平透明锁存器 (High-level sensitive latch) // 规律:clock 为高时,p 实时跟随 a 的变化;clock 为低时,p 保持之前的值。 always @(*) begin if (clock) begin p = a; end // 注意:此处不写 else,会自动产生锁存行为,符合波形图 t=120 后的保持特征 end // 逻辑 q:下降沿触发器 (Negative-edge triggered flip-flop) // 规律:q 只在 clock 的下降沿(1变0的瞬间)改变,采样此时 p 的值。 always @(negedge clock) begin q <= p; end endmoduleSim/circuit9
这个感觉像是计数器,每当a的下降沿的下一个clock开始从4开始计数,代码如下:
module top_module ( input clk, input a, output [3:0] q ); always @(posedge clk)begin if(a)begin q <= 4'd4; end else if ( q == 6 ) begin q <= 4'd0; end else begin q <= q + 1'd1; end end endmoduleSim/circuit10
直接懵了啊,看不出有啥规律,我只知道组合和逻辑都有,代码如下:
参考:https://blog.csdn.net/qq_24999747/article/details/124708510
module top_module ( input clk, input a, input b, output q, output state ); always@(posedge clk)begin if(a&&b) state <= 1'b1; else if(!(a||b)) state <= 1'b0; else state <= state; end assign q = state?(a~^b):(a^b); endmodule