Simple 8 leds flasher

Here I am trying to make a simple program to give an example of using if statements, making the delay, bit toggle flag. To be easily understood, the example here is applied to 8led flasher with a certain period. In block entities, STOP as the input channel in the form of bit, serves to turn off the 8 led. Q_LED an 8bit output channel an array of Q_LED [7 .. 0], serves to turn on or turn off the leds. Internally there is a register for the delay is variable called ‘delay’, serves as a counter delay for the flashing leds. In addition there is a flip-flop bit to mark the led is in a state of on / off is called as “flag_blink”.

VHDL Codes

  • Lines 1-2 are library definitions use standart logic.
  • Lines 4-8 are Entities block define the I/O  of module. STOP as bit input for stopping the flasher. Q_LEDs are outputs as 8bit array for drive 8 leds. And CLK50MHZ as clock about 50MHz.
  • Process block, start on the line 10 and end on the line 36.  
  • Line 12 is a defining a integer for delay counter. Line 13 is defining bit as toggle bit for state of leds blinking.
  • Lines 16-34 is the main process of leds flasher begin by statement “begin”.
  • Below line 18 will be execute only if CLK50MHZ at rising edge state. And lines 19-23 is at the outer loop so that is always executed every CLK50MHZ on rising edge state, which produce the toggle state on flag_blink variable.
  • Lines 24-33 leds will be turned on, only when STOP = 0 and flag_blink = 1.

Flashing period

To calculate the period of the leds flashing is obtained based on frequency oscillator of fpga about 50MHz. With 50MHz oscillator the period become 20 nano second. At line 20 variable flag_blink will be toggled every 2500*8000 count of oscillator period. Time of toggle will be 2500*800*20 nano second =  400,000,000 nano second or 0.4 second. All leds will be turned on about 0.4 second and will be turned of about 0.4 second.


YouTube Preview Image


Last updated by at .

Avatar of Bambang Siswoyo

About Bambang Siswoyo

I am a college lecturer since 1988 at UB (University of Brawijaya) in the electronics department. My experience: Applications of Microprocessor system, Applications of Control System, Applications of Field Programmable Gate Array, Computer Programming in computer instrumentations. My hobby: Music especially playing the saxophone, hiking and exploring the countryside.
This entry was posted in Electronics, fpga and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *



You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>