M
mysticlol
Guest
Is this way of state machine coding is correct?
process(reset, clk100)
Begin
if reset='1' then
present_state <= idle;
elsif rising_edge(clk100) then
present_state <= next_state;
end if;
end process;
process(reset, clk100)
begin
if reset='1' then
clk_cnt <= (others => '0')
elsif rising_edge(clk100) then
clk_cnt <= clk_cnt + '1';
end if;
end process;
process(present_state, clk_cnt)
begin
case present_state is
when idle => next_state <= present_state;
when shiftout => if conv_integer(clk_cnt) <= 15 then next_state <=
shiftin; else next_state <= shiftout; end if;
when shiftin => if conv_integer(clk_cnt) <= 31 then next_state <=
shiftin; else next_state <= idle; end if;
when others => next_state <= idle;
end case;
end process;
process(reset, clk100)
begin
if reset='1' then
Idle_out <= '0'; shiftout_out <= '0'; shiftin_out <= '0';
elsif rising_edge(clk100) then
case present_state is
when idle => Idle_out <= '1; shiftout_out <= '0'; shiftin_out
<= '0';
when shiftout => Idle_out <= '0'; shiftout_out <= '1;
shiftin_out <= '0'; data(31 downto 0) <= sig_out & data(31 downto
1);
when shiftin => Idle_out <= '0'; shiftout_out <= '0';
shiftin_out <= '1; data(31 downto 0) <= data(30 downto 0) & sig_in;
when others => Idle_out <= '1; shiftout_out <= '0'; shiftin_out
<= '0';
end case;
end if;
end process;
or is there a better way ? I dont want to use variables in my state
machine coding.
I feel using variables in RTL coding is an inefficient way of coding -
testbenches are exemption.
Please suggest.
Regards,
Krishna
process(reset, clk100)
Begin
if reset='1' then
present_state <= idle;
elsif rising_edge(clk100) then
present_state <= next_state;
end if;
end process;
process(reset, clk100)
begin
if reset='1' then
clk_cnt <= (others => '0')
elsif rising_edge(clk100) then
clk_cnt <= clk_cnt + '1';
end if;
end process;
process(present_state, clk_cnt)
begin
case present_state is
when idle => next_state <= present_state;
when shiftout => if conv_integer(clk_cnt) <= 15 then next_state <=
shiftin; else next_state <= shiftout; end if;
when shiftin => if conv_integer(clk_cnt) <= 31 then next_state <=
shiftin; else next_state <= idle; end if;
when others => next_state <= idle;
end case;
end process;
process(reset, clk100)
begin
if reset='1' then
Idle_out <= '0'; shiftout_out <= '0'; shiftin_out <= '0';
elsif rising_edge(clk100) then
case present_state is
when idle => Idle_out <= '1; shiftout_out <= '0'; shiftin_out
<= '0';
when shiftout => Idle_out <= '0'; shiftout_out <= '1;
shiftin_out <= '0'; data(31 downto 0) <= sig_out & data(31 downto
1);
when shiftin => Idle_out <= '0'; shiftout_out <= '0';
shiftin_out <= '1; data(31 downto 0) <= data(30 downto 0) & sig_in;
when others => Idle_out <= '1; shiftout_out <= '0'; shiftin_out
<= '0';
end case;
end if;
end process;
or is there a better way ? I dont want to use variables in my state
machine coding.
I feel using variables in RTL coding is an inefficient way of coding -
testbenches are exemption.
Please suggest.
Regards,
Krishna