Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
13 years ago

Rotating square in seven segment LED

now I want to make a rotating square using the seven segment.. The pattern I want to create looks something like the attached picture.

Im new to verilog so here is the code I came up with... I kind of knew it would not work as it is written in a C style but I thought combinational logic in a separate block would work

reg  ticker; //a 23 bit register to count to 5M, to generate a 0.1 sec tick
wire click;
reg  fourth, third, second, first;
always @ (posedge clock or posedge reset)
begin //this block will generate a 0.1 sec tick
    if(reset)
        ticker <= 0;
    else if(ticker == 5000000)
        ticker <= 0;
    else
        ticker <= ticker + 1;
end
assign click = ((ticker == 5000000)?1'b1:1'b0);
always @ (click) // this will just simple rotate the square
begin 
// I have equaled 1 in the seven segment display to make the top square and 2 to make the lower square
            fourth = 1;
            third = 1;
            second = 1;
            first = 1;
            first = 2;
            second = 2;
            third = 2;
            fourth = 2;
end
//Having 4 seven segment displays being multiplexed first is the right most display and fourth is the left most display
Please note that the multiplexing circuit and the block related to turning on the seven segment is not shown in the main code.. As Im sure the problem is in the above code.

I know this doesnt work, when I put it on the board It just shows the top squares and it does not rotate.

i dont want a fix, or some one to do this.. i just want to know why is this code wrong??

Thank you

4 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Your statement:

    fourth = 1;

    fourth = 2; etc

    does not implement fourth to be 1 then 2. It is compile time settled to fourth = 2 as it updates the sequential statement on same node.

    you need to create logic for that using a flag: 0 to assign 1, 1 to assign 2

    to same signal.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    thanks.. I thought that updating registers at the end of an always block was only with non blocking assignments..

    However I tried putting it in a more controlled format, such as a case like below, but its still not working..

    Should I make it as an FSM?

    The thinking behind this is that the register click count will change its value every 0.1 second, and every 0.1 the value is changed using the case statement.

    However when put on the board only the fourth and second display show the square and its not rotating.. =/

    reg clickcount;
    assign click = ((ticker == 5000000)?1'b1:1'b0);
    always @ (click)
    begin
        if(clickcount == 7)
            clickcount <= 0;
        else 
        clickcount <= clickcount + 1;
    end
    always @(*)
    begin
        case(clickcount)
            
            0: fourth = 4'd1;
            1:    third = 4'd1;
            2:    second = 4'd1;
            3:    first = 4'd1;
            4:    first = 4'd2;
            5:    second = 4'd2;
            6:    third = 4'd2;
            7:    fourth = 4'd2;
        endcase
    end
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    How wide is your register clickcount?

    --- Quote End ---

    haha.. look at that.. silly me. :)

    Thanks for pointing that out