D
Divyang M
Hi,
In two of the states of my state machine I need to transition (or stay
in the same state) depending on internal signals (and not the inputs).
These signals are essentially counters. Is this OK to do and
synthesize?
Or should I make a separate state for each of the counter values?
Below is a skeleton of my state machine to explain what I am saying
above (definitely not final VHDL code but just gives an idea. I am
looking up correct styles of coding state machines with two processes).
The Input / Output ports are as follows
(horiz and vert will be assigned to x and y)
entity my_sm
port(
clk : in std_logic;
newline : in std_logic;
x : out std_logic_vector(7 downto 0);
y : out std_logic_vector(9 downto 0)
);
and the state machine:
signal vert, horiz, mydelay (length as appropriate)
process(clk)
begin
if (clk = '1' and clk'event) then
case next_state is
when RESET =>
mydelay <= 0;
horiz <= 0;
vert <= 0;
next_state <= WAIT_16;
when WAIT_16 =>
if (newline = '1') then
mydelay <= mydelay + 1;
end if;
if mydelay = 16 then
next_state <= PROCESS;
else
next_state <= WAIT_16;
end if;
when PROCESS =>
if (horiz = 640) then
next_state <= WAIT_FOR_NEWLINE
else
horiz <= horiz + 1;
next_state <= PROCESS;
end if;
when WAIT_FOR_NEWLINE =>
if (newline = '1') then
horiz <= 0;
if (vert = 240) then
vert <= 0;
else
vert <= vert + 1;
end if;
next_state <= PROCESS;
else
next_state <= WAIT_FOR_NEWLINE;
end if;
end case
Thanks,
Divyang M
In two of the states of my state machine I need to transition (or stay
in the same state) depending on internal signals (and not the inputs).
These signals are essentially counters. Is this OK to do and
synthesize?
Or should I make a separate state for each of the counter values?
Below is a skeleton of my state machine to explain what I am saying
above (definitely not final VHDL code but just gives an idea. I am
looking up correct styles of coding state machines with two processes).
The Input / Output ports are as follows
(horiz and vert will be assigned to x and y)
entity my_sm
port(
clk : in std_logic;
newline : in std_logic;
x : out std_logic_vector(7 downto 0);
y : out std_logic_vector(9 downto 0)
);
and the state machine:
signal vert, horiz, mydelay (length as appropriate)
process(clk)
begin
if (clk = '1' and clk'event) then
case next_state is
when RESET =>
mydelay <= 0;
horiz <= 0;
vert <= 0;
next_state <= WAIT_16;
when WAIT_16 =>
if (newline = '1') then
mydelay <= mydelay + 1;
end if;
if mydelay = 16 then
next_state <= PROCESS;
else
next_state <= WAIT_16;
end if;
when PROCESS =>
if (horiz = 640) then
next_state <= WAIT_FOR_NEWLINE
else
horiz <= horiz + 1;
next_state <= PROCESS;
end if;
when WAIT_FOR_NEWLINE =>
if (newline = '1') then
horiz <= 0;
if (vert = 240) then
vert <= 0;
else
vert <= vert + 1;
end if;
next_state <= PROCESS;
else
next_state <= WAIT_FOR_NEWLINE;
end if;
end case
Thanks,
Divyang M