start from a specific stat in the FSM












0















I have a specific FSM that works just fine. but I want to start from a specific state in the FSM, I was wondering if I can do it using an event that only happens once in the circuit but I can't do it because all the events I think of keeps the circuit in the same state



library ieee;
use ieee.std_logic_1164.all;
use work.all;

entity ELEVAR is
port(
clk, rst: in std_logic;
NF,status : in std_logic_vector(2 downto 0);
output: out std_logic_vector(2 downto 0));
end ELEVAR;

architecture struct of ELEVAR is
type state is(S,S0,S1,S2,S3,S4,S5,S6,S7,S8,HI);
signal current_state, next_state:state;
signal output22 : std_logic_vector(2 downto 0);

begin
process(clk, rst)
begin
if(rst='1')then
current_state<=S0;

elsif(rising_edge(clk))then


else
null;
end if;

end process;




process(current_state)

begin

case current_state is

when S8=>next_state<=S7;
output<="111";

output22<="111";
if (NF=output22) then
next_state<=HI;
output<="111";
end if;

when S7=>next_state<=S6;
output<="110";

output22<="110";
if (NF=output22) then
next_state<=HI;
output<="110";
end if;
when S6=>next_state<=S5;
output<="101";

output22<="101";
if (NF=output22) then
next_state<=HI;
output<="101";

end if;
when S5=>next_state<=S4;
output<="100";

output22<="100";
if (NF=output22) then
next_state<=HI;
output<="100";
end if;
when S4=>next_state<=S3;
output<="011";

output22<="011";
if (NF=output22) then
next_state<=HI;
output<="011";
end if;
when S3=>next_state<=S2;
output<="010";

output22<="010";
if (NF=output22) then
next_state<=HI;
output<="010";
end if;
when S2=>next_state<=S1;
output<="001";

output22<="001";
if (NF=output22) then
next_state<=HI;
output<="001";
end if;
when S1=>next_state<=S0;
output<="000";

output22<="000";
if (NF=output22) then
next_state<=HI;
output<="000";
end if;

when others => next_state<=HI;
null;


end case;
end process;

end struct;


-- this code selects the state I want to start from but I don't know
--- where should I place it in my code.



   current_state<=next_state;
elsif status = "000" then
current_state<=S0;
elsif
status = "001" then
current_state<=S1;
elsif
status = "010" then
current_state<=S2;
elsif
status = "011" then
current_state<=S3;
elsif
status = "100" then
current_state<=S4;
elsif
status = "101" then
current_state<=S5;
elsif
status = "110" then
current_state<=S6;
elsif
status = "111" then
current_state<=S7;









share|improve this question


















  • 2





    horrible formatting, I'm not fixing that. Just assign a different state during reset if (rst = '1') then current_state <= <state of your choice>; else ...

    – damage
    Jan 1 at 14:12













  • @damage that does not fix my problem !!, how do u think this will make it start from a specific state !!

    – islam toukhy
    Jan 1 at 15:39






  • 1





    You should use got code formatting (e.g. indentation) if you want a quick and good solutions from the SO community. No one will spend minutes in understanding your code if it's not well prepared. At next, you should read about state machine pattern.

    – Paebbels
    Jan 1 at 22:15
















0















I have a specific FSM that works just fine. but I want to start from a specific state in the FSM, I was wondering if I can do it using an event that only happens once in the circuit but I can't do it because all the events I think of keeps the circuit in the same state



library ieee;
use ieee.std_logic_1164.all;
use work.all;

entity ELEVAR is
port(
clk, rst: in std_logic;
NF,status : in std_logic_vector(2 downto 0);
output: out std_logic_vector(2 downto 0));
end ELEVAR;

architecture struct of ELEVAR is
type state is(S,S0,S1,S2,S3,S4,S5,S6,S7,S8,HI);
signal current_state, next_state:state;
signal output22 : std_logic_vector(2 downto 0);

begin
process(clk, rst)
begin
if(rst='1')then
current_state<=S0;

elsif(rising_edge(clk))then


else
null;
end if;

end process;




process(current_state)

begin

case current_state is

when S8=>next_state<=S7;
output<="111";

output22<="111";
if (NF=output22) then
next_state<=HI;
output<="111";
end if;

when S7=>next_state<=S6;
output<="110";

output22<="110";
if (NF=output22) then
next_state<=HI;
output<="110";
end if;
when S6=>next_state<=S5;
output<="101";

output22<="101";
if (NF=output22) then
next_state<=HI;
output<="101";

end if;
when S5=>next_state<=S4;
output<="100";

