HDLBits答案(24)_由波形图描述电路
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                HDLBits答案(24)_由波形图描述电路
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                Build a circuit from a simulation waveform
HDLBits鏈接
前言
今天更新HDLBits習題由波形圖描述電路的部分,看圖寫代碼。
題庫
Combinational circuit 1
由圖可見,q=a&b
Solution:
module top_module (input a,input b,output q );//assign q = a & b; // Fix meendmoduleCombinational circuit 2
由圖列出卡諾圖描述出來即可。
Solution:
module top_module (input a,input b,input c,input d,output q );//assign q = ~a & ~b & ~c & ~d | ~a & ~b & c & d | ~a & b & ~c & d | ~a & b & c & ~d | a & ~b & ~c & d | a & ~b & c & ~d | a & b & ~c & ~d | a & b & c & d; // Fix meendmoduleCombinational circuit 3
由波形圖列出卡諾圖化簡可得。
Solution:
module top_module (input a,input b,input c,input d,output q );//assign q = b & d | b & c | a & d | a & c; // Fix meendmoduleCombinational circuit 4
與上題同理
Solution:
module top_module (input a,input b,input c,input d,output q );//assign q = b | c; // Fix meendmoduleCombinational circuit 5
由波形圖可見這是個多路選擇器,通過c路信號進行信號選擇;
Solution:
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 @(*) begincase(c)4'd0: q <= b;4'd1: q <= e;4'd2: q <= a;4'd3: q <= d;default:q <= 4'hf;endcaseendendmoduleCombinational circuit 6
Solution:
module top_module (input [2:0] a,output [15:0] q ); always @(*) begincase(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;default:q <= 16'h2f19;endcaseendendmoduleSequential circuit 7
Solution:
module top_module (input clk,input a,output q );always @(posedge clk) beginq <= ~a;endendmoduleSequential circuit 8
由圖可見,p為a在clock為高電平時的選通信號,q為clock下降沿觸發的信號,存放p的值。
Solution:
module top_module (input clock,input a,output p,output q );reg clk_0;assign p = clock ? a : p;always @(negedge clock) beginq <= p;endendmoduleSequential circuit 9
由圖可見,q應當是一個從0-6的計數器,當a為高電平時,q保持為4,直到a為低電平時,再繼續計數;
Solution:
module top_module (input clk,input a,output [3:0] q );always @(posedge clk) beginif(a) beginq <= 4'd4;endelse if(q == 4'd6) beginq <= 4'd0;endelse beginq <= q + 4'd1;endendendmoduleSequential circuit 10
q為a,b和state的組合邏輯,列出真值表即可;
Solution:
module top_module (input clk,input a,input b,output q,output state );assign q = a ^ b ^ state;always @(posedge clk) beginif(a & b) beginstate <= 1'b1;endelse if(~a & ~b) beginstate <= 1'b0;endelse beginstate <= state;endendendmodule結語
該小結就算更新結束了,勝利就在眼前,哈哈哈!本章的解法并不唯一,大家有什么其他思路歡迎在評論區討論交流。
總結
以上是生活随笔為你收集整理的HDLBits答案(24)_由波形图描述电路的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: HDLBits答案(23)_找BUG
 - 下一篇: HDLBits答案(25)_编写Test