DE2-115 FPGA Verilog blink LED based on counter

OP #6006861
Hello,
I am using DE2-115 FPGA to make LEDG[0] and LEDG[1] blink respectively.
LEDG[0] will be on in 2s. In that period of time, LEDG[1] will be off.
After that, LEDG[0] will be off and LEDG[1] will be on for 2 seconds.
In the end, I have reset line to make the blink test repeat again.
The clock is 50Mhz => 2s is 10^8 period = 9'd100000000.
After I connected with the FPGA and run the code, the LEDG[8] was on but 
the LEDG[0] was on forever and the LEDG[1] was off forever as well.
Please help me!
Thank you



module GD (
    input CLOCK_50,
    output [8:0] LEDG
);

    reg [31:0] counter = 0;
    reg reset = 1;

    assign LEDG[7:0] = 1’b0;
    assign LEDG[8] = 1’b1;
    /* always */
   always @ (posedge CLOCK_50) begin
    if (reset==0)
      counter <= 0;
    else
      counter <= counter + 1;
    end
    always @ (posedge CLOCK_50) begin
        if (counter < 9'd100000000 ) begin
          LEDG[0] <= 1'b1;
          LEDG[1] <= 1'b0;
        end else begin
          if (counter < 9'd200000000 ) begin
          LEDG[0] <= 1'b0;
          LEDG[1] <= 1'b1;
          end else
          reset <= 0;
          end

        end

endmodule
Guest
I don't think your code syntesize without errors. In an always block, 
you can only write into registers, but your LEDGs are wires.

So you need a register for the LED states and assign that to the 
outputs:
1
module GD (
2
    input CLOCK_50,
3
    output [8:0] LEDG
4
);
5

6
    reg [31:0] counter = 0;
7
    reg reset = 1'b1;
8
    reg ledState = 1'b0;
9

10
    assign LEDG[7:0] =  ledState;
11
    assign LEDG[8]   = ~ledState;
12

13
    always @ (posedge CLOCK_50) begin
14
       if (reset==0)
15
          counter <= 0;
16
       else
17
          counter <= counter + 1;
18

19
       if (counter == 99_999_999 ) begin
20
          ledState <= ~ledState;
21
          counter  <= 0;
22
       end
23
    end
24

25
endmodule

Reply

A question of your own? This thread is over 7 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.