When the ‘light’ comes on, is it an LED? Part 2

In the previous article (I am adding a link so the analysis will be happier) Part 1 I discussed my troubles trying to blink an LED on the Hackaday 2019 Badge. I decided to post the full FPGA code that finally works. I got two different versions.

After getting proper results with the one code, I decided to try out the different way. The assign ledc[5] = 1'b1; to turn on the LED at start was my problem all along.

Here are the two successful FPGA codes.

module top (
input clk,
output [10:0] ledc,
output [2:0] leda,
);

assign leda = 3'b010;

assign ledc[5] = counter[21];

reg [31:0] counter;

initial begin
counter <= 32'b0;
end

always @(posedge clk) begin
counter <= counter + 1'b1;
end

endmodule

ADM! That was difficult to type into one paragraph! Copy and paste was not going to work. And the second FPGA code is below.

module top (
input clk,
output [10:0] ledc,
output [2:0] leda,
);

assign leda = 3'b010;
assign ledc[5] = led_status;

reg [31:0] counter;
reg led_status;

initial begin
counter <= 32'b0;
led_status = 1'b0;
end

always @(posedge clk) begin
counter <= counter + 1'b1;
if (counter > 5000000) begin
led_status <= !led_status;
counter <= 32'b0;
end
end

endmodule

That was a little bit easier, but copy and paste got rid of a lot of the returns at the end of lines. I had to shift-return a bunch of times. Adding FPGA code to this post hasn’t been easy.