Jump to content
  • 0

Help For Coding a blinking trail


xanderplush

Question

Hi there, new to Verilog and Basys 3 board. I am trying to write a code that allows for a single blinking trail that keeps repeating itself starting from LD9 and going towards LD0 on the Basys 3 board.

However, the code does not work properly and I am unable to code it onto the board. My code is as follows below. I would appreciate some help as I am confused since there is no errors popping up.

module trail(input CLOCK);

    reg [25:0] COUNT = 26'b0000;
    integer M;
    reg [9:0]led;  
    always @ (posedge CLOCK) begin
    
    for (M = 9; M >= 0; M = M -1) begin
        led[M] <= (COUNT == 26'b0000) ? ~ led[M] : led[M];
        led[M-1] <= (COUNT == 26'b0000) ? ~ led[M-1] : led[M-1];
    end
    end
    
endmodule

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

@xanderplush,

Your problem is that you are thinking like a software engineer, not a hardware engineer.  In software, instructions get executed in sequence.  For loops work by executing what's in them, updating the loop variable, and then repeating.  That's not how for loops work in hardware.  In hardware, everything gets unrolled.  Your for loop gets executed once per clock cycle.  At best, the synthesis tool will generate the *appearance* of time passing.  In your case, you are using non-blocking assignments.  (These are recommended, so that much is a good choice.)  The problem you will have though is that none of the non-blocking assignments will take effect until the entire loop's processing is complete and all of the LEDs are turned off--except perhaps the MSB.  You will never see the blinking rail as a result.

It's for this reason that I recommend beginner's avoid for loops.  They are just so easily misunderstood.  The don't work the same.  You can read about one of my experiences with them here, where I was forced to use them by the situation I was in, yet got surprised by the hardware they actually generated.

As for the blinking rail design, perhaps I can refer you to my own tutorial.  This sort of design is one of the projects that goes along with the tutorial.

Dan

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...