Język VERLOG w praktyce RUS RUS
Język VERLOG rzykłady syntezy blokowej RUS RUS
Elementy systemu cyfrowego magistrala danych cd. module swap (Data, Resetn, w, Clock, Extern, RinExt, Busires); input [7:0] Data; input Resetn, w, Clock, Extern; input [1:3] RinExt; output [7:0] Busires; tri [7:0] Busires; wire [1:3] Rin, Rout, Q; wire [7:0] R1, R2, R3; shiftr control (Resetn, w, Clock, Q); defparam control.m = 3; assign Rin[1] = RinExt[1] Q[3]; assign Rin[2] = RinExt[2] Q[2]; assign Rin[3] = RinExt[3] Q[1]; assign Rout[1] = Q[2]; assign Rout[2] = Q[1]; assign Rout[3] = Q[3]; regn reg_1 (Busires, Rin[1], Clock, R1); regn reg_2 (Busires, Rin[2], Clock, R2); regn reg_3 (Busires, Rin[3], Clock, R3); trin tri_ext (Data, Extern, Busires); trin tri_1 (R1, Rout[1], Busires); trin tri_2 (R2, Rout[2], Busires); trin tri_3 (R3, Rout[3], Busires); module Rys. 7.69. Specyfikacja systemu cyfrowego z rys. 7.60 3
Elementy systemu cyfrowego magistrala danych cd. module swapmux(data, Resetn, w, Clock, RinExt, Busires); input [7:0] Data; input Resetn, w, Clock; input [1:3] RinExt; output [7:0] Busires; reg [7:0] Busires; wire [1:3] Rin, Q; wire [7:0] R1, R2, R3; reg [1:0] S; shiftr control (Resetn, w, Clock, Q); defparam control.m = 3; assign Rin[1] = RinExt[1] Q[3]; assign Rin[2] = RinExt[2] Q[2]; assign Rin[3] = RinExt[3] Q[1]; regn reg_1 (Busires, Rin[1], Clock, R1); regn reg_2 (Busires, Rin[2], Clock, R2); regn reg_3 (Busires, Rin[3], Clock, R3); always @(Q or Data or R1 or R2 or R3 or S) // Kodowanie if (Q == 3'b000) S = 2'b00; else if (Q == 3'b100) S = 2'b10; else if (Q == 3'b010) S = 2'b01; else S = 2'b11; // Multipleksery if (S == 2'b00) Busires = Data; else if (S == 2'b01) Busires = R1; else if (S == 2'b10) Busires = R2; else Busires = R3; module Rys. 7.70. Specyfikacja magistrali danych z multiplekserami 4
Elementy systemu cyfrowego magistrala danych cd. module swapmux (Data, Resetn, w, Clock, RinExt, Busires); input [7:0] Data; input Resetn, w, Clock; input [1:3] RinExt; output [7:0] Busires; reg [7:0] Busires; wire [1:3] Rin, Q; wire [7:0] R1, R2, R3; shiftr control (Resetn, w, Clock, Q); defparam control.m = 3; assign Rin[1] = RinExt[1] Q[3]; assign Rin[2] = RinExt[2] Q[2]; assign Rin[3] = RinExt[3] Q[1]; regn reg_1 (Busires, Rin[1], Clock, R1); regn reg_2 (Busires, Rin[2], Clock, R2); regn reg_3 (Busires, Rin[3], Clock, R3); always @(Q or Data or R1 or R2 or R3) if (Q == 3'b000) Busires = Data; else if (Q == 3'b100) Busires = R2; else if (Q == 3'b010) Busires = R1; else Busires = R3; module Rys. 7.71. Uproszczona wersja specyfikacji z rys. 7.70 5
rzykład systemu cyfrowego: prosty procesor cd. module proc (Data, Reset, w, Clock, F, Rx, Ry, Done, Busires); input [7:0] Data; input Reset, w, Clock; input [1:0] F, Rx, Ry; output [7:0] Busires; output Done; wire [7:0] Busires; reg [0:3] Rin, Rout; reg [7:0] Sum; wire Clear, AddSub, Extern, Ain, Gin, Gout, FRin; wire [1:0] Count; wire [0:3],, Xreg, Y; wire [7:0] R0, R1, R2, R3, A, G; wire [1:6] Func, FuncReg; integer k; upcount counter (Clear, Clock, Count); dec2to4 dec (Count, 1, ); assign Clear = Reset Done (~w & [0]); assign Func = {F, Rx, Ry}; assign FRin = w & [0]; regn functionreg (Func, FRin, Clock, FuncReg); defparam functionreg.n = 6; dec2to4 dec (FuncReg[1:2], 1, ); dec2to4 decx (FuncReg[3:4], 1, Xreg); dec2to4 decy (FuncReg[5:6], 1, Y); assign Extern = [0] & [1]; assign Done = (([0] [1]) & [1]) (([2] [3]) & [3]); assign Ain = ([2] [3]) & [1]; assign Gin = ([2] [3]) & [2]; assign Gout = ([2] [3]) & [3]; assign AddSub = [3]; kontynuacja w części b. Rys. 7.77. Specyfikacja procesora (część a.) 6
rzykład systemu cyfrowego: prosty procesor cd. // RegCntl always @( or or Xreg or Y) for (k = 0; k < 4; k = k+1) Rin[k] = (([0] [1]) & [1] & Xreg[k]) (([2] [3]) & [1] & Y[k]); Rout[k] = ([1] & [1] & Y[k]) (([2] [3]) & (([1] & Xreg[k]) ([2] & Y[k]))); trin tri_ext (Data, Extern, Busires); regn reg_0 (Busires, Rin[0], Clock, R0); regn reg_1 (Busires, Rin[1], Clock, R1); regn reg_2 (Busires, Rin[2], Clock, R2); regn reg_3 (Busires, Rin[3], Clock, R3); trin tri_0 (R0, Rout[0], Busires); trin tri_1 (R1, Rout[1], Busires); trin tri_2 (R2, Rout[2], Busires); trin tri_3 (R3, Rout[3], Busires); trin reg_a (Busires, Ain, Clock, A); // alu always @(AddSub or A or Busires) if (!AddSub) Sum = A + Busires; else Sum = A - Busires; regn reg_g (Sum, Gin, Clock, G); trin tri_g (G, Gout, Busires); module Rys. 7.77. Specyfikacja procesora (część b.) 7
rzykład systemu cyfrowego: prosty procesor cd. module proc(data, Reset, w, Clock, F, Rx, Ry, Done, Busires); input [7:0] Data; input Reset, w, Clock; input [1:0] F, Rx, Ry; output [7:0] Busires; output Done; reg [7:0] Busires, Sum; reg [0:3] Rin, Rout; reg Extern, Done, Ain, Gin, Gout, AddSub; wire [1:0] Count, ; wire [0:3] Xreg, Y; wire [7:0] R0, R1, R2, R3, A, G; wire [1:6] Func, FuncReg, Sel; wire Clear = Reset Done (~w & ~Count[1] & ~Count[0]); upcount counter (Clear, Clock, Count); assign Func = {F, Rx, Ry}; wire FRin = w & ~Count[1] & ~Count[0]; regn functionreg (Func, FRin, Clock, FuncReg); defparam functionreg.n = 6; assign = FuncReg[1:2]; dec2to4 decx (FuncReg[3:4], 1, Xreg); dec2to4 decy (FuncReg[5:6], 1, Y); kontynuacja w części b) Rys. 7.78. Alternatywna specyfikacja procesora (część a) 8
rzykład systemu cyfrowego: prosty procesor cd. always @(Count or or Xreg or Y) Extern = 1'b0; Done = 1'b0; Ain = 1'b0; Gin = 1'b0; Gout = 1'b0; AddSub = 1'b0; Rin = 4'b0; Rout = 4'b0; case (Count) 2'b00: ; //no signals asserted in time step 0 2'b01: //define signals in time step 1 case () 2'b00: // Ładowanie (Load) Extern = 1'b1; Rin = Xreg; Done = 1'b1; 2'b01: // rzemieszczenie (Move) Rout = Y; Rin = Xreg; Done = 1'b1; default: //Add, Sub Rout = Xreg; Ain = 1'b1; case 2'b10: //określenie sygnałów w kroku 2 case () 2'b10: //Add Rout = Y; Gin = 1'b1; 2'b11: //Sub Rout = Y; AddSub = 1'b1; Gin = 1'b1; default: ; //Add, Sub case 2'b11: case () 2'b10, 2'b11: Gout = 1'b1; Rin = Xreg; Done = 1'b1; default: ; //Add, Sub case case kontynuacja w części c). Rys. 7.78. Alternatywna specyfikacja procesora (część b) 9
rzykład systemu cyfrowego: prosty procesor cd. regn reg_0 (Busires, Rin[0], Clock, R0); regn reg_1 (Busires, Rin[1], Clock, R1); regn reg_2 (Busires, Rin[2], Clock, R2); regn reg_3 (Busires, Rin[3], Clock, R3); regn reg_a (Busires, Ain, Clock, A); //alu always @(AddSub or A or Busires) if (!AddSub) Sum = A + Busires; else Sum = A - Busires; regn reg_g (Sum, Gin, Clock, G); assign Sel = {Rout, Gout, Extern}; always @(Sel or R0 or R1 or R2 or R3 or G or Data) if (Sel == 6'b100000) Busires = R0; else if (Sel == 6'b010000) Busires = R1; else if (Sel == 6'b001000) Busires = R2; else if (Sel == 6'b000100) Busires = R3; else if (Sel == 6'b000010) Busires = G; else Busires = Data; module Rys. 7.78. Alternatywna specyfikacja procesora (część c) 10
rzykład systemu cyfrowego: miernik czasu reakcji cd. module BCDcount (Clock, Clear, E, BCD1, BCD0); input Clock, Clear, E; output [3:0] BCD1, BCD0; reg [3:0] BCD1, BCD0; always @(posedge Clock) if (Clear) BCD1 <= 0; BCD0 <= 0; else if (E) if (BCD0 == 4'b1001) BCD0 <= 0; if (BCD1 == 4'b1001) BCD1 <= 0; else BCD1 <= BCD1 + 1; else BCD0 <= BCD0 + 1; module Rys. 7.81 Specyfikacja dwucyfrowego licznika BCD 11
rzykład systemu cyfrowego: miernik czasu reakcji cd. module reaction (c9, Reset, w, ushn, LEDn, Digit1, Digit0); input c9, Reset, w, ushn; output LEDn; output [1:7] Digit1, Digit0; wire LEDn; wire [1:7] Digit1, Digit0; reg LED; wire [3:0] BCD1, BCD0; always @(posedge c9) if (ushn == 0) LED <= 0; else if (w) LED <= 1; assign LEDn = ~LED; BCDcount counter (c9, Reset, LED, BCD1, BCD0); seg7 seg1 (BCD1, Digit1); seg7 seg0 (BCD0, Digit0); module Rys. 7.82 Specyfikacja miernika czasu reakcji 12
VERLOG specyfikacja automatów cd. module mealy (Clock, Resetn, w, z); input Clock, Resetn, w; output z; reg y, Y, z; parameter A = 0, B = 1; // Określenie stanu następnego i wyjścia always @(w or y) case (y) A: if (w) z = 0; Y = B; else z = 0; Y = A; B: if (w) z = 1; Y = B; else z = 0; Y = A; case // Określenie bloku sekwencyjnego always @(negedge Resetn or posedge Clock) if (Resetn == 0) y <= A; else y <= Y; module Rys. 8.34 Specyfikacja automatu Mealy ego z rys. 8.23 13
rzykład : sumator sekwencyjny cd. module serial_adder (A, B, Reset, Clock, Sum); input [7:0] A, B; input Reset, Clock; output [7:0] Sum; reg [3:0] Count; reg s, y, Y; wire [7:0] QA, QB, Sum; wire Run; parameter G = 0, H = 1; shiftrne shift_a (A, Reset, 1, 0, Clock, QA); shiftrne shift_b (B, Reset, 1, 0, Clock, QB); shiftrne shift_sum (0, Reset, Run, s, Clock, Sum); // Automat sumatora // yjście i stan następny (część kombinacyjna) always @(QA or QB or y) case (y) G: s = QA[0] ^ QB[0]; if (QA[0] & QB[0]) Y = H; else Y = G; H: s = QA[0] ~^ QB[0]; if (~QA[0] & ~QB[0]) Y = G; else Y = H; default: Y = G; case // Blok sekwencyjny always @(posedge Clock) if (Reset) y <= G; else y <= Y; // Sterowanie operacją przesuwu always @(posedge Clock) if (Reset) Count = 8; else if (Run) Count = Count - 1; assign Run = Count; module Rys. 8.49 Specyfikacja sumatora sekwencyjnego 14
rzykład : licznik jedynek w słowie cd. module bitcount (Clock, Resetn, LA, s, Data, B, Done); input Clock, Resetn, LA, s; input [7:0] Data; output [3:0] B; output Done; wire [7:0] A; wire z; reg [1:0] Y, y; reg [3:0] B; reg Done, EA, EB, LB; // układ sterujący parameter S1 = 2'b00, S2 = 2'b01, S3 = 2'b10; always @(s or y or z) : State_table case (y) S1: if (!s) Y = S1; else Y = S2; S2: if (z == 0) Y = S2; else Y = S3; S3: if (s) Y = S3; else Y = S1; default: Y = 2'bxx; case always @(posedge Clock or negedge Resetn) : State_flipflops if (Resetn == 0) y <= S1; else y <= Y; kontynuacja w części b. Rys. 10.13 Specyfikacja układu licznika jedynek (część a.) 15
rzykład : licznik jedynek w słowie cd. module always @(y or A[0]) : FSM_outputs // defaults EA = 0; LB = 0; EB = 0; Done = 0; case (y) S1: LB = 1; S2: EA = 1; if (A[0]) EB = 1; else EB = 0; S3: Done = 1; case // układ operacyjny (datapath circuit) // licznik B always @(negedge Resetn or posedge Clock) if (!Resetn) B <= 0; else if (LB) B <= 0; else if (EB) B <= B + 1; shiftrne ShiftA (Data, LA, EA, 0, Clock, A); assign z = ~ A; Rys. 10.13 Specyfikacja układu licznika jedynek (część b.) 16