Em vừa viết code VHDL để mô tả FSM Counter đếm từ 0 đến 9. Lúc compilation trong quartus II thì nó báo lỗi mà sửa mãi ko đc. Nhờ các bác xem giúp em tí.
Code
library Ieee;
use Ieee.std_logic_1164.all;
entity ten_counter is
port (
w: in std_logic_vector(0 to 1);
Clk: in std_logic;
Reset: in std_logic;
Z: out std_logic_vector(0 to 3)
);
end ten_counter;
Architecture Behave of ten_counter is
type Counter_States is(S0,S1,S2,S3,S4,S5,S6,S7,S8,S9);
signal CurrentState,NextState: Counter_States;
Begin
OutputAndNextStateLogic:
process (w,CurrentState) is
begin
Case CurrentState is
When S0 =>
Z <= "0000";
case w is
when "00" => NextState <= S0;
when "01" => NextState <= S1;
when "10" => NextState <= S2;
when "11" => NextState <= S9;
end case;
When S1 =>
Z<="0001";
case w is
when "00" => NextState <= S1;
when "01" => NextState <= S2;
when "10" => NextState <= S3;
when "11" => NextState <= S0;
end case;
When S2 =>
Z<="0010";
case w is
when "00" => NextState <= S2;
when "01" => NextState <= S3;
when "10" => NextState <= S4;
when "11" => NextState <= S1;
end case;
When S3 =>
Z<="0011";
case w is
when "00" => NextState <= S3;
when "01" => NextState <= S4;
when "10" => NextState <= S5;
when "11" => NextState <= S2;
end case;
When S4 =>
Z<="0100";
case w is
when "00" => NextState <= S4;
when "01" => NextState <= S5;
when "10" => NextState <= S6;
when "11" => NextState <= S3;
end case;
When S5 =>
Z<="0101";
case w is
when "00" => NextState <= S5;
when "01" => NextState <= S6;
when "10" => NextState <= S7;
when "11" => NextState <= S4;
end case;
When S6 =>
Z<="0110";
case w is
when "00" => NextState <= S6;
when "01" => NextState <= S7;
when "10" => NextState <= S8;
when "11" => NextState <= S5;
end case;
When S7 =>
Z<="0111";
case w is
when "00" => NextState <= S7;
when "01" => NextState <= S8;
when "10" => NextState <= S9;
when "11" => NextState <= S6;
end case;
When S8 =>
Z<="1000";
case w is
when "00" => NextState <= S8;
when "01" => NextState <= S9;
when "10" => NextState <= S0;
when "11" => NextState <= S7;
end case;
When S9 =>
Z<="1001";
case w is
when "00" => NextState <= S9;
when "01" => NextState <= S0;
when "10" => NextState <= S1;
when "11" => NextState <= S8;
end case;
end case;
end process;
State_Register:
process (Clk,Reset,NextState)
begin
if (Reset='1') then
NextState <= S0;
elsif (Clk'event AND Clk='1') then
CurrentState <= NextState;
end if;
end process;
End Behave;
Lúc compilation thì nó báo lỗi:
Error (10028): Can't resolve multiple constant drivers for net "NextState.S0" at ten_Counter.vhd(105)
Error (10029): Constant driver at ten_Counter.vhd(19)
Error (10028): Can't resolve multiple constant drivers for net "NextState.S1" at ten_Counter.vhd(105)
Error (10028): Can't resolve multiple constant drivers for net "NextState.S2" at ten_Counter.vhd(105)
Error (10028): Can't resolve multiple constant drivers for net "NextState.S3" at ten_Counter.vhd(105)
Error (10028): Can't resolve multiple constant drivers for net "NextState.S4" at ten_Counter.vhd(105)
Error (10028): Can't resolve multiple constant drivers for net "NextState.S5" at ten_Counter.vhd(105)
Error (10028): Can't resolve multiple constant drivers for net "NextState.S6" at ten_Counter.vhd(105)
Error (10028): Can't resolve multiple constant drivers for net "NextState.S7" at ten_Counter.vhd(105)
Error (10028): Can't resolve multiple constant drivers for net "NextState.S8" at ten_Counter.vhd(105)
Error (10028): Can't resolve multiple constant drivers for net "NextState.S9" at ten_Counter.vhd(105)
Error: Can't elaborate top-level user hierarchy
Em mới học lập trình nên code luộm thuộm. Các bác chịu khó giúp em nhé. Em cảm ơn nhiều!
Code
library Ieee;
use Ieee.std_logic_1164.all;
entity ten_counter is
port (
w: in std_logic_vector(0 to 1);
Clk: in std_logic;
Reset: in std_logic;
Z: out std_logic_vector(0 to 3)
);
end ten_counter;
Architecture Behave of ten_counter is
type Counter_States is(S0,S1,S2,S3,S4,S5,S6,S7,S8,S9);
signal CurrentState,NextState: Counter_States;
Begin
OutputAndNextStateLogic:
process (w,CurrentState) is
begin
Case CurrentState is
When S0 =>
Z <= "0000";
case w is
when "00" => NextState <= S0;
when "01" => NextState <= S1;
when "10" => NextState <= S2;
when "11" => NextState <= S9;
end case;
When S1 =>
Z<="0001";
case w is
when "00" => NextState <= S1;
when "01" => NextState <= S2;
when "10" => NextState <= S3;
when "11" => NextState <= S0;
end case;
When S2 =>
Z<="0010";
case w is
when "00" => NextState <= S2;
when "01" => NextState <= S3;
when "10" => NextState <= S4;
when "11" => NextState <= S1;
end case;
When S3 =>
Z<="0011";
case w is
when "00" => NextState <= S3;
when "01" => NextState <= S4;
when "10" => NextState <= S5;
when "11" => NextState <= S2;
end case;
When S4 =>
Z<="0100";
case w is
when "00" => NextState <= S4;
when "01" => NextState <= S5;
when "10" => NextState <= S6;
when "11" => NextState <= S3;
end case;
When S5 =>
Z<="0101";
case w is
when "00" => NextState <= S5;
when "01" => NextState <= S6;
when "10" => NextState <= S7;
when "11" => NextState <= S4;
end case;
When S6 =>
Z<="0110";
case w is
when "00" => NextState <= S6;
when "01" => NextState <= S7;
when "10" => NextState <= S8;
when "11" => NextState <= S5;
end case;
When S7 =>
Z<="0111";
case w is
when "00" => NextState <= S7;
when "01" => NextState <= S8;
when "10" => NextState <= S9;
when "11" => NextState <= S6;
end case;
When S8 =>
Z<="1000";
case w is
when "00" => NextState <= S8;
when "01" => NextState <= S9;
when "10" => NextState <= S0;
when "11" => NextState <= S7;
end case;
When S9 =>
Z<="1001";
case w is
when "00" => NextState <= S9;
when "01" => NextState <= S0;
when "10" => NextState <= S1;
when "11" => NextState <= S8;
end case;
end case;
end process;
State_Register:
process (Clk,Reset,NextState)
begin
if (Reset='1') then
NextState <= S0;
elsif (Clk'event AND Clk='1') then
CurrentState <= NextState;
end if;
end process;
End Behave;
Lúc compilation thì nó báo lỗi:
Error (10028): Can't resolve multiple constant drivers for net "NextState.S0" at ten_Counter.vhd(105)
Error (10029): Constant driver at ten_Counter.vhd(19)
Error (10028): Can't resolve multiple constant drivers for net "NextState.S1" at ten_Counter.vhd(105)
Error (10028): Can't resolve multiple constant drivers for net "NextState.S2" at ten_Counter.vhd(105)
Error (10028): Can't resolve multiple constant drivers for net "NextState.S3" at ten_Counter.vhd(105)
Error (10028): Can't resolve multiple constant drivers for net "NextState.S4" at ten_Counter.vhd(105)
Error (10028): Can't resolve multiple constant drivers for net "NextState.S5" at ten_Counter.vhd(105)
Error (10028): Can't resolve multiple constant drivers for net "NextState.S6" at ten_Counter.vhd(105)
Error (10028): Can't resolve multiple constant drivers for net "NextState.S7" at ten_Counter.vhd(105)
Error (10028): Can't resolve multiple constant drivers for net "NextState.S8" at ten_Counter.vhd(105)
Error (10028): Can't resolve multiple constant drivers for net "NextState.S9" at ten_Counter.vhd(105)
Error: Can't elaborate top-level user hierarchy
Em mới học lập trình nên code luộm thuộm. Các bác chịu khó giúp em nhé. Em cảm ơn nhiều!
Comment