May 14, 2022

FPGA - Zedboard - my second FPGA design

My first design (a wire from a switch to an LED) was primarily intended to test my Vivado installation (as well as my second hand Zedboard) and to get familiar in a very basic way with Vivado.

Before launching into something new, I want to try something. I find a constraint file for my first project and edit it. Now I start Vivado and go to "Run Synthesis". Indeed it goes ahead and reruns it (warning me I will overwrite prior work) rather than telling me everything is up to date.

Blink an LED

Actually, I think I will blink two of them (LD0 and LD1). Also I will use vim outside of Vivado to edit the source files.

I already have vivado 2021.2 open, so I go to File, Project, New and am greeted by the new project wizard. I call the new project "zed_2".

I add a design source "blink.v". I create 2 output ports, led0 and led1.

Now I go to:

cd /home/tom/zed_2/zed_2.srcs/sources_1/new
vi blink.v
I recognize I do need an input (namely the clock), but that is trivial to edit into the verilog.

Now, the constraint file. I am going to take the approach of adding a file that I will edit ahead of time (namely the master constraint file with 3 lines uncommented).

cd /u1/Projects/FPGA/Zedboard
cp Zedboard-Master.xdc /home/tom/blink.xdc
cd
vi blink.xdc
The lines I want are:
Y9 for GCLK (I rename clock)
T22 for led0
T21 for led1
This certainly seemed to work using "add sources". There is a box to "copy the file to the project" and when I am done, I see the copy at:
/home/tom/zed_2/zed_2.srcs/constrs_1/imports/tom/blink.xdc

Now I do "Run synthesis" and get an error. I have a semicolon after "input clock" rather than a comma. I fix this with the vivado editor. Now the error is about a license for device xc7vx485t, what the heck? Indeed I look at settings and see this set for the project device (I thought I selected Zedboard??). I change and apply this in settings and try "Run Synthesis" again. This works.

I see a warning about my constraints file. This is for line 370 which sets the voltage for bank 34. Perhaps I should have commented out this line since I have nothing in bank 34. But it is just a warning.

And it works!!

I have two LED blinking away; and it does look like 1 Hz.
Here is the verilog I used:

module blink(
    input clock,
    output led0,
    output led1
    );

parameter p_CNT_1HZ = 50_000_000;

reg [31:0] r_CNT = 0;

reg  r_TOGGLE = 1'b0;

always @ (posedge clock)
    begin
      if (r_CNT == p_CNT_1HZ-1) // -1, since counter starts at 0
        begin
          r_TOGGLE <= !r_TOGGLE;
          r_CNT    <= 0;
        end
      else
        r_CNT <= r_CNT + 1;
    end

    assign led0 = r_TOGGLE;
    assign led1 = r_TOGGLE;

endmodule

I am using ideas from this example:

A change

I get tired of watching the blinking, so I edit the blink.v file and add an input "enable" and also edit the constraint file to make "enable" switch 0.

It sure is slow. Vivado has a "status" line at the upper right that you can check if you wonder if it is doing what it is supposed to be doing. But when the smoke clears, this works perfectly, here is the verilog:

module blink(
    input clock,
    input enable,
    output led0,
    output led1
    );

parameter p_CNT_1HZ = 50_000_000;

reg [31:0] r_CNT = 0;

reg  r_TOGGLE = 1'b0;

always @ (posedge clock)
    begin
      if (r_CNT == p_CNT_1HZ-1) // -1, since counter starts at 0
        begin
          r_TOGGLE <= !r_TOGGLE;
          r_CNT    <= 0;
        end
      else
        r_CNT <= r_CNT + 1;
    end

    assign led0 = enable & r_TOGGLE;
    assign led1 = enable & r_TOGGLE;

endmodule

Feedback? Questions? Drop me a line!

Tom's Computer Info / [email protected]