state machine coding

M

mysticlol

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
 
M

Mike Treseler

mysticlol said:
Is this way of state machine coding is correct?
or is there a better way ?

This style question has many answers
and it has no answer.
Here are 50 recent postings on the subject:
http://tinyurl.com/hsrc7
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.

In that case, I have nothing to add.

-- Mike Treseler
 
A

Andy

mysticlol said:
Is this way of state machine coding is correct? ....
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

My opinion is that using variables in a single, clocked process is a
better, more efficient way to code state machines and their outputs.

Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top