1 / 85

數位積體電路雛型製作

數位積體電路雛型製作. Ch01-2 Verilog 語法 資料流 (DataFlow) 設計 行為 (Behavior) 設計. 資料流設計 (Dataflow level). 說明資料如何在暫存器中儲存和傳送,和資料處理的方式。使用具有關鍵字 assign 之連續指定敘述。. 持續指定 (continuous assignment). 在 資料處理層次 中對於 一條線指定給其值 的描述。 當其輸出是經過 邏輯線路 時,使用資料處理可以較為 簡潔 。 電路的設計重點在於說明 資料如何在電路中的傳送 過程。 ex. wire out;

bobby
Télécharger la présentation

數位積體電路雛型製作

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 數位積體電路雛型製作 Ch01-2 Verilog語法 資料流(DataFlow)設計 行為(Behavior)設計

  2. 資料流設計(Dataflow level) • 說明資料如何在暫存器中儲存和傳送,和資料處理的方式。使用具有關鍵字assign之連續指定敘述。

  3. 持續指定(continuous assignment) • 在資料處理層次中對於一條線指定給其值的描述。 • 當其輸出是經過邏輯線路時,使用資料處理可以較為簡潔。 • 電路的設計重點在於說明資料如何在電路中的傳送過程。 • ex. wire out; assignout = i n1 & in2; //正規式的持續指定 ex. wire out = in1 & in2 ; //隱藏式的持續指定,與上面同效果

  4. 延遲(delay) wire out; assign #10 out = in1 & in2;

  5. 布林表示式1 • assign D=(A&B)|(~C) • assignE= ~C

  6. 布林表示式 module test( E, F, A, B, C, D); output E, F; input A, B, C, D; assign E = A | (B & C) | (~B & D); assign F = (~B & C) | (B & ~C & ~D); endmodule

  7. 1 bit 半加器 module half_add(s, cout, a, b); output s, cout; // sum and carry out input a, b; assign s = a^ b; assign cout = a & b; endmodule

  8. 全加器設計 module full_adder_df (Cin, A, B, S, Cout); input Cin, A, B; output S, Cout; assign S = A ^ B ^ Cin; assign Cout = A & B | A & Cin | B & Cin; endmodule

  9. 8 bit 偶同位/全零檢查電路 • 利用精簡運算子 module even_parity(ev_parity, all_zeros, din); output ev_parity, all_zeros; input [7:0] din; assign ev_parity = ~^ din; // ev_parity = din[0]⊙din[1]⊙din[2]⊙din[3]⊙din[4]⊙din[5]⊙din[6]⊙din[7] XNOR assign all_zeros = ~| din; // all_zeros = NOT(din[0] + din[1] + din[2] + din[3] + din[4] + din[5] + din[6] + din[7] ) NOR endmodule

  10. 上機模擬練習7-7 • 利用精簡運算子 • assign練習 • 8 bit 偶同位/全零檢查電路

  11. 除8電路 • 利用移位運算子 module divid_8(quot, div); output [7:0] quot; //quotient input [7:0] div; //dividend parameter sh_bit = 3; //define the number of bits for shifting assign quot = div >> sh_bit; // >>右移 endmodule

  12. 2對1多工器 module mux2x1_df (I0,I1,S,Y); input I0,I1; input S; output Y; // 2-to-1 MUX body assign Y = ~S ? I0 : I1; endmodule

  13. 4 bit 2對1多工器 • 利用條件運算子 module mul2_1_4bits(y, sel, a, b); output [3:0] y; input [3:0] a, b; // 4-bit input data input sel; // selection line assign y = (sel) ? a : b; //條件運算子 endmodule

  14. 1對4解多工器 module demux_1_4( input i, input [1:0] s, output [3:0] f ); assign f[0] = i&(~s[1])&(~s[0]); assign f[1] = i&(~s[1])&( s[0]); assign f[2] = i&( s[1])&(~ s[0]); assign f[3] = i&( s[1])&( s[0]); endmodule

  15. 3 bit 多數表決電路 `timescale 1ns / 1ps module majority_3_data( input [2:0] i, output f ); assign f = ( i[1] & i[0] ) +( i[2] & ( i[0] | i[1] ) ); //卡諾圖化簡後結果 endmodule

  16. 4 bit 多數表決電路

  17. 有enable的2對4解碼器 module decoder_2_to_4 (x, E, Y); input [1:0] x; input E; output [3:0] Y; assign Y[0] = ~E & ~x[1] & ~x[0]; assign Y[1] = ~E & ~x[1] & x[0]; assign Y[2] = ~E & x[1] & ~x[0]; assign Y[3] = ~E & x[1] & x[0]; endmodule

  18. 3對8低態輸出解碼器 module decoder3_8( input [2:0] d, output [7:0] y ); assign y[0] = ~((~d[2]) & (~d[1]) & (~d[0])) , y[1] = ~((~d[2]) & (~d[1]) & (d[0])) , y[2] = ~((~d[2]) & (d[1]) & (~d[0])) , y[3] = ~((~d[2]) & (d[1]) & (d[0])) , y[4] = ~((d[2]) & (~d[1]) & (~d[0])) , y[5] = ~((d[2]) & (~d[1]) & (d[0])) , y[6] = ~((d[2]) & (d[1]) & (~d[0])) , y[7] = ~((d[2]) & (d[1]) & (d[0])) ; endmodule

  19. 4對2高態輸出編碼器 module encoder4_2_data( input i3, input i2, input i1, input i0, output [1:0] y ); // assign y[1] = ((((~i3) & i2) | (i3 & (~i2))) & (~i1) & (~i0)), // y[0] = ( (~i2)&(~i0)&( ((~i3) & i1) |( i3 & (~i1)) ) ); assign y[1] = ((((~i3) & i2) | (i3 & (~i2))) & (~i1) & (~i0)); assign y[0] = ( (~i2)&(~i0)&( ((~i3) & i1) |( i3 & (~i1)) ) ); endmodule

  20. 4 bit加法器 module adder_4bit( input [3:0] a, input [3:0] b, input cin, output [3:0] sum, output cout ); assign { cout,sum } = a + b + cin; endmodule

  21. 1 bit 全減器 module subtractor_1bit( input x, input y, input bin, output dif, output bout ); assign dif = ((~x)&(~y)& bin) |( (~x)&(y)&(~bin)) |(x&(~y)&(~bin))|( x & y & bin); assign bout = ((~x)&y)|((~x)& bin)|(y & bin); endmodule

  22. 4 bit 比較器 module comparator_4bit (A, B, IALTB, IAEQB, IAGTB, OAGTB, OAEQB, OALTB); input [3:0] A; input [3:0] B; input IALTB,IAEQB,IAGTB; output OAGTB,OAEQB,OALTB ; // -- comparator body-- // assign OALTB = (A < B)||(A==B)&& IALTB; assign OAGTB = (A > B)||(A==B)&& IAGTB; assign OAEQB = (A==B)&& IAEQB; endmodule

  23. 8bit偶同位產生器 module even_parity_generator(x,f); input [7:0] x; output f; assign f =^x;// compute the even parity of x endmodule

  24. 行為描述(Behavioral level ) 只考慮模組中的功能和函數,不必考慮硬體方面的詳細電路。使用具有關鍵字always之程序指定敘述。

  25. 結構化程序 • 在Verilog中”initial”和”always”是行為模型中最基本的描述,Verilog是一並行程式語言,須用硬體的角度來思考所需的設計。 • “initial”:一個initial的區塊開始的時間為時間零(t=0),當區塊中有很多的敘述時,需用begin…end上下包起來。Initial的動作是不可合成的指令,使用於模擬測試自己的設計是否正確。 • “always”:用來描述重複工作的數位邏輯電路

  26. 程序指定(Procedural assignments) • 程序指定用來更新暫存器(reg)的值,變數上被指定的值會維持到新的程序指定更新為止。 • 限定指定: (blocking assignment ) • 依照在循序區塊的位置,依序執行。一般用於模擬測試(testbench)中。使用符號為“=”。 • 無限定指定:(nonblocking assignment): • 不受敘述位置的影響,用在設計當中較能符合設計的要求,使用符號為”<=”。

  27. 事件基礎時間控制 • 一個訊號產生觸發區塊開始動作,以達到其設計功能。 • @(clock) q=d; • //當clock訊號有變化的時,q=d被執行。 • @(posedge clock) q=d; • //clock正緣觸發,當clock訊號變化為1的時,q=d被執行。 • @(negedge clock) q=d; • //clock負緣觸發,當clock訊號變化為0的時,q=d被執行。 • q=@(poedge clock) d; • //d立刻被執行,等到clock正緣觸發時再指定至q。

  28. if (條件敘述) • a. if (xxx) …. else …. • b. if (xxx)… else if (xxx) …. else…

  29. case(多路徑分支) case (判斷訊號名稱) 條件1:…..//條件1成立時,所要做的動作 條件2:.….//條件2成立時,所要做的動作 ….. default:…. //最後最好加上 。 endcase

  30. 4 bit 暫存器 • 區塊程序指定 ( blocking procedure assignment ) module reg(clk,reset,din,qout); input clk,reset; input din; output [3:0] qout; reg [3:0] qout; always@(posedge clk or posedge reset) if ( reset ) qout = 4'b0000; else begin qout[0] =din; qout[1] = qout[0]; qout[2] = qout[1]; qout[3] = qout[2]; end endmodule

  31. 4 bit 暫存器 • 非區塊程序指定 ( non_blocking procedure assignment ) module reg_bpa(clk,reset,din,qout); input clk,reset; input din; output [3:0] qout; reg [3:0] qout; always@(posedge clk or posedge reset) if ( reset ) qout <= 4'b0000; else begin qout[0] <=din; qout[1] <= qout[0]; qout[2] <=qout[1]; qout[3] <= qout[2]; end endmodule

  32. 2對1多工器 module mux2x1_bh (I0,I1,S,Y); input I0,I1; input S; output Y; reg Y; always @(I0 or I1 or S) if (S == 0) Y = I0; else Y = I1; endmodule

  33. 4 bit 2對1多工器 module mux2_1_4bit(a,b,s,f); input [3:0] a; input [3:0] b; input s; output [3:0] f; reg [3:0] f; always@( s or a or b ) begin if ( s ) f = b; else f = a; end endmodule

  34. 4對1多工器(if) module mux4_1_bhv(i,s,f); input [3:0] i; input [1:0] s; output f; reg f; always@( s, i ) begin if ( s == 2'b00 ) f = i[0]; else if ( s == 2'b01 ) f = i[1]; else if (s == 2'b10 ) f = i[2]; else f = i[3]; end endmodule

  35. 4對1多工器(case) module mux_4_1_bhv_case(i,s,f); input [3:0] i; input [1:0] s; output f; reg f; always@( i or s ) begin case ( s ) 2'b00 : f = i[0]; 2'b01 : f = i[1]; 2'b10 : f = i[2]; default: f = i[3]; endcase end endmodule

  36. 4對1多工器(case)2 module mux4_1 (I0,I1,I2,I3,S,Y); input I0,I1,I2,I3; input [1:0] S; output Y; reg Y; always @(I0 or I1 or I2 or I3 or S) case (S) 2'b00: Y =I0; 2'b01: Y =I1; 2'b10: Y =I2; 2'b11: Y =I3; endcase endmodule

  37. BCD對7段共陽解碼器

  38. BCD對7段共陽解碼器 module bcd2seg_case(hex, seg); input [3:0] hex; output [7:0] seg; reg [7:0] seg; always@( hex ) begin case ( hex) 4'b0001 : seg = 8'b1111_1001; // 1= F9H (共陽,a段在bit0) 4'b0010 : seg = 8'b1010_0100; // 2= A4H 4'b0011 : seg = 8'b1011_0000; // 3= B0H 4'b0100 : seg = 8'b1001_1001; // 4= 99H 4'b0101 : seg = 8'b1001_0010; // 5= 92H 4'b0110 : seg = 8'b1000_0010; // 6= 82H 4'b0111 : seg = 8'b1111_1000; // 7= F8H 4'b1000 : seg = 8'b1000_0000; // 8= 80H 4'b1001 : seg = 8'b1001_0000; // 9= 90H 4'b1010 : seg = 8'b1000_1000; // A= 88H 4'b1011 : seg = 8'b1000_0011; // b= 83H 4'b1100 : seg = 8'b1100_0110; // c= C6H 4'b1101 : seg = 8'b1010_0001; // d= A1H 4'b1110 : seg = 8'b1000_0110; // E= 86H 4'b1111 : seg = 8'b1000_1110; // F= 8EH default : seg = 8'b1100_0000; // 0= C0H endcase end endmodule

  39. 有enable的2對4解碼器-if module decode2_4( input wire en, input wire [1:0] a, output reg [3:0] d ); always @* begin if ( en == 1'b0 ) //也可寫成 ~en d = 4'b0000; else if ( a == 2'b00 ) d = 4'b0001; else if ( a == 2'b01 ) d = 4'b0010; else if ( a == 2'b10 ) d = 4'b0100; else d = 4'b1000; end endmodule

  40. 有enable的2對4解碼器-case module decode2_4( input wire [1:0] a, input wire en, output reg [3:0] d ); always@* begin case ( { en , a } ) 3'b000, 3'b001, 3'b010, 3'b011 : d = 4'b0000; 3'b100 : d = 4'b0001; 3'b101 : d = 4'b0010; 3'b110 : d = 4'b0100; 3'b111 : d = 4'b1000; endcase end endmodule

  41. 有enable的3對8低態輸出解碼器1 module Decoder_Behavioral_3x8_2( input [2:0] i, input en, output reg [7:0] y ); always @* begin case( { en , i } ) 4'b1000: y = 8'hfe; 4'b1001: y = 8'hfd; 4'b1010: y = 8'hfb; 4'b1011: y = 8'hf7; 4'b1100: y = 8'hef; 4'b1101: y = 8'hdf; 4'b1110: y = 8'hbf; 4'b1111: y = 8'h7f; default: y = 8'hff; endcase end endmodule

  42. 有enable的3對8低態輸出解碼器2 module Decoder_Behavioral_3x8_1( input [2:0] i, input en, output [7:0] y ); reg [7:0] x; always @* begin x = 8'b0000_0001; x = x << {~en,i}; end assign y = ~x; endmodule

  43. 4對16解碼器 • 利用有enable 的2對4解碼器

  44. 1對4解多工器 module demux_1_4_bhv_if(i,s,f); input i; input [1:0] s; output [3:0] f; reg [3:0] f; always@( i or s ) begin if ( s == 2'b00 ) f = { 3'b000, i }; else if ( s == 2'b01 ) f = { 2'b00, i, 1'b0 }; else if ( s == 2'b10 ) f = { 1'b0, i, 2'b00 }; else f = {i, 3'b000 }; end endmodule

  45. 4 bit 比較器-1 module compare1(comout, a, b); output [2:0] comout; //comout[2]:great than, //comout[1]:equal comout[0]:less than input [3:0] a, b; //input data reg [2:0] tmp_dat; always @(a or b) begin if (a>b) tmp_dat <= 3'b100; //GT EQ LT else if (a==b) tmp_dat <= 3'b010; else tmp_dat <= 3'b001; end assign comout = tmp_dat; endmodule

  46. 4 bit 比較器-2 module comparator_4bit_bhv_if(a,b,gt,eq,lt); input[3:0] a,b; output gt,eq,lt; reg gt,eq,lt; always@( a or b ) begin if ( a == b ) begin eq = 1'b1; gt = 1'b0; lt = 1'b0; end else if ( a > b ) begin eq = 1'b0; gt = 1'b1; lt = 1'b0; end else begin eq = 1'b0; gt = 1'b0; lt = 1'b1; end end endmodule

  47. 4 bit 栓鎖器(latch) module latch_4bit(din,load,f); input [3:0] din; input load; output [3:0] f; reg[3:0] f; always@( load ) begin if ( load ) f = din; end endmodule

  48. 計數器 • 不規則計數的計數器 • 規則計數 • 上數計數器 • 下數計數器 • 可上、下數計數器 • 可載入計數器

  49. 3bit不規則計數的計數器 • 1 → 3 → 5→ 7→1

  50. 4bit不規則計數的計數器2 • 2 → 4 → 6→ 8→10 →12 →14 →2

More Related