Advertisement
redsees

Untitled

Jan 14th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module blinker(CLK, RST, LED);
  2.  
  3.     input       CLK;
  4.     input   RST;
  5.     output      LED;
  6.     reg[31:0]   counter;
  7.     reg         LEDR;
  8.  
  9.     always@(posedge CLK, posedge RST)
  10.     begin
  11.     if( RST )
  12.     begin
  13.         counter <= 32'b0;
  14.         LEDR <= 0;
  15.     end
  16.     else
  17.     begin
  18.             if( counter == 12499999 )
  19.             begin
  20.                     LEDR <= 1'b1;
  21.                 counter <= 0;
  22.             end
  23.             else
  24.             begin
  25.                     counter <= counter + 1;
  26.             if ( counter > 6249999 )
  27.                 LEDR <= 1'b0;
  28.             end
  29.     end
  30.     end
  31.  
  32.     assign      LED = LEDR;
  33.  
  34. endmodule
  35.  
  36. module tb;
  37.  
  38.     reg clk, rst;
  39.     wire    out;
  40.  
  41.     initial
  42.     begin
  43.         clk = 1'b0;
  44.         rst = 1'b1;
  45.         #5
  46.         rst = 1'b0;
  47.     end
  48.  
  49.     always
  50.          #5 clk = !clk;
  51.    
  52.     initial
  53.         $monitor("[%d] LED = %b", $time, out);
  54.  
  55.     blinker inst0(.CLK(clk), .RST (rst), .LED(out));
  56. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement