Gigaxalus
Gigaxalus

Reputation: 107

Defining Two Things per Case Statement

I am using a case statement to determine what seven seg LED digit is to turn on. I am also trying to use the same case statement to determine which actual number to show on that digit. My broken code:

always @(*)
begin
    case(sel_state)

        2'b00: selector = 3'b000; //1st digit
               BCD = BCD1;
               
        2'b01: selector = 3'b100; //2nd digit
        2'b01: BCD = BCD2;
        2'b10: selector = 3'b110;  //3rd digit
        2'b10: BCD = BCD3;
        2'b11: selector = 3'b001;  //4th digit
        2'b11: BCD = BCD4;
        
        
        default: selector = 3'b000;
    endcase
end

As you can see, I was messing around with different syntax, but it doesn't seem to like anything I've tried. If I modeled the first case like the other 3, the case switches between selectors but doesn't change what BCD equals. If I switch the order, BCD changes but selector doesn't. Does anyone know a proper way to do this?

Upvotes: 1

Views: 4251

Answers (2)

paxdiablo
paxdiablo

Reputation: 882806

Looks like the only thing you haven't tried is using a block statement, which is exactly the thing you need:

case(sel_state)
    2'b00: begin
        selector = 3'b000;
        BCD = BCD1;
    end
    2'b01: begin
        selector = 3'b100;
        BCD = BCD2;
    end
    : :
endcase

Upvotes: 6

Greg
Greg

Reputation: 19132

Use begin-end

always @* begin
  case(sel_state)
    2'b00: begin //1st digit
      selector = 3'b000;
      BCD = BCD1;
    end
    2'b01: begin //2nd digit
      selector = 3'b100; 
      BCD = BCD2;
    end
    // ... others ...
  endcase
end

Upvotes: 3

Related Questions