当前位置:   article > 正文

刷完这套题,我才发现Verilog原来如此简单----HDLBits答案系列 -- Build a circuit from a simulation waveform_a异或b异或cfpga

a异或b异或cfpga

写在前面

全部答案汇总:刷完这套题,我才发现Verilog原来如此简单----HDLBits答案汇总

今天更新Circuits章节中Verification:Reading Simulation的1个小节:Build a circuit from a simulation waveform

这个章节的内容是根据波形图编写Verilog代码,从波形图到硬件描述语言的转变是FPGAer的基本功(核心),而且在信号多、时序复杂的项目中读懂波形图更是一项一定要熟练掌握的能力。


Combinational circuit 1

【题目】:

        根据下面的时序图实现这个组合逻辑电路。

【个人思路】:

        从上面的q输出为1处,可以看到a、b均为1,所以逻辑是 a & b.

  1. module top_module (
  2. input a,
  3. input b,
  4. output q );//
  5. assign q = a & b; // Fix me
  6. endmodule

Combinational circuit 2

【题目】:

        根据下面的时序图实现这个组合逻辑电路。

【个人思路】:

        这个时序图稍微复杂点,最好是列出卡诺图,如下:

红色部分的四个数据,可以看出来是 ( a同或b ) 与上 ( c同或d );

蓝色部分的四个数据,可以看出来是 ( a异或b ) 与上 ( c异或d );

红色+蓝色 = ( a异或b ) 同或( c异或d ) =~a^b^c^d;

  1. module top_module (
  2. input a,
  3. input b,
  4. input c,
  5. input d,
  6. output q );//
  7. //assign q = 1-a^b^c^d;
  8. assign q = ~a^b^c^d;
  9. endmodule

Combinational circuit 3

【题目】:

        根据下面的时序图实现这个组合逻辑电路。

 【个人思路】:

          这个时序图稍微复杂点,最好是列出卡诺图,如下:

像我这样框起来:红色:b | d;黄色:b | c;黑色:a | d;绿色:a | c;

  1. module top_module (
  2. input a,
  3. input b,
  4. input c,
  5. input d,
  6. output q );//
  7. assign q = b & d | b & c | a & d | a & c;
  8. endmodule

Combinational circuit 4

【题目】:

        根据下面的时序图实现这个组合逻辑电路。

 【个人思路】:

          这个时序图稍微复杂点,最好是列出卡诺图,如下:

 红色:c;绿色:b;所以化简为 b | c。

  1. module top_module (
  2. input a,
  3. input b,
  4. input c,
  5. input d,
  6. output q );//
  7. assign q = b | c; // Fix me
  8. endmodule

Combinational circuit 5

【题目】:

        根据下面的时序图实现这个组合逻辑电路。

【个人思路】 :

        可以看出这是一个4输入、1输出的组合电路,且输出是根据c的取值来的,所以这个是个4选1电路(MUX4),所以可以用case语句来根据c的取值来进行输出。

  1. module top_module (
  2. input [3:0] a,
  3. input [3:0] b,
  4. input [3:0] c,
  5. input [3:0] d,
  6. input [3:0] e,
  7. output [3:0] q );
  8. always@(*)begin
  9. case(c)
  10. 4'd0: q = b;
  11. 4'd1: q = e;
  12. 4'd2: q = a;
  13. 4'd3: q = d;
  14. default: q = 4'hf;
  15. endcase
  16. end
  17. endmodule

Combinational circuit 6

【题目】:

        根据下面的时序图实现这个组合逻辑电路。

【个人思路】 :

        可以看出这是一个根据输入a的取值来进行输出的组合电路,可以用case语句来根据a的取值来进行输出。

  1. module top_module (
  2. input [2:0] a,
  3. output [15:0] q );
  4. always@(*)begin
  5. case(a)
  6. 3'd0: q = 16'h1232;
  7. 3'd1: q = 16'haee0;
  8. 3'd2: q = 16'h27d4;
  9. 3'd3: q = 16'h5a0e;
  10. 3'd4: q = 16'h2066;
  11. 3'd5: q = 16'h64ce;
  12. 3'd6: q = 16'hc526;
  13. 3'd7: q = 16'h2f19;
  14. default:;
  15. endcase
  16. end
  17. endmodule

Sequential circuit 7

【题目】:

        根据下面的时序图实现这个时序逻辑电路。

 

【个人思路】 :

        可以看出输出q是输入a的取反,因为是时序逻辑,所以输出落后输入一个时钟周期。

  1. module top_module (
  2. input clk,
  3. input a,
  4. output q );
  5. always@(posedge clk)begin
  6. if(a)
  7. q <= 1'b0;
  8. else
  9. q <= 1'b1;
  10. end
  11. endmodule

Sequential circuit 8

【题目】:

        根据下面的时序图实现这个时序逻辑电路。

 

【个人思路】 :

        由图可见,p为a在clock为高电平时的选通信号,q为clock下降沿触发的信号,存放p的值。

  1. module top_module (
  2. input clock,
  3. input a,
  4. output p,
  5. output q );
  6. always@(*)begin
  7. if(clock)
  8. p <= a;
  9. else
  10. p <= p;
  11. end
  12. always@(negedge clock)begin
  13. q <= p;
  14. end
  15. endmodule

Sequential circuit 9

【题目】:

        根据下面的时序图实现这个时序逻辑电路。

【个人思路】 :

        可以看出这是一个~a使能的0~6计数器,a高电平时计数器复位到4.

  1. module top_module (
  2. input clk,
  3. input a,
  4. output [3:0] q );
  5. always@(posedge clk)begin
  6. if(~a)begin
  7. if(q == 4'd6)
  8. q <= 4'd0;
  9. else
  10. q <= q + 1'b1;
  11. end
  12. else
  13. q <= 4'd4;
  14. end
  15. endmodule

Sequential circuit 10

【题目】:

        根据下面的时序图实现这个电路,该电路包含组合逻辑和D触发器。

【个人思路】 :

        可以看到当输出q为高电平时,a、b、state三个中总是有奇数个高电平,所以q是a、b、state三个的偶校验位:q = a ^ b ^ state;

        再来观察state的变化,state的变化都发生在(a == b)时,且变化的值为a(或者说b),当a不等于b时,state保持不变。

  1. module top_module (
  2. input clk,
  3. input a,
  4. input b,
  5. output q,
  6. output state );
  7. assign q = a ^ b ^ state;
  8. always @(posedge clk)begin
  9. if(a == b)
  10. state <= a;
  11. else
  12. state <= state;
  13. end
  14. endmodule

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号