红绿灯的时间计数器不会增加

时间:2018-01-14 22:54:55

标签: vhdl

我正在写简单的交集"模拟器"作业。它是这样的: 用户输入在每条车道上停在交通信号灯处的汽车数量,并定义更换灯的时间。当计时器值等于用户定义的时间时,灯光应该改变颜色。

time_counter中的问题出现,过程看起来像这样

 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;

我不知道为什么,但计时器没有正确递增。它保持在&#34; 000000&#34;的值。有人能告诉我为什么它不能正常工作吗?

为了更加清晰,我还将展示各州的变化情况

    begin
next_state<= state;
case state is
when state_1 =>
    if time_counter < state_1_time_value then
            traffic_signal_1 <= "10"; --green
            traffic_signal_2 <= "00"; -- red
            traffic_signal_3 <= "00";   
            traffic_signal_4 <= "10";
            traffic_signal_5 <= "00";
            traffic_signal_6 <= "00";


            elsif time_counter = state_1_time_value then

                    next_state<=state_2;
            end if;

1 个答案:

答案 0 :(得分:1)

您应该将大 if -statement与 case -statement交换为state,并将计数器条件实现为 if 选择时每个中的> -statement。

time_counter = state_1_time_value之类的条件永远不会成立,因为信号会在流程结束时更新。您位于time_counter < state_1_time_value为真的分支中,因此time_counter = state_1_time_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;

顺便说一下,您应该更喜欢设计中的同步重置。