W
Wouter
Guest
Hi list,
For education purposes I am building a state machine. I made the state
tables, simplification with karnaugh maps, state table for the output
y and created the following VHDL code:
--
library IEEE;
use IEEE.std_logic_1164.all;
entity d_ff is
port (d, clk, reset : in std_logic; q : out std_logic);
end d_ff;
architecture gedrag_dff of d_ff is
begin
ff_behavior : process is
begin
wait until (clk'event and clk='1');
if (reset = '1') then
q <= '0';
else
q <= d;
end if;
end process;
end gedrag_dff;
--
-----------------------------------------------------
ENTITY systeem IS
port ( x, clk, reset : in std_logic;
y: out std_logic_vector(2 downto 0)
);
END systeem;
-----------------------------------------------------
ARCHITECTURE fsm OF systeem IS
-- Transition functions
--
-- d2 = Q1'.Q0'.X'Q2 + Q1.Q0'.X'.Q2'
-- d1 = Q1.Q0.X'.Q2' + Q1'.X.Q2'
-- d0 = Q1'.Q0'.X'.Q2 + Q0.X.Q2' + Q1.X.Q2' + Q1.Q0.Q2'
--
-- Output functions
--
-- y2 = Q2'.Q0
-- y1 = Q2.Q1'.Q0' + Q2'.Q1'.Q0 + Q2'.Q1.Q0'
-- y0 = Q2'.Q1.Q0 + Q2.Q1'.Q0'
SIGNAL d2, d1, d0 : std_logic;
SIGNAL q2, q1, q0 : std_logic;
BEGIN
-- next state selection
d2 <= (NOT q1 AND NOT q0 AND x AND NOT q2) OR (q1 AND NOT q0 AND NOT
x AND NOT q2);
d1 <= (q1 AND q0 AND NOT x AND NOT q2) OR (NOT q1 AND x AND NOT q2);
d0 <= (NOT q1 AND NOT q0 AND NOT x AND q2) OR (q0 AND x AND NOT q2)
OR (q1 AND x AND NOT q2) OR (q1 AND q0 AND NOT q2);
DFF2: ENTITY WORK.d_ff PORT MAP (d2, clk, reset, q2);
DFF1: ENTITY WORK.d_ff PORT MAP (d1, clk, reset, q1);
DFF0: ENTITY WORK.d_ff PORT MAP (d0, clk, reset, q0);
-- result of the output functions
y(2) <= NOT q2 AND q0;
y(1) <= (q2 AND (NOT q1) AND (NOT q0)) OR ((NOT q2) AND (NOT q1) AND
q0) OR ( (NOT q2) AND q1 AND (NOT q0) );
y(0) <= (NOT q2 AND q1 AND q0) OR (q2 AND NOT q1 AND NOT q0);
END fsm;
I have tested the functions manually in the simulator of Modelsim.
This is cumbersome as you can imagine, so i tried creating the
following test bench:
--
entity systeem_tb is
end systeem_tb;
architecture TB of systeem_tb is
component systeem
port ( x, clk, reset : in std_logic;
y: out std_logic_vector(2 downto 0)
);
end component;
signal x: std_logic := '0';
signal clk: std_logic := '0';
signal reset: std_logic := '1';
signal y: std_logic_vector(2 downto 0);
begin
uut: systeem port map(x => x, clk => clk, reset => reset, y => y);
clk_proc : process
begin
clk <= '0';
wait for 5 ns;
clk <= '1';
wait for 5 ns;
end process;
stim_proc : process
begin
-- simulation step 1:
reset <= '0' AFTER 11 ns;
x <= '1' AFTER 16 ns;
x <= '0' AFTER 26 ns;
wait;
end process;
end;
--
The problem is: signal x never goes to one. It always stays zero. I
have tried all kind of things, such as changing the waiting times, not
assigning default values, et cetera. I am pretty certain my logic in
the state machine is correct
(checked manually). I am obviously doing something wrong, but I am in
the dark. I don't know where to go from here. Could you give me some
pointers? Thank you,
Wouter
For education purposes I am building a state machine. I made the state
tables, simplification with karnaugh maps, state table for the output
y and created the following VHDL code:
--
library IEEE;
use IEEE.std_logic_1164.all;
entity d_ff is
port (d, clk, reset : in std_logic; q : out std_logic);
end d_ff;
architecture gedrag_dff of d_ff is
begin
ff_behavior : process is
begin
wait until (clk'event and clk='1');
if (reset = '1') then
q <= '0';
else
q <= d;
end if;
end process;
end gedrag_dff;
--
-----------------------------------------------------
ENTITY systeem IS
port ( x, clk, reset : in std_logic;
y: out std_logic_vector(2 downto 0)
);
END systeem;
-----------------------------------------------------
ARCHITECTURE fsm OF systeem IS
-- Transition functions
--
-- d2 = Q1'.Q0'.X'Q2 + Q1.Q0'.X'.Q2'
-- d1 = Q1.Q0.X'.Q2' + Q1'.X.Q2'
-- d0 = Q1'.Q0'.X'.Q2 + Q0.X.Q2' + Q1.X.Q2' + Q1.Q0.Q2'
--
-- Output functions
--
-- y2 = Q2'.Q0
-- y1 = Q2.Q1'.Q0' + Q2'.Q1'.Q0 + Q2'.Q1.Q0'
-- y0 = Q2'.Q1.Q0 + Q2.Q1'.Q0'
SIGNAL d2, d1, d0 : std_logic;
SIGNAL q2, q1, q0 : std_logic;
BEGIN
-- next state selection
d2 <= (NOT q1 AND NOT q0 AND x AND NOT q2) OR (q1 AND NOT q0 AND NOT
x AND NOT q2);
d1 <= (q1 AND q0 AND NOT x AND NOT q2) OR (NOT q1 AND x AND NOT q2);
d0 <= (NOT q1 AND NOT q0 AND NOT x AND q2) OR (q0 AND x AND NOT q2)
OR (q1 AND x AND NOT q2) OR (q1 AND q0 AND NOT q2);
DFF2: ENTITY WORK.d_ff PORT MAP (d2, clk, reset, q2);
DFF1: ENTITY WORK.d_ff PORT MAP (d1, clk, reset, q1);
DFF0: ENTITY WORK.d_ff PORT MAP (d0, clk, reset, q0);
-- result of the output functions
y(2) <= NOT q2 AND q0;
y(1) <= (q2 AND (NOT q1) AND (NOT q0)) OR ((NOT q2) AND (NOT q1) AND
q0) OR ( (NOT q2) AND q1 AND (NOT q0) );
y(0) <= (NOT q2 AND q1 AND q0) OR (q2 AND NOT q1 AND NOT q0);
END fsm;
I have tested the functions manually in the simulator of Modelsim.
This is cumbersome as you can imagine, so i tried creating the
following test bench:
--
entity systeem_tb is
end systeem_tb;
architecture TB of systeem_tb is
component systeem
port ( x, clk, reset : in std_logic;
y: out std_logic_vector(2 downto 0)
);
end component;
signal x: std_logic := '0';
signal clk: std_logic := '0';
signal reset: std_logic := '1';
signal y: std_logic_vector(2 downto 0);
begin
uut: systeem port map(x => x, clk => clk, reset => reset, y => y);
clk_proc : process
begin
clk <= '0';
wait for 5 ns;
clk <= '1';
wait for 5 ns;
end process;
stim_proc : process
begin
-- simulation step 1:
reset <= '0' AFTER 11 ns;
x <= '1' AFTER 16 ns;
x <= '0' AFTER 26 ns;
wait;
end process;
end;
--
The problem is: signal x never goes to one. It always stays zero. I
have tried all kind of things, such as changing the waiting times, not
assigning default values, et cetera. I am pretty certain my logic in
the state machine is correct
(checked manually). I am obviously doing something wrong, but I am in
the dark. I don't know where to go from here. Could you give me some
pointers? Thank you,
Wouter