Skip to main content

Posts

Showing posts from June, 2012

Binary Counter in Verilog | BASYS2

Now that we have the blinking LED in Verilog up and running, we can do an advanced version of the same project; a binary counter using the LED's. Also this time I will be using the push button to increment the counter. So every time the push button is pressed the counter will be incremented by 1, the LED's will present the binary counter. The code for the program is shown below: module button_binary( input clock, input reset, input button, output led, output led2, output led3, output led4, output led5, output led6, output led7, output led8 ); reg [7:0]count; always @ (posedge button or posedge reset) begin if (reset) count <= 0; else if (button) count <= count + 1; end assign led = count[0]; assign led2 = count[1]; assign led3 = count[2]; assign led4 = count[3]; assign led5 = count[4]; assign led6 = count[5]; assign led7 = count[6]; assign led8 = count[7]; endmodule The above program is so simple it ne

Code to Make the LED Blink

This is a very simple program, the desired target is to make the LED's on the BASYS2 board blink, and by blinking I mean a very visible turning on and off. This can be very easily achieved in verilog. The code can be found below: module led_simple( input clock, input reset, output led, led2, led3, led4, led5 ); reg [26:0] count; //A sizable 27 bit register so that the blink can be seen and is visible, too small a register will make the //register stay on as it will blink extremely fast. always@ (posedge clock or posedge reset) begin if (reset) count <= 0; //if reset button is pressed, initialize or reset the register else count <= count + 1; //otherwise increment the register end assign led = count[26]; //MSB connected to output led. and the other outputes conncted as below assign led2 = count[25]; assign led3 = count[24]; assign led4 = count[23]; assign led5 = count[22]; endmodule The concept is very simple. I defined a 27 b

User Constraint File .UCF for BASYS2 Board

Here is the user constraint file (.ucf) file that shows every pin location on the board. This file will be used in every project here as without it programming the FPGA is impossible. # Pin assignment for LEDs NET "ld<7>" LOC = "g1" ; NET "ld<6>" LOC = "p4" ; NET "ld<5>" LOC = "n4" ; NET "ld<4>" LOC = "n5" ; NET "ld<3>" LOC = "p6" ; NET "ld<2>" LOC = "p7" ; NET "ld<1>" LOC = "m11" ; NET "ld<0>" LOC = "m5" ; # Pin assignment for slide switches NET "sw<7>" LOC = "n3"; NET "sw<6>" LOC = "e2"; NET "sw<5>" LOC = "f3"; NET "sw<4>" LOC = "g3"; NET "sw<3>" LOC = "b4"; NET "sw<2>" LOC = "k3"; NET "sw<1>&qu