1

I have a design module (a partially implemented seven segment display) with a case statement as shown below. However, it looks as if, if a case statement is not catered for a bcd value the previously assigned segment value is returned as the segment value for the bcd value which is not catered for in the switch statement.

Why is it behaving that way? Assuming I don't want to use a default statement.

I printed out the values of the bcd, segment and the expectedOutput and I observed what I just wrote above.

module seven_segment_display(output logic[6:0] segment, input logic[3:0] bcd);
    always@(*)
        begin
            case (bcd)
                4'b0011 : begin segment = 7'b1011011; end
                4'b1000 : begin segment = 7'b1111011; end
                4'b1010 : begin segment = 7'b0000000; end
                4'b0000 : begin segment = 7'b1111110; end
            endcase
        end
endmodule
bcd  segment expectedOutput
0000 1111110 1111110
0001 1111110 0110000
0010 1111110 1101101
0011 1011011 1111001
0100 1011011 0110011
0101 1011011 1011011
0110 1011011 1011111
0111 1011011 1110000
1000 1111011 1111111
1001 1111011 1111011
1010 0000000 0000000
1011 0000000 0000000
1100 0000000 0000000
1101 0000000 0000000
1110 0000000 0000000
1111 0000000 0000000
0

1 Answer 1

1

segment is a variable. Like in any other (software) language, variables remember their value until you overwrite their value with some other value.

Your first input (bcd) is 4'b0000. There is a branch of the case statement that matches that value and so the value of 7'b1111110 is assigned to the variable segment. Then you change the value of bcd to 4'b0001. There is no branch that matches that value, so no new value is assigned to the variable segment. So, it retains it's old value.

Sign up to request clarification or add additional context in comments.

3 Comments

I can't understand what else you'd expect to happen. The expected value corresponding to an input of 4'b0001 is not assigned anywhere (because there is no branch of the case statement that corresponds to 4'b0001). I can't understand, therefore, why you would expect that value to be assigned to segment.
I get it now, I mistakenly assumed an unknown value should be assigned.
@user2987773 add a default condition to your case statement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.