2020年1月5日 星期日

Verilog SR-Latch

Verilog SR-Latch 




 module RS_latch (R,  S,  Q1,  Q1bar, Q2,  Q2bar);
input R,S;
output Q1, Q1bar, Q2,  Q2bar;

 SR_latch_gate      U1(.R(R),  .S(S),  .Q(Q1),   .Qbar(Q1bar));
 SR_latch_dataflow  U2(.R(R),  .S(S),  .Q(Q2),   .Qbar(Q2bar));

endmodule

//================================================================
module SR_latch_gate (input R, input S, output Q, output Qbar);
nor (Q, R, Qbar);
nor (Qbar, S, Q);
endmodule
//================================================================
module SR_latch_dataflow (input R, input S, output Q, output Qbar);
assign #2 Q_i = Q;
assign #2 Qbar_i = Qbar;
assign #2 Q = ~ (R | Qbar);
assign #2 Qbar = ~ (S | Q);
endmodule

// 時間單位 100ns, 時間精確度100 ps
`timescale 100ns/100ps     
module Test_bench;
//(R,  S,  Q,  Qbar);
 reg R,S;
 wire Q1, Q1bar, Q2,  Q2bar;

 RS_latch UUT (R,  S,  Q1, Q1bar, Q2,  Q2bar);

initial begin
    // Initialize Inputs
    S = 0;
    R = 1;
   
    // Add stimulus here
    #100 S = 1;R = 0;
    #100 S = 1;R = 1;
    #100 S = 1;R = 0;
    #100 R = 1;S = 1;
    #100 S = 0;R = 0;
    #100 S = 1;R = 1;
    #100 S = 0;R = 0;
    #100 $stop;
end
endmodule

沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) Node-Red 程式 [{"id":"d8886...