output22<="100";
if (NF=output22) then
next_state<=HI;
output<="100";
end if;
when S4=>next_state<=S3;
output<="011";

output22<="011";
if (NF=output22) then
next_state<=HI;
output<="011";
end if;
when S3=>next_state<=S2;
output<="010";

output22<="010";
if (NF=output22) then
next_state<=HI;
output<="010";
end if;
when S2=>next_state<=S1;
output<="001";

output22<="001";
if (NF=output22) then
next_state<=HI;
output<="001";
end if;
when S1=>next_state<=S0;
output<="000";

output22<="000";
if (NF=output22) then
next_state<=HI;
output<="000";
end if;

when others => next_state<=HI;
null;


end case;
end process;

end struct;


-- this code selects the state I want to start from but I don't know
--- where should I place it in my code.



   current_state<=next_state;
elsif status = "000" then
current_state<=S0;
elsif
status = "001" then
current_state<=S1;
elsif
status = "010" then
current_state<=S2;
elsif
status = "011" then
current_state<=S3;
elsif
status = "100" then
current_state<=S4;
elsif
status = "101" then
current_state<=S5;
elsif
status = "110" then
current_state<=S6;
elsif
status = "111" then
current_state<=S7;









share|improve this question


















  • 2





    horrible formatting, I'm not fixing that. Just assign a different state during reset if (rst = '1') then current_state <= <state of your choice>; else ...

    – damage
    Jan 1 at 14:12













  • @damage that does not fix my problem !!, how do u think this will make it start from a specific state !!

    – islam toukhy
    Jan 1 at 15:39






  • 1





    You should use got code formatting (e.g. indentation) if you want a quick and good solutions from the SO community. No one will spend minutes in understanding your code if it's not well prepared. At next, you should read about state machine pattern.

    – Paebbels
    Jan 1 at 22:15














0












0








0








I have a specific FSM that works just fine. but I want to start from a specific state in the FSM, I was wondering if I can do it using an event that only happens once in the circuit but I can't do it because all the events I think of keeps the circuit in the same state



library ieee;
use ieee.std_logic_1164.all;
use work.all;

entity ELEVAR is
port(
clk, rst: in std_logic;
NF,status : in std_logic_vector(2 downto 0);
output: out std_logic_vector(2 downto 0));
end ELEVAR;

architecture struct of ELEVAR is
type state is(S,S0,S1,S2,S3,S4,S5,S6,S7,S8,HI);
signal current_state, next_state:state;
signal output22 : std_logic_vector(2 downto 0);

begin
process(clk, rst)
begin
if(rst='1')then
current_state<=S0;

elsif(rising_edge(clk))then


else
null;
end if;

end process;




process(current_state)

begin

case current_state is

when S8=>next_state<=S7;
output<="111";

output22<="111";
if (NF=output22) then
next_state<=HI;
output<="111";
end if;

when S7=>next_state<=S6;
output<="110";

output22<="110";
if (NF=output22) then
next_state<=HI;
output<="110";
end if;
when S6=>next_state<=S5;
output<="101";

output22<="101";
if (NF=output22) then
next_state<=HI;
output<="101";

end if;
when S5=>next_state<=S4;
output<="100";

output22<="100";
if (NF=output22) then
next_state<=HI;
output<="100";
end if;
when S4=>next_state<=S3;
output<="011";

output22<="011";
if (NF=output22) then
next_state<=HI;
output<="011";
end if;
when S3=>next_state<=S2;
output<="010";

output22<="010";
if (NF=output22) then
next_state<=HI;
output<="010";
end if;
when S2=>next_state<=S1;
output<="001";

output22<="001";
if (NF=output22) then
next_state<=HI;
output<="001";
end if;
when S1=>next_state<=S0;
output<="000";

output22<="000";
if (NF=output22) then
next_state<=HI;
output<="000";
end if;

when others => next_state<=HI;
null;


end case;
end process;

end struct;


-- this code selects the state I want to start from but I don't know
--- where should I place it in my code.



   current_state<=next_state;
elsif status = "000" then
current_state<=S0;
elsif
status = "001" then
current_state<=S1;
elsif
status = "010" then
current_state<=S2;
elsif
status = "011" then
current_state<=S3;
elsif
status = "100" then
current_state<=S4;
elsif
status = "101" then
current_state<=S5;
elsif
status = "110" then
current_state<=S6;
elsif
status = "111" then
current_state<=S7;









share|improve this question














I have a specific FSM that works just fine. but I want to start from a specific state in the FSM, I was wondering if I can do it using an event that only happens once in the circuit but I can't do it because all the events I think of keeps the circuit in the same state



