我必须在7段LED上显示消息和定时器。因此,我通过使用多路复用器并在一个状态下显示消息“Hi”,然后在计数器达到7500的一段时间后,它应该停止显示“Hi”并开始显示计时器。
问题是它只显示“嗨”并且不会从那里向前移动。
localparam [1:0]
idle = 2'b00,
starting = 2'b01,
time_it = 2'b10,
done = 2'b11;
reg state_reg, state_next;
reg [12:0] count_reg, count_next; //**change for simulation
always @ (posedge clock or posedge reset)
begin
if(reset)
begin
state_reg <= idle;
count_reg <= 0;
end
else
begin
state_reg <= state_next;
count_reg <= count_next;
end
end
always @ (*)
begin
state_next = state_reg; //default state stays the same
count_next = count_reg;
case(state_reg)
idle:
begin
//DISPLAY HI HERE
sel = 2'b00;
if(start)
begin
count_next = random; //get the random number from LFSR module
state_next = starting;
end
end
starting:
begin
if(count_next == 7500)
begin //and starting from 'rand' ensures a random delay
outled = 1'b1; //turn on the led
state_next = time_it; //go to next state
end
else
count_next = count_reg + 1;
end
time_it:
begin
sel = 2'b01; //start the timer
state_next = done;
end
done:
begin
if(stop)
begin
sel = 2'b10; //stop the timer
outled = 1'b0;
end
end
endcase
case(sel)
2'b00: //hi
begin
go_start = 0; //make sure timer module is off
regd0 = 4'd12;
regd1 = 4'd10;
regd2 = 4'd11;
regd3 = 4'd12;
end
2'b01: //timer
begin
go_start = 1'b1; //enable start signal to start timer
regd0 = reg_d0; //get values from stopwatch module
regd1 = reg_d1; //get values from stopwatch module
regd2 = reg_d2; //get values from stopwatch module
regd3 = reg_d3; //get values from stopwatch module
end
2'b10: //stop timer
begin
go_start = 1'b0;
end
default:
begin
regd0 = 4'bx;
regd1 = 4'bx;
regd2 = 4'bx;
regd3 = 4'bx;
end
endcase
end
现在在模拟中,case
保持在00并且即使在time_it
状态下被告知这样做也不会改变。由于sel
未更改go_start
未启用,因此定时器永远不会启用。为什么会留在sel=00
?
答案 0 :(得分:4)
将您的状态regs从1更改为2位宽:
reg [1:0] state_reg, state_next;
答案 1 :(得分:0)
你能算出reg“start”的定义吗?如果它保持为0,则可以确定当前状态永远不会变为“开始”状态。