Last active
March 7, 2019 02:03
-
-
Save k3170makan/e45447f4da043b3690020f1e0dd88790 to your computer and use it in GitHub Desktop.
LEDBlinker.v
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`default_nettype none | |
module top( | |
input clk, //clock input | |
output reg LED1, //LED outputs | |
output reg LED2, | |
output reg LED3, | |
output reg LED4, | |
output reg LED5 | |
); | |
localparam BITS = 5; //a bit for each LED | |
localparam LOG2DELAY = 21; //size of the clock, divide it by 2**21 => 21 MHZ / 21 MHZ => 1HZ clock | |
reg [BITS+LOG2DELAY-1:0] cntr = 0; //set up an array of flip flops as a clock scaler | |
reg [BITS-1:0] outcnt; //output reg's we will map to the LEDs | |
assign {LED1, LED2, LED3, LED4, LED5} = outcnt; //map the LED outputs to the outcnt reg's | |
//this means everytime the LED* changes it will be according to the bit array in outcnt | |
always @ (posedge clk) begin | |
cntr <= cntr + 1; //update clock counter | |
outcnt <= cntr >> LOG2DELAY; //assign value to outcnt | |
end | |
endmodule |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment