Moore fsm VHDL Testbench











up vote
0
down vote

favorite












Hello i got this FSM.



enter image description here



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



enter image description here










share|improve this question
























  • 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















up vote
0
down vote

favorite












Hello i got this FSM.



enter image description here



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



enter image description here










share|improve this question
























  • 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













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Hello i got this FSM.



enter image description here



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



enter image description here










share|improve this question















Hello i got this FSM.



enter image description here



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



enter image description here







vhdl fsm






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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












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';






share|improve this answer























  • 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












  • 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










  • i updated the testbench and the waveforms!
    – Ioan Kats
    11 hours ago











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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

























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';






share|improve this answer























  • 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












  • 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










  • i updated the testbench and the waveforms!
    – Ioan Kats
    11 hours ago















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';






share|improve this answer























  • 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












  • 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










  • i updated the testbench and the waveforms!
    – Ioan Kats
    11 hours ago













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';






share|improve this answer














In the test bench, you are trying to assign a value to the signal type out



Remove these:



Moore_tick <= '0';



Moore_tick <= '1';







share|improve this answer














share|improve this answer



share|improve this answer








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 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












  • 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










  • 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












  • 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












  • 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


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Berounka

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...

Sphinx de Gizeh