Moore fsm VHDL Testbench
up vote
0
down vote
favorite
Hello i got this FSM.
I wrote the VHDL code :
library ieee;
use ieee.std_logic_1164.all;
entity fsm is
port(
clk, reset : in std_logic;
level : in std_logic;
Moore_tick: out std_logic
);
end fsm;
architecture rtl of fsm is
type stateFsm_type is (s1, s2, s3); -- 3 states are required
signal stateFsm_reg, stateFsm_next : stateFsm_type;
begin
process(clk, reset)
begin
if (reset = '1') then -- go to state zero if reset
stateFsm_reg <= s1;
elsif (clk'event and clk = '1') then -- otherwise update the states
stateFsm_reg <= stateFsm_next;
else
null;
end if;
end process;
process(stateFsm_reg, level)
begin
-- store current state as next
stateFsm_next <= stateFsm_reg; -- required: when no case statement is satisfied
Moore_tick <= '0'; -- set tick to zero (so that 'tick = 1' is available for 1 cycle only)
case stateFsm_reg is
when s1 => -- if state is zero,
if level = '1' then -- and level is 1
stateFsm_next <= s2; -- then go to state edge.
end if;
when s2 =>
Moore_tick <= '1'; -- set the tick to 1.
if level = '1' then -- if level is 1,
stateFsm_next <= s3; --go to state one,
else
stateFsm_next <= s1; -- else go to state zero.
end if;
when s3 =>
if level = '0' then -- if level is 0,
stateFsm_next <= s1; -- then go to state zero.
end if;
end case;
end process;
end rtl;
So i compiled the code without errors. Currently i am trying to create a testbench so to be able to get the visuals so to be sure that it is workign correctly.
This is the code that i wrote for the testbench.
[![library ieee;
use ieee.std_logic_1164.all;
entity fsm_tb is
end fsm_tb;
architecture fsm_arch_tb of fsm_tb is
component fsm is
port(
clk, reset : in std_logic;
level : in std_logic;
Moore_tick: out std_logic
);
end component;
signal clk: std_logic :='1';
signal reset: std_logic :='0';
signal level: std_logic :='0';
signal Moore_tick: std_logic ;
type stateFsm_type is (s1, s2 , s3 ); -- 3 states are required
signal stateFsm_reg, stateFsm_next : stateFsm_type ;
constant clk_period : time := 1 ns;
begin
cnt_inst : fsm
port map (
clk, reset, level, Moore_tick
);
clk_gen: process is
begin
clk <= '1';
wait for clk_period/2; --for 5 ns signal is '0'.
clk <= '0';
wait for clk_period/2; --for next 5 ns signal is '1'.
end process clk_gen;
trig: process is
begin
wait for clk_period;
level<= '1';
wait for clk_period;
reset <= '0' ;
level <= '1' ;
wait for clk_period;
level <= '1' ;
wait for clk_period;
level <= '1' ;
wait for clk_period;
reset <= '1' ;
wait for clk_period;
reset <= '0' ;
level <= '1' ;
wait for clk_period;
level <= '1' ;
wait for clk_period;
level <= '1' ;
wait for clk_period;
level <= '1' ;
wait;
end process trig;
end architecture fsm_arch_tb;
But i am stuck on the last process.
I am trying to implement the trig process
so to be able to see all the transitions on waveforms
vhdl fsm
add a comment |
up vote
0
down vote
favorite
Hello i got this FSM.
I wrote the VHDL code :
library ieee;
use ieee.std_logic_1164.all;
entity fsm is
port(
clk, reset : in std_logic;
level : in std_logic;
Moore_tick: out std_logic
);
end fsm;
architecture rtl of fsm is
type stateFsm_type is (s1, s2, s3); -- 3 states are required
signal stateFsm_reg, stateFsm_next : stateFsm_type;
begin
process(clk, reset)
begin
if (reset = '1') then -- go to state zero if reset
stateFsm_reg <= s1;
elsif (clk'event and clk = '1') then -- otherwise update the states
stateFsm_reg <= stateFsm_next;
else
null;
end if;
end process;
process(stateFsm_reg, level)
begin
-- store current state as next
stateFsm_next <= stateFsm_reg; -- required: when no case statement is satisfied
Moore_tick <= '0'; -- set tick to zero (so that 'tick = 1' is available for 1 cycle only)
case stateFsm_reg is
when s1 => -- if state is zero,
if level = '1' then -- and level is 1
stateFsm_next <= s2; -- then go to state edge.
end if;
when s2 =>
Moore_tick <= '1'; -- set the tick to 1.
if level = '1' then -- if level is 1,
stateFsm_next <= s3; --go to state one,
else
stateFsm_next <= s1; -- else go to state zero.
end if;
when s3 =>
if level = '0' then -- if level is 0,
stateFsm_next <= s1; -- then go to state zero.
end if;
end case;
end process;
end rtl;
So i compiled the code without errors. Currently i am trying to create a testbench so to be able to get the visuals so to be sure that it is workign correctly.
This is the code that i wrote for the testbench.
[![library ieee;
use ieee.std_logic_1164.all;
entity fsm_tb is
end fsm_tb;
architecture fsm_arch_tb of fsm_tb is
component fsm is
port(
clk, reset : in std_logic;
level : in std_logic;
Moore_tick: out std_logic
);
end component;
signal clk: std_logic :='1';
signal reset: std_logic :='0';
signal level: std_logic :='0';
signal Moore_tick: std_logic ;
type stateFsm_type is (s1, s2 , s3 ); -- 3 states are required
signal stateFsm_reg, stateFsm_next : stateFsm_type ;
constant clk_period : time := 1 ns;
begin
cnt_inst : fsm
port map (
clk, reset, level, Moore_tick
);
clk_gen: process is
begin
clk <= '1';
wait for clk_period/2; --for 5 ns signal is '0'.
clk <= '0';
wait for clk_period/2; --for next 5 ns signal is '1'.
end process clk_gen;
trig: process is
begin
wait for clk_period;
level<= '1';
wait for clk_period;
reset <= '0' ;
level <= '1' ;
wait for clk_period;
level <= '1' ;
wait for clk_period;
level <= '1' ;
wait for clk_period;
reset <= '1' ;
wait for clk_period;
reset <= '0' ;
level <= '1' ;
wait for clk_period;
level <= '1' ;
wait for clk_period;
level <= '1' ;
wait for clk_period;
level <= '1' ;
wait;
end process trig;
end architecture fsm_arch_tb;
But i am stuck on the last process.
I am trying to implement the trig process
so to be able to see all the transitions on waveforms
vhdl fsm
So far you don't appear to be asking a question and are simply stating you are stuck. What's got you stuck? Note that Moore_tick is an output from fsm and assigning it in the testbench creates a second driver where the value of the signal will the resolution of the two drivers.
– user1155120
2 days ago
Testing all the branches in your state machine can be done by manipulating reset and level and not driving Moore_tick.
– user1155120
2 days ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Hello i got this FSM.
I wrote the VHDL code :
library ieee;
use ieee.std_logic_1164.all;
entity fsm is
port(
clk, reset : in std_logic;
level : in std_logic;
Moore_tick: out std_logic
);
end fsm;
architecture rtl of fsm is
type stateFsm_type is (s1, s2, s3); -- 3 states are required
signal stateFsm_reg, stateFsm_next : stateFsm_type;
begin
process(clk, reset)
begin
if (reset = '1') then -- go to state zero if reset
stateFsm_reg <= s1;
elsif (clk'event and clk = '1') then -- otherwise update the states
stateFsm_reg <= stateFsm_next;
else
null;
end if;
end process;
process(stateFsm_reg, level)
begin
-- store current state as next
stateFsm_next <= stateFsm_reg; -- required: when no case statement is satisfied
Moore_tick <= '0'; -- set tick to zero (so that 'tick = 1' is available for 1 cycle only)
case stateFsm_reg is
when s1 => -- if state is zero,
if level = '1' then -- and level is 1
stateFsm_next <= s2; -- then go to state edge.
end if;
when s2 =>
Moore_tick <= '1'; -- set the tick to 1.
if level = '1' then -- if level is 1,
stateFsm_next <= s3; --go to state one,
else
stateFsm_next <= s1; -- else go to state zero.
end if;
when s3 =>
if level = '0' then -- if level is 0,
stateFsm_next <= s1; -- then go to state zero.
end if;
end case;
end process;
end rtl;
So i compiled the code without errors. Currently i am trying to create a testbench so to be able to get the visuals so to be sure that it is workign correctly.
This is the code that i wrote for the testbench.
[![library ieee;
use ieee.std_logic_1164.all;
entity fsm_tb is
end fsm_tb;
architecture fsm_arch_tb of fsm_tb is
component fsm is
port(
clk, reset : in std_logic;
level : in std_logic;
Moore_tick: out std_logic
);
end component;
signal clk: std_logic :='1';
signal reset: std_logic :='0';
signal level: std_logic :='0';
signal Moore_tick: std_logic ;
type stateFsm_type is (s1, s2 , s3 ); -- 3 states are required
signal stateFsm_reg, stateFsm_next : stateFsm_type ;
constant clk_period : time := 1 ns;
begin
cnt_inst : fsm
port map (
clk, reset, level, Moore_tick
);
clk_gen: process is
begin
clk <= '1';
wait for clk_period/2; --for 5 ns signal is '0'.
clk <= '0';
wait for clk_period/2; --for next 5 ns signal is '1'.
end process clk_gen;
trig: process is
begin
wait for clk_period;
level<= '1';
wait for clk_period;
reset <= '0' ;
level <= '1' ;
wait for clk_period;
level <= '1' ;
wait for clk_period;
level <= '1' ;
wait for clk_period;
reset <= '1' ;
wait for clk_period;
reset <= '0' ;
level <= '1' ;
wait for clk_period;
level <= '1' ;
wait for clk_period;
level <= '1' ;
wait for clk_period;
level <= '1' ;
wait;
end process trig;
end architecture fsm_arch_tb;
But i am stuck on the last process.
I am trying to implement the trig process
so to be able to see all the transitions on waveforms
vhdl fsm
Hello i got this FSM.
I wrote the VHDL code :
library ieee;
use ieee.std_logic_1164.all;
entity fsm is
port(
clk, reset : in std_logic;
level : in std_logic;
Moore_tick: out std_logic
);
end fsm;
architecture rtl of fsm is
type stateFsm_type is (s1, s2, s3); -- 3 states are required
signal stateFsm_reg, stateFsm_next : stateFsm_type;
begin
process(clk, reset)
begin
if (reset = '1') then -- go to state zero if reset
stateFsm_reg <= s1;
elsif (clk'event and clk = '1') then -- otherwise update the states
stateFsm_reg <= stateFsm_next;
else
null;
end if;
end process;
process(stateFsm_reg, level)
begin
-- store current state as next
stateFsm_next <= stateFsm_reg; -- required: when no case statement is satisfied
Moore_tick <= '0'; -- set tick to zero (so that 'tick = 1' is available for 1 cycle only)
case stateFsm_reg is
when s1 => -- if state is zero,
if level = '1' then -- and level is 1
stateFsm_next <= s2; -- then go to state edge.
end if;
when s2 =>
Moore_tick <= '1'; -- set the tick to 1.
if level = '1' then -- if level is 1,
stateFsm_next <= s3; --go to state one,
else
stateFsm_next <= s1; -- else go to state zero.
end if;
when s3 =>
if level = '0' then -- if level is 0,
stateFsm_next <= s1; -- then go to state zero.
end if;
end case;
end process;
end rtl;
So i compiled the code without errors. Currently i am trying to create a testbench so to be able to get the visuals so to be sure that it is workign correctly.
This is the code that i wrote for the testbench.
[![library ieee;
use ieee.std_logic_1164.all;
entity fsm_tb is
end fsm_tb;
architecture fsm_arch_tb of fsm_tb is
component fsm is
port(
clk, reset : in std_logic;
level : in std_logic;
Moore_tick: out std_logic
);
end component;
signal clk: std_logic :='1';
signal reset: std_logic :='0';
signal level: std_logic :='0';
signal Moore_tick: std_logic ;
type stateFsm_type is (s1, s2 , s3 ); -- 3 states are required
signal stateFsm_reg, stateFsm_next : stateFsm_type ;
constant clk_period : time := 1 ns;
begin
cnt_inst : fsm
port map (
clk, reset, level, Moore_tick
);
clk_gen: process is
begin
clk <= '1';
wait for clk_period/2; --for 5 ns signal is '0'.
clk <= '0';
wait for clk_period/2; --for next 5 ns signal is '1'.
end process clk_gen;
trig: process is
begin
wait for clk_period;
level<= '1';
wait for clk_period;
reset <= '0' ;
level <= '1' ;
wait for clk_period;
level <= '1' ;
wait for clk_period;
level <= '1' ;
wait for clk_period;
reset <= '1' ;
wait for clk_period;
reset <= '0' ;
level <= '1' ;
wait for clk_period;
level <= '1' ;
wait for clk_period;
level <= '1' ;
wait for clk_period;
level <= '1' ;
wait;
end process trig;
end architecture fsm_arch_tb;
But i am stuck on the last process.
I am trying to implement the trig process
so to be able to see all the transitions on waveforms
vhdl fsm
vhdl fsm
edited 11 hours ago
asked 2 days ago
Ioan Kats
439
439
So far you don't appear to be asking a question and are simply stating you are stuck. What's got you stuck? Note that Moore_tick is an output from fsm and assigning it in the testbench creates a second driver where the value of the signal will the resolution of the two drivers.
– user1155120
2 days ago
Testing all the branches in your state machine can be done by manipulating reset and level and not driving Moore_tick.
– user1155120
2 days ago
add a comment |
So far you don't appear to be asking a question and are simply stating you are stuck. What's got you stuck? Note that Moore_tick is an output from fsm and assigning it in the testbench creates a second driver where the value of the signal will the resolution of the two drivers.
– user1155120
2 days ago
Testing all the branches in your state machine can be done by manipulating reset and level and not driving Moore_tick.
– user1155120
2 days ago
So far you don't appear to be asking a question and are simply stating you are stuck. What's got you stuck? Note that Moore_tick is an output from fsm and assigning it in the testbench creates a second driver where the value of the signal will the resolution of the two drivers.
– user1155120
2 days ago
So far you don't appear to be asking a question and are simply stating you are stuck. What's got you stuck? Note that Moore_tick is an output from fsm and assigning it in the testbench creates a second driver where the value of the signal will the resolution of the two drivers.
– user1155120
2 days ago
Testing all the branches in your state machine can be done by manipulating reset and level and not driving Moore_tick.
– user1155120
2 days ago
Testing all the branches in your state machine can be done by manipulating reset and level and not driving Moore_tick.
– user1155120
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
In the test bench, you are trying to assign a value to the signal type out
Remove these:
Moore_tick <= '0';
Moore_tick <= '1';
Hello i made the changes that you sugggested. and i get these waveforms. Why i dont get output values for thestateFsm_reg
and thestateFsm_next
thought?
– Ioan Kats
yesterday
In yout testbench, you have declared the signalsstateFsm_reg
andstateFsm_next
as std_logic, instead they should be of your declared type stateFsm_type (as in your rtl code)
– Sai Varun
18 hours ago
Hello again i changed the signals i addedtype stateFsm_type is (s1, s2 , s3 )
signal stateFsm_reg, stateFsm_next : stateFsm_type ;
i get outputs1
but it does not change. All the time iss1
– Ioan Kats
11 hours ago
changed code and/or relevant figures might be more helpful to provide answers
– Sai Varun
11 hours ago
i updated the testbench and the waveforms!
– Ioan Kats
11 hours ago
|
show 3 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
In the test bench, you are trying to assign a value to the signal type out
Remove these:
Moore_tick <= '0';
Moore_tick <= '1';
Hello i made the changes that you sugggested. and i get these waveforms. Why i dont get output values for thestateFsm_reg
and thestateFsm_next
thought?
– Ioan Kats
yesterday
In yout testbench, you have declared the signalsstateFsm_reg
andstateFsm_next
as std_logic, instead they should be of your declared type stateFsm_type (as in your rtl code)
– Sai Varun
18 hours ago
Hello again i changed the signals i addedtype stateFsm_type is (s1, s2 , s3 )
signal stateFsm_reg, stateFsm_next : stateFsm_type ;
i get outputs1
but it does not change. All the time iss1
– Ioan Kats
11 hours ago
changed code and/or relevant figures might be more helpful to provide answers
– Sai Varun
11 hours ago
i updated the testbench and the waveforms!
– Ioan Kats
11 hours ago
|
show 3 more comments
up vote
0
down vote
accepted
In the test bench, you are trying to assign a value to the signal type out
Remove these:
Moore_tick <= '0';
Moore_tick <= '1';
Hello i made the changes that you sugggested. and i get these waveforms. Why i dont get output values for thestateFsm_reg
and thestateFsm_next
thought?
– Ioan Kats
yesterday
In yout testbench, you have declared the signalsstateFsm_reg
andstateFsm_next
as std_logic, instead they should be of your declared type stateFsm_type (as in your rtl code)
– Sai Varun
18 hours ago
Hello again i changed the signals i addedtype stateFsm_type is (s1, s2 , s3 )
signal stateFsm_reg, stateFsm_next : stateFsm_type ;
i get outputs1
but it does not change. All the time iss1
– Ioan Kats
11 hours ago
changed code and/or relevant figures might be more helpful to provide answers
– Sai Varun
11 hours ago
i updated the testbench and the waveforms!
– Ioan Kats
11 hours ago
|
show 3 more comments
up vote
0
down vote
accepted
up vote
0
down vote
accepted
In the test bench, you are trying to assign a value to the signal type out
Remove these:
Moore_tick <= '0';
Moore_tick <= '1';
In the test bench, you are trying to assign a value to the signal type out
Remove these:
Moore_tick <= '0';
Moore_tick <= '1';
edited 2 days ago
answered 2 days ago
Sai Varun
464
464
Hello i made the changes that you sugggested. and i get these waveforms. Why i dont get output values for thestateFsm_reg
and thestateFsm_next
thought?
– Ioan Kats
yesterday
In yout testbench, you have declared the signalsstateFsm_reg
andstateFsm_next
as std_logic, instead they should be of your declared type stateFsm_type (as in your rtl code)
– Sai Varun
18 hours ago
Hello again i changed the signals i addedtype stateFsm_type is (s1, s2 , s3 )
signal stateFsm_reg, stateFsm_next : stateFsm_type ;
i get outputs1
but it does not change. All the time iss1
– Ioan Kats
11 hours ago
changed code and/or relevant figures might be more helpful to provide answers
– Sai Varun
11 hours ago
i updated the testbench and the waveforms!
– Ioan Kats
11 hours ago
|
show 3 more comments
Hello i made the changes that you sugggested. and i get these waveforms. Why i dont get output values for thestateFsm_reg
and thestateFsm_next
thought?
– Ioan Kats
yesterday
In yout testbench, you have declared the signalsstateFsm_reg
andstateFsm_next
as std_logic, instead they should be of your declared type stateFsm_type (as in your rtl code)
– Sai Varun
18 hours ago
Hello again i changed the signals i addedtype stateFsm_type is (s1, s2 , s3 )
signal stateFsm_reg, stateFsm_next : stateFsm_type ;
i get outputs1
but it does not change. All the time iss1
– Ioan Kats
11 hours ago
changed code and/or relevant figures might be more helpful to provide answers
– Sai Varun
11 hours ago
i updated the testbench and the waveforms!
– Ioan Kats
11 hours ago
Hello i made the changes that you sugggested. and i get these waveforms. Why i dont get output values for the
stateFsm_reg
and the stateFsm_next
thought?– Ioan Kats
yesterday
Hello i made the changes that you sugggested. and i get these waveforms. Why i dont get output values for the
stateFsm_reg
and the stateFsm_next
thought?– Ioan Kats
yesterday
In yout testbench, you have declared the signals
stateFsm_reg
and stateFsm_next
as std_logic, instead they should be of your declared type stateFsm_type (as in your rtl code)– Sai Varun
18 hours ago
In yout testbench, you have declared the signals
stateFsm_reg
and stateFsm_next
as std_logic, instead they should be of your declared type stateFsm_type (as in your rtl code)– Sai Varun
18 hours ago
Hello again i changed the signals i added
type stateFsm_type is (s1, s2 , s3 )
signal stateFsm_reg, stateFsm_next : stateFsm_type ;
i get output s1
but it does not change. All the time is s1
– Ioan Kats
11 hours ago
Hello again i changed the signals i added
type stateFsm_type is (s1, s2 , s3 )
signal stateFsm_reg, stateFsm_next : stateFsm_type ;
i get output s1
but it does not change. All the time is s1
– Ioan Kats
11 hours ago
changed code and/or relevant figures might be more helpful to provide answers
– Sai Varun
11 hours ago
changed code and/or relevant figures might be more helpful to provide answers
– Sai Varun
11 hours ago
i updated the testbench and the waveforms!
– Ioan Kats
11 hours ago
i updated the testbench and the waveforms!
– Ioan Kats
11 hours ago
|
show 3 more comments
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53402732%2fmoore-fsm-vhdl-testbench%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
So far you don't appear to be asking a question and are simply stating you are stuck. What's got you stuck? Note that Moore_tick is an output from fsm and assigning it in the testbench creates a second driver where the value of the signal will the resolution of the two drivers.
– user1155120
2 days ago
Testing all the branches in your state machine can be done by manipulating reset and level and not driving Moore_tick.
– user1155120
2 days ago