library ieee;
use ieee.std_logic_1164.all;
use work.all;

entity ELEVAR is
port(
clk, rst: in std_logic;
NF,status : in std_logic_vector(2 downto 0);
output: out std_logic_vector(2 downto 0));
end ELEVAR;

architecture struct of ELEVAR is
type state is(S,S0,S1,S2,S3,S4,S5,S6,S7,S8,HI);
signal current_state, next_state:state;
signal output22 : std_logic_vector(2 downto 0);

begin
process(clk, rst)
begin
if(rst='1')then
current_state<=S0;

elsif(rising_edge(clk))then


else
null;
end if;

end process;




process(current_state)

begin

case current_state is

when S8=>next_state<=S7;
output<="111";

output22<="111";
if (NF=output22) then
next_state<=HI;
output<="111";
end if;

when S7=>next_state<=S6;
output<="110";

output22<="110";
if (NF=output22) then
next_state<=HI;
output<="110";
end if;
when S6=>next_state<=S5;
output<="101";

output22<="101";
if (NF=output22) then
next_state<=HI;
output<="101";

end if;
when S5=>next_state<=S4;
output<="100";

output22<="100";
if (NF=output22) then
next_state<=HI;
output<="100";
end if;
when S4=>next_state<=S3;
output<="011";

output22<="011";
if (NF=output22) then
next_state<=HI;
output<="011";
end if;
when S3=>next_state<=S2;
output<="010";

output22<="010";
if (NF=output22) then
next_state<=HI;
output<="010";
end if;
when S2=>next_state<=S1;
output<="001";

output22<="001";
if (NF=output22) then
next_state<=HI;
output<="001";
end if;
when S1=>next_state<=S0;
output<="000";

output22<="000";
if (NF=output22) then
next_state<=HI;
output<="000";
end if;

when others => next_state<=HI;
null;


end case;
end process;

end struct;


-- this code selects the state I want to start from but I don't know
--- where should I place it in my code.



   current_state<=next_state;
elsif status = "000" then
current_state<=S0;
elsif
status = "001" then
current_state<=S1;
elsif
status = "010" then
current_state<=S2;
elsif
status = "011" then
current_state<=S3;
elsif
status = "100" then
current_state<=S4;
elsif
status = "101" then
current_state<=S5;
elsif
status = "110" then
current_state<=S6;
elsif
status = "111" then
current_state<=S7;






vhdl state modelsim fsm quartus






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 31 '18 at 18:36









islam toukhyislam toukhy

81




81








  • 2





    horrible formatting, I'm not fixing that. Just assign a different state during reset if (rst = '1') then current_state <= <state of your choice>; else ...

    – damage
    Jan 1 at 14:12













  • @damage that does not fix my problem !!, how do u think this will make it start from a specific state !!

    – islam toukhy
    Jan 1 at 15:39






  • 1





    You should use got code formatting (e.g. indentation) if you want a quick and good solutions from the SO community. No one will spend minutes in understanding your code if it's not well prepared. At next, you should read about state machine pattern.

    – Paebbels
    Jan 1 at 22:15














  • 2





    horrible formatting, I'm not fixing that. Just assign a different state during reset if (rst = '1') then current_state <= <state of your choice>; else ...

    – damage
    Jan 1 at 14:12













  • @damage that does not fix my problem !!, how do u think this will make it start from a specific state !!

    – islam toukhy
    Jan 1 at 15:39






  • 1





    You should use got code formatting (e.g. indentation) if you want a quick and good solutions from the SO community. No one will spend minutes in understanding your code if it's not well prepared. At next, you should read about state machine pattern.

    – Paebbels
    Jan 1 at 22:15








2




2





horrible formatting, I'm not fixing that. Just assign a different state during reset if (rst = '1') then current_state <= <state of your choice>; else ...

– damage
Jan 1 at 14:12







horrible formatting, I'm not fixing that. Just assign a different state during reset if (rst = '1') then current_state <= <state of your choice>; else ...

– damage
Jan 1 at 14:12















@damage that does not fix my problem !!, how do u think this will make it start from a specific state !!

– islam toukhy
Jan 1 at 15:39





@damage that does not fix my problem !!, how do u think this will make it start from a specific state !!

– islam toukhy
Jan 1 at 15:39




1




1





You should use got code formatting (e.g. indentation) if you want a quick and good solutions from the SO community. No one will spend minutes in understanding your code if it's not well prepared. At next, you should read about state machine pattern.

– Paebbels
Jan 1 at 22:15





You should use got code formatting (e.g. indentation) if you want a quick and good solutions from the SO community. No one will spend minutes in understanding your code if it's not well prepared. At next, you should read about state machine pattern.

