日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDLBits答案(6)_硬件模块设计的思考方式

發布時間:2023/12/19 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDLBits答案(6)_硬件模块设计的思考方式 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

硬件模塊設計的思考方式

HDLBits鏈接


基本的邏輯門操作

題目描述1:將輸入端口in和輸出端口out連接。

Solution1

module top_module (input in,output out);assign out = in; endmodule

題目描述2:將輸出out接地。

Solution2

module top_module (output out);assign out = 1'b0; endmodule

題目描述3:實現或非門操作。

Solution3

module top_module (input in1,input in2,output out);assign out =~(in1 | in2); endmodule

題目描述4:實現下圖所示的邏輯操作。

Solution4

module top_module (input in1,input in2,output out);assign out = in1 & (~in2); endmodule

題目描述5:實現下圖所示的邏輯操作。

Solution5

module top_module (input in1,input in2,input in3,output out);wire temp;assign temp = ~(in1^in2);assign out = temp ^ in3; endmodule

題目描述6:嘗試同時建立幾個邏輯門,建立一個兩輸入的組合電路。

共7個輸出如下:

  • out_and: a and b
  • out_or: a or b
  • out_xor: a xor b
  • out_nand: a nand b
  • out_nor: a nor b
  • out_xnor: a xnor b
  • out_anotb: a and-not b

Solution6

module top_module( input a, b,output out_and,output out_or,output out_xor,output out_nand,output out_nor,output out_xnor,output out_anotb );assign out_and = a&b;assign out_or = a|b;assign out_xor = a^b;assign out_nand = ~(a&b);assign out_nor = ~(a|b);assign out_xnor = ~(a^b);assign out_anotb = a&(~b); endmodule

題目描述7

7400系列集成電路是一個數字芯片系列,每個都由幾個基本的邏輯門構成。7420是一個帶有兩個4輸入與非門的芯片。

實現一個具有與7420芯片相同功能的模塊,共8個輸入和2個輸出。

Solution7

module top_module ( input p1a, p1b, p1c, p1d,output p1y,input p2a, p2b, p2c, p2d,output p2y );assign p1y=~(p1a&p1b&p1c&p1d);assign p2y=~(p2a&p2b&p2c&p2d); endmodule

真值表

在前面的練習中,我們使用簡單的邏輯門和幾個邏輯門的組合,這些電路是組合電路的例子。

組合電路的意思是電路的輸出僅取決于輸入,這意味著對于任何給定的輸入值,只有一個可能的輸出值。因此,描述組合函數行為的一種方法是明確地列出所有可能的輸入所對應的輸出值,即真值表。

對一個有N個輸入的布爾函數而言,有2N種可能的輸入組合。真值表的每一行都列出了一個輸入組合,因此總有2N行。output列顯示了每個輸入值對應的輸出。

那么我們如何只用標準邏輯門來實現查找表的功能呢?

一種簡單的方法是將真值表中所有的真值寫為乘積求和項的形式。求和即為或操作,乘積即為與操作。先使用一個N-輸入的與門來決定是否輸入的向量與真值表匹配,然后再用一個或門來選擇滿足匹配條件的結果進行輸出。

題目描述:構建一個模塊實現上述真值表的功能。

Solution

module top_module( input x3,input x2,input x1, // three inputsoutput f // one output );assign f = ((~x3)&x2&(~x1))|((~x3)&x2&x1)|(x3&(~x2)&x1)|(x3&x2&x1); endmodule

部分考題

題目描述1

創建一個有兩個2位輸入A[1:0]和B[1:0]的電路,產生一個輸出z。若A=B,則z=1,否則z=0。

Solution1

module top_module ( input [1:0] A, input [1:0] B, output z ); assign z=(A==B)?1'b1:1'b0; endmodule

題目描述2

構建模塊實現函數z = (x^y) & x

Solution2:

module top_module (input x, input y, output z);assign z=(x^y)&x; endmodule

題目描述3

構建模塊實現如下波形圖的輸入輸出關系

Solution3

module top_module ( input x, input y, output z );assign z=~(x^y); endmodule

題目描述4

A模塊實現的功能如上述題二所示,B模塊實現的功能如題三所示。搭建模塊實現下圖所示功能:

Solution4

module top_module (input x, input y, output z);wire za;wire zb;assign za = (x ^ y) & x;assign zb = ~(x ^ y);assign z = (za | zb) ^ (za & zb);endmodule

硬件工程師的思考方式

[David說]:當進行模塊設計時,我們最好后向思考問題,如何從輸出到輸入。這與我們平時順序式地思考編程問題不同,在編程時我們一般首先看輸入如何決定輸出,即輸入為XX時輸出為XX;對硬件工程師而言,通常的思路為輸出為XX時輸入是XX

在硬件設計中,在兩種思路間思考與切換是很重要的技能。

題目描述1:設計一種電路來控制手機的鈴聲和振動馬達。當有來電輸入信號時(input ring),電路必須打開鈴聲(output ringer= 1)或電機(output motor= 1),但不能同時打開。如果手機處于振動模式(input vibrate_mode = 1),打開電機。否則打開鈴聲。

Solution1

module top_module (input ring,input vibrate_mode,output ringer, // Make soundoutput motor // Vibrate );assign ringer = ring & (~vibrate_mode);assign motor = ring & vibrate_mode; endmodule

題目描述2:加熱/冷卻恒溫器同時控制加熱器(冬季)和空調(夏季)。設計一個電路,根據需要打開或關閉加熱器、空調和鼓風機。

恒溫器有兩種模式:加熱模式(mode= 1)和冷卻模式(mode= 0)。在加熱模式下,當溫度過低時打開加熱器(too_cold = 1)但是不要使用空調。在冷卻模式下,當溫度太高(too_hot= 1)時打開空調,但不要打開加熱器。

當暖氣或空調打開時。同時打開風扇讓空氣流通。此外。用戶也可以僅要求風扇打開(fan_on = 1),即使加熱器和空調關閉。

Solution2

module top_module (input too_cold,input too_hot,input mode,input fan_on,output heater,output aircon,output fan ); assign heater = mode & too_cold;assign aircon = (~mode) & too_hot;assign fan = (mode & too_cold) | ((~mode) & too_hot) | fan_on; endmodule

對單向量的各bit進行操作

[David說]:想到assign實現就用assign,否則可以合理使用for循環減少代碼量。

題目描述1:為3位輸入向量構造一個數1的計數電路。

Solution1

module top_module( input [2:0] in,output [1:0] out );integer i;always @(*) beginout = 2'b0;for(i=0;i<3;i++) beginout = out + in[i];endend endmodule

題目描述2:。輸入一個4位的輸入向量in[3:0],輸出每個比特和它相鄰比特之間的一些關系:

  • out_both:這個輸出向量的每一位應該表示對應的輸入位和它左邊的比特位(左邊比特具有更高的索引)是否均為“1”。舉例說明,out_both[2]應該指示出in[2]和in[3]是否均為1。
  • out_any:這個輸出向量的每一位都應該表示相應的輸入位和它右邊的比特位是否存在“1”
  • out_different:這個輸出向量的每一位都應該表明相應的輸入位是否與其左邊的比特位不同

Solution2

思路一:

module top_module( input [3:0] in,output [2:0] out_both,output [3:1] out_any,output [3:0] out_different );integer i;always @(*) beginfor(i=0;i<3;i++) beginout_both[i] = in[i] & in[i+1];out_any[i+1] = in[i+1] | in[i];out_different[i] = in[i] ^ in[i+1];endout_different[3] = in[0] ^ in[3];endendmodule

思路二:

module top_module( input [3:0] in,output [2:0] out_both,output [3:1] out_any,output [3:0] out_different );assign out_both = in[2:0] & in[3:1];assign out_any = in[3:1] | in[2:0];assign out_different = in[3:0] ^ {in[0],in[3:1]};endmodule

題目描述3:題目同上,但輸入向量變為100位。

Solution3

思路一:

module top_module( input [99:0] in,output [98:0] out_both,output [99:1] out_any,output [99:0] out_different );integer i;always @(*) beginfor(i=0;i<99;i++) beginout_both[i] = in[i] & in[i+1];out_any[i+1] = in[i+1] | in[i];out_different[i] = in[i] ^ in[i+1];endout_different[99] = in[0] ^ in[99];endendmodule

思路二:

module top_module( input [99:0] in,output [98:0] out_both,output [99:1] out_any,output [99:0] out_different );assign out_both = in[98:0] & in[99:1];assign out_any = in[99:1] | in[98:0];assign out_different = in[99:0] ^ {in[0],in[99:1]};endmodule

總結

  • 熟悉了基本的邏輯門操作。
  • 學習了硬件工程師的設計思維:由輸出到輸入。
  • 學習了用標準的邏輯門實現查找表的功能。
  • 合理使用assign或for循環對向量的各bit位進行操作。

總結

以上是生活随笔為你收集整理的HDLBits答案(6)_硬件模块设计的思考方式的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。