Vhdl 交通灯的时间计数器不会增加

Vhdl 交通灯的时间计数器不会增加,vhdl,Vhdl,我正在为作业编写简单的交叉口“模拟器”。事情是这样的: 用户输入在每条车道的交通灯处停车的车辆数量,并定义换灯时间。当计时器值等于用户定义的时间时,灯光应更改其颜色 时间计数器出现问题,进程如下所示 time_counter_process: process (reset, clk) begin if reset = '1' then time_counter<= "0000000"; elsif clk'event and clk='1' then if (s

我正在为作业编写简单的交叉口“模拟器”。事情是这样的: 用户输入在每条车道的交通灯处停车的车辆数量,并定义换灯时间。当计时器值等于用户定义的时间时,灯光应更改其颜色

时间计数器出现问题,进程如下所示

 time_counter_process: process (reset, clk)
begin
if reset = '1' then
    time_counter<=  "0000000";
elsif clk'event and clk='1' then
        if (state = state_1 and time_counter < state_1_time_value) then
            -- in state_1 one some lights are green and others red, simple
            time_counter <= time_counter + 1;

                if (state = state_1 and time_counter = state_1_time_value) then
                    time_counter <= "0000000";
                end if;

        etc...

        elsif state = state_6 and time_counter < state_6_time_value then

            time_counter <= time_counter + 1;

                if state = state_6 and time_counter = state_6_time_value then
                    time_counter <= "0000000";
                end if;


    end if;
end if;
end process time_counter_process;
time\u counter\u进程:进程(复位,时钟)
开始
如果重置='1',则

time_counter您应该将big if语句与case语句交换为
state
,并在每个when选项中将计数器条件实现为if语句

time\u counter=state\u 1\u time\u value
这样的条件永远不会为真,因为信号在进程结束时更新。您所在的分支中,
time\u counter
为真,因此
time\u counter=state\u 1\u time\u value
也不能为真

time_counter_process: process (reset, clk)
begin
  if (reset = '1') then
    time_counter<=  "0000000";
  elsif rising_edge(clk) then
    case state is
      when state_1 =>
        if (time_counter < state_1_time_value) then
          -- in state_1 one some lights are green and others red, simple
          time_counter <= time_counter + 1;
        else
          time_counter <= "0000000";
        end if;

-- etc...

    when state_6 =>
      if (time_counter < state_6_time_value) then
        time_counter <= time_counter + 1;
      else
        time_counter <= "0000000";
      end if;

    end case;
  end if;
end process time_counter_process;
time\u counter\u进程:进程(复位,时钟)
开始
如果(重置='1'),则
时间计数器
如果(时间计数器<状态1时间值),则
--在状态1中,一些灯是绿色的,另一些灯是红色的,很简单

时间计数器请使用适当的缩进,以便我们阅读和理解您的代码。您应该将big if语句与case语句交换为
state
,并在每个when选项中将计数器条件实现为if语句。像
time\u counter=state\u 1\u time\u value
这样的条件永远不会为真,因为信号在进程结束时更新。您所处的分支中,
time\u counter
为true,因此
time\u counter=state\u 1\u time\u value
也不能为true。如果将上述case语句与when选项一起使用,则可以将
如果(state=state\u 1和time\u counter=state\u 1\u time\u value)重写为
else
-分支。
time_counter_process: process (reset, clk)
begin
  if (reset = '1') then
    time_counter<=  "0000000";
  elsif rising_edge(clk) then
    case state is
      when state_1 =>
        if (time_counter < state_1_time_value) then
          -- in state_1 one some lights are green and others red, simple
          time_counter <= time_counter + 1;
        else
          time_counter <= "0000000";
        end if;

-- etc...

    when state_6 =>
      if (time_counter < state_6_time_value) then
        time_counter <= time_counter + 1;
      else
        time_counter <= "0000000";
      end if;

    end case;
  end if;
end process time_counter_process;