– Paebbels
Jan 1 at 22:15












1 Answer
1






active

oldest

votes


















0














Signals get initialized by default with the left-most value of the range of that signal's subtype, if no initial value is provided. In your case the type is State and it's left-most value is S. Thus your initial state is S.



You can assign an initial value to while declaring the signal:



signal current_state : State := S4;
signal next_state : State;


Now, the initial value is S4 and the start state is also S4.



Please note, an FSM can have different start and reset states. (Not saying it's always clever.) It depends on the underlying technology (FPGA, Xilinx, Altera, ASIC, ...) if the reset state can differ from initial state.





Other hints:




  • Do not enumerate identifiers like S1, S2!

    Use proper state names.

  • If you need to check status for multiple different values, use a case statement, but no if/elsif decision-tree.

  • You process' sensitivity list is incomplete.

  • Don't use asynchronous resets.






share|improve this answer























    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',
    autoActivateHeartbeat: false,
    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%2f53990461%2fstart-from-a-specific-stat-in-the-fsm%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









    0














    Signals get initialized by default with the left-most value of the range of that signal's subtype, if no initial value is provided. In your case the type is State and it's left-most value is S. Thus your initial state is S.



    You can assign an initial value to while declaring the signal:



    signal current_state : State := S4;
    signal next_state : State;


    Now, the initial value is S4 and the start state is also S4.



    Please note, an FSM can have different start and reset states. (Not saying it's always clever.) It depends on the underlying technology (FPGA, Xilinx, Altera, ASIC, ...) if the reset state can differ from initial state.





    Other hints:




    • Do not enumerate identifiers like S1, S2!

      Use proper state names.

    • If you need to check status for multiple different values, use a case statement, but no if/elsif decision-tree.

    • You process' sensitivity list is incomplete.

    • Don't use asynchronous resets.






    share|improve this answer




























      0














      Signals get initialized by default with the left-most value of the range of that signal's subtype, if no initial value is provided. In your case the type is State and it's left-most value is S. Thus your initial state is S.



      You can assign an initial value to while declaring the signal:



      signal current_state : State := S4;
      signal next_state : State;


      Now, the initial value is S4 and the start state is also S4.



      Please note, an FSM can have different start and reset states. (Not saying it's always clever.) It depends on the underlying technology (FPGA, Xilinx, Altera, ASIC, ...) if the reset state can differ from initial state.





      Other hints:




      • Do not enumerate identifiers like S1, S2!

        Use proper state names.

      • If you need to check status for multiple different values, use a case statement, but no if/elsif decision-tree.

      • You process' sensitivity list is incomplete.

      • Don't use asynchronous resets.






      share|improve this answer


























        0












        0








        0







        Signals get initialized by default with the left-most value of the range of that signal's subtype, if no initial value is provided. In your case the type is State and it's left-most value is S. Thus your initial state is S.



        You can assign an initial value to while declaring the signal:



        signal current_state : State := S4;
        signal next_state : State;


        Now, the initial value is S4 and the start state is also S4.



        Please note, an FSM can have different start and reset states. (Not saying it's always clever.) It depends on the underlying technology (FPGA, Xilinx, Altera, ASIC, ...) if the reset state can differ from initial state.





        Other hints:




        • Do not enumerate identifiers like S1, S2!

          Use proper state names.

        • If you need to check status for multiple different values, use a case statement, but no if/elsif decision-tree.

        • You process' sensitivity list is incomplete.

        • Don't use asynchronous resets.






        share|improve this answer













        Signals get initialized by default with the left-most value of the range of that signal's subtype, if no initial value is provided. In your case the type is State and it's left-most value is S. Thus your initial state is S.



        You can assign an initial value to while declaring the signal:



        signal current_state : State := S4;
        signal next_state : State;


        Now, the initial value is S4 and the start state is also S4.



        Please note, an FSM can have different start and reset states. (Not saying it's always clever.) It depends on the underlying technology (FPGA, Xilinx, Altera, ASIC, ...) if the reset state can differ from initial state.





        Other hints:




        • Do not enumerate identifiers like S1, S2!

          Use proper state names.

        • If you need to check status for multiple different values, use a case statement, but no if/elsif decision-tree.

        • You process' sensitivity list is incomplete.

        • Don't use asynchronous resets.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 1 at 22:25









        PaebbelsPaebbels

        7,43983577




        7,43983577
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53990461%2fstart-from-a-specific-stat-in-the-fsm%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

            Mossoró

            Error while reading .h5 file using the rhdf5 package in R

            Pushsharp Apns notification error: 'InvalidToken'