不工作,我討厭問又另一個問題就在這裏,但顯然我與模擬真沒用:(VHDL狀態轉換 - 適用於主板,但在模擬器
基本上,我有一個紅綠燈控制器,它由許多不同的狀態和幾個定時器組成,它們運行不同的時間長度,當系統進入一個狀態時,它激活一個定時器,並且有一條if語句來監視定時器的輸出和當計時器輸出值爲1時,將系統指向下一個狀態。
這一切都可以在主板上正常工作,但是當我模擬它時,計數會打勾爲'1',但是t他未選擇下一個狀態。由此可以看出,在這裏:
我試圖歸結代碼到下面的要領,但如果你需要更多的內容(和感覺更加大方,比我應得的),那麼全代碼是here。
初始化:
entity trafficlightcontroller is
port
(
clk : in std_logic;
reset : in std_logic;
ambulance : in std_logic;
smr : in std_logic;
sml : in std_logic;
ssr : in std_logic;
rlmr : out std_logic;
almr : out std_logic;
glmr : out std_logic;
rlsr : out std_logic;
alsr : out std_logic;
glsr : out std_logic
);
end entity;
architecture rtl of trafficlightcontroller is
-- Build an enumerated type for the state machine
-- r=red;a=amber;g=green;c=car waiting;m=main road;s=side road
type state_type is (rmgs, rmas, rmrs, amrs, gmrs, gmrcs, ramrs, rmacs, rmrcs, ramrcs, rmras, rmrs2);
-- Signals to hold the states
signal present_state, next_state : state_type;
signal divclk, reset2, reset2b, reset3, reset3b, reset10, reset20, reset20b, count2, count2b, count3, count3b, count10, count20, count20b: std_logic;
component timer is
generic (
trigger_cnt: natural := 20
);
port (
clk: in std_logic;
reset: in std_logic;
count: buffer std_logic
);
end component timer;
component clockdivider
port(clkin : in std_logic;
dividedclk : out std_logic
);
end component clockdivider;
begin
timer2 : timer generic map (trigger_cnt => 2) port map(divclk,reset2,count2);
timer2b : timer generic map (trigger_cnt => 2) port map(divclk,reset2b,count2b);
timer3 : timer generic map (trigger_cnt => 3) port map(divclk,reset3,count3);
timer3b : timer generic map (trigger_cnt => 3) port map(divclk,reset3b,count3b);
timer10 : timer generic map (trigger_cnt => 10) port map(divclk,reset10,count10);
timer20 : timer generic map (trigger_cnt => 20) port map(divclk,reset20,count20);
timer20b : timer generic map (trigger_cnt => 20) port map(divclk,reset20b,count20b);
divider : clockdivider port map(clk, divclk);
狀態(包括在仿真中所示的狀態)的開始:
case present_state is
--Red light main; green side road
when rmgs=>
reset2 <= '0';
reset2b <= '0';
reset3 <= '0';
reset3b <= '0';
reset20 <= '0';
reset20b <= '0';
rlmr <= '1';
almr <= '0';
glmr <= '0';
rlsr <= '0';
alsr <= '0';
glsr <= '1';
reset10 <= '1';
--if count is complete then move to next state
if (count10='1') THEN
next_state <= rmas;
--otherwise, return to current state
else
next_state <= rmgs;
end if;
時鐘過程:
--Every clock tick, the next state is selected as the present state.
state_clocked: process(clk)
begin
if (rising_edge(clk)) THEN
present_state <= next_state;
end if;
end process state_clocked;
我輸入到線模擬器初始化時鐘:
force clk 0 0ns, 1 10 ns -repeat 20ns
不應該present_state作爲在present_state寄存器中重置的目標嗎? (你顯示next_state,它在兩個不同的進程中創建兩個驅動程序。) – user1155120
@DavidKoontz。謝謝。我已經更新了代碼。如果您願意,歡迎您自行編輯。 –