-
Notifications
You must be signed in to change notification settings - Fork 51
Example: Blink LEDs
Julian Kemmerer edited this page Dec 9, 2024
·
20 revisions
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:
It is recommended to follow the design patterns shown in a series of examples designed for dev boards.
The blinking section of top.c
is shown below:
// 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 a board specific header inside of the board/ directory.
This design pattern of common code in top.c
with different board specifics configured in top.h
allows the final generated VHDL to be dev board specific and easy instantiate. While the internal PipelineC code can share a common interface with generic names, common helper libraries, etc.