2012年10月18日 星期四

P6-8 非同步reset 8-bit Counter

P6-8 非同步reset 8-bit Counter 因為50Mhz / 8 =6.25MHz  無法由眼睛檢視Countert
需要由示波器量測才行,故修改為為24bit counter LEDG[0] 閃爍來測試程式


//--------------------------------------------------
// 8-bit synchronous counter wit asynchronous reset
// Filename : counter_sim.v
//--------------------------------------------------
module _8bit_counter(CLOCK_50,SW, KEY, LEDR, LEDG );

input  [17:0] SW; // toggle switches
input  [7:0]  KEY;
input  CLOCK_50;    //Clock 50MHZ
output [17:0] LEDR; // red LEDs
output [7:0]  LEDG; // green LEDs

    //change original input output to wire
    wire CLK;
    wire RESET_n;
    // wire [7:0] COUNT;  disable
    //reg [7:0] COUNT;
    //50MHZ / 8 = 6.25MHZ change into reg [23:0] COUNT;
    reg [23:0] COUNT;
    reg led;
    parameter T1S = 24'd50_000_000;  //50MHZ 
         
    assign CLK =CLOCK_50;
    assign RESET =KEY[0] ; 
    
    
always @(posedge CLK or posedge RESET_n)
begin
if (RESET_n)
  begin
COUNT <= 8'b0;
led <= 1'b0;
  end
else 
begin
COUNT <= COUNT + 1;

   if (COUNT == 24'd50_000_000)
      led <= (led ^ 1'b1);
end
   
end
  
  
   assign LEDG[0]=led;

endmodule

/*
module counter_sim(CLK, RESET, COUNT);
    input CLK;
    input RESET;
    output [7:0] COUNT;
    reg [7:0] COUNT;

always @(posedge CLK or posedge RESET)
begin
   if (RESET)
      COUNT <= 8'b0;
   else 
      COUNT <= COUNT + 1;
end
endmodule
*/





沒有留言:

張貼留言

WOKWI DHT22 & LED , Node-Red + SQLite database

 WOKWI DHT22 & LED , Node-Red + SQLite database Node-Red程式 [{"id":"6f0240353e534bbd","type":"comment&...