Skip to content

Example: Blink LEDs

Julian Kemmerer edited this page Dec 9, 2024 · 20 revisions

UNDER CONSTRUCTION, UPDATES IN PROGRESS


blink.c is the primary example code for blinking an LED. It looks like so:

#include "uintN_t.h"  // uintN_t types for any N

// Install+configure synthesis tool then specify part here
#pragma PART "LFE5U-85F-6BG381C" 

// 'Called'/'Executing' every 30ns (33.33MHz)
#pragma MAIN_MHZ blink 33.33
uint1_t blink()
{
  // Count to 33333333 iterations * 30ns each ~= 1sec
  static uint25_t counter;

  // LED on off state
  static uint1_t led;

  // If reached 1 second
  if(counter==(33333333-1))
  {
    // Toggle led
    led = !led;
    // Reset counter
    counter = 0;
  }
  else
  {
    counter += 1; // one 30ns increment
  }
  return led;
}

--top top produces the following output VHDL:

entity top is
port(
  clk_33p33 : in std_logic;
  -- IO for each main func
  blink_return_output : out unsigned(0 downto 0)
);
end top;

Here is an old but mostly still accurate little presentation discussing a similar blinking example: blinkvid

Dev Board Setup

The below blinking portion of top.c code is from a series of examples designed for dev boards.

// See top level IO pin config in top.h
#include "top.h"

#define N 22
#define count_t uint23_t

#pragma MAIN_MHZ blinky_main 25.0
void blinky_main(){
  static count_t counter;
  led_r = 1;
  led_g = 1;
  led_b = counter >> N;
  counter += 1;
}

top.h references the board specific header inside board/ directory.

TODO Tool console output TODO final top VHDL ports depend on dev board, but internal signal names for code are the same

Clone this wiki locally