I am trying to debug my finite state machine in modelsim and I have no idea what's wrong with the code. It would be helpful to see the state/next_state internal signals in the waveform viewer. Is this possible?
Is there anything that is wrong with this code? It compiles but it's not progressing to the next state after starting at Start at the posedge of clk.
module statemachine(resetb, slow_clock, dscore, pscore, pcard3, loadpcard1, loadpcard2, loadpcard3, loaddcard1, loaddcard2, loaddcard3, player_win_light, dealer_win_light);
input logic resetb;
input logic slow_clock;
input logic [3:0] dscore;
input logic [3:0] pscore;
input logic [3:0] pcard3;
output logic loadpcard1, loadpcard2, loadpcard3, loaddcard1,loaddcard2, loaddcard3;
output logic player_win_light, dealer_win_light;
enum reg [2:0] {Start = 3'b000, FirstP = 3'b001, FirstD = 3'b010, SecondP = 3'b011, SecondD = 3'b100, ThirdP = 3'b101, ThirdD = 3'b110, GameOver = 3'b111} state, next_state;
always_comb
begin
case(state)
Start: next_state = FirstP;
FirstP: next_state = FirstD;
FirstD: next_state = SecondP;
SecondP: next_state = SecondD;
SecondD: next_state = pscore == 4'b1000 || pscore == 4'b1001 || dscore == 4'b1000 || dscore == 4'b1001 ? GameOver :
pscore <= 1'd5 ? ThirdP :
dscore <= 3'd5 ? ThirdD : GameOver;
ThirdP: next_state = dscore == 3'd7 ? GameOver :
dscore == 3'd6 && (pcard3 == 3'd6 || pcard3 == 3'd7) ? ThirdD :
dscore == 3'd5 && (pcard3 == 2'd4 || pcard3 == 3'd5 || pcard3 == 3'd6 || pcard3 == 3'd7) ? ThirdD :
dscore == 3'd4 && (pcard3 != 1'd0 && pcard3 != 1'd1 && pcard3 != 3'd8) ? ThirdD :
dscore == 3'd3 && pcard3 != 8 ? ThirdD :
GameOver;
ThirdD: next_state = GameOver;
GameOver: next_state = GameOver;
endcase
end
always_ff @ (posedge slow_clock) begin
if (resetb == 0)
state <= Start;
else
state <= next_state;
end
always_comb
begin
case(state)
Start:
begin
loadpcard1 = 0;
loaddcard1 = 0;
loadpcard2 = 0;
loaddcard2 = 0;
loadpcard3 = 0;
loaddcard3 = 0;
player_win_light = 0;
dealer_win_light = 0;
end
FirstP:
begin
loadpcard1 = 1;
loaddcard1 = 0;
loadpcard2 = 0;
loaddcard2 = 0;
loadpcard3 = 0;
loaddcard3 = 0;
player_win_light = 0;
dealer_win_light = 0;
end
FirstD:
begin loaddcard1 = 1;
loadpcard1 = 0;
loadpcard2 = 0;
loaddcard2 = 0;
loadpcard3 = 0;
loaddcard3 = 0;
player_win_light = 0;
dealer_win_light = 0;
end
SecondP:
begin
loadpcard1 = 0;
loaddcard1 = 0;
loadpcard2 = 1;
loaddcard2 = 0;
loadpcard3 = 0;
loaddcard3 = 0;
player_win_light = 0;
dealer_win_light = 0;
end
SecondD:
begin
loadpcard1 = 0;
loaddcard1 = 0;
loadpcard2 = 0;
loaddcard2 = 1;
loadpcard3 = 0;
loaddcard3 = 0;
player_win_light = 0;
dealer_win_light = 0;
end
ThirdP:
begin
loadpcard1 = 0;
loaddcard1 = 0;
loadpcard2 = 0;
loaddcard2 = 0;
loadpcard3 = 1;
loaddcard3 = 0;
player_win_light = 0;
dealer_win_light = 0;
end
ThirdD:
begin
loadpcard1 = 0;
loaddcard1 = 0;
loadpcard2 = 0;
loaddcard2 = 0;
loadpcard3 = 0;
loaddcard3 = 1;
player_win_light = 0;
dealer_win_light = 0;
end
GameOver:
begin
loadpcard1 = 0;
loaddcard1 = 0;
loadpcard2 = 0;
loaddcard2 = 0;
loaddcard3 = 0;
loaddcard3 = 0;
player_win_light = 0;
dealer_win_light = 0;
player_win_light = (pscore > dscore) ? 1 : ((dscore > pscore) ? 0 : 0);
dealer_win_light = (dscore > pscore) ? 1 : ((pscore > dscore) ? 0 : 0);
end
endcase
end
endmodule