M
Markus Hagen
Guest
Hello!
I'm about to describe a big state machine in Verilog. Most of the
states (let's call them "opcodes") need more than one clock cycle to
finish. So each of theese states do have a number of 'sub-states' on
it's own (let's call them "ticks").
To accomplish this i've come up with two design ideas:
1) The state is a concatenation of {opcode,tick} and leads to one big
FSM with many states with some of them undefined.
case {opcode,tick}
{add,0}: ... next <= {add,1}
{add,1}: ... next <= {add,2}
{add,2}: ... next <= {fetchOP,0}
{sub,0}: ... next <= {sub,1}
...
default:
endcase
2) The other solution i found is to create a reg "tick" which counts up
each clock cycle if not otherwise set to zero. The states of the FSM
now only consist of {opcode} thus it is smaller and undefined opcodes
could be avoided. The inferred hardware in each state depends on the
actual tick:
case opcode
add:
if (tick == 0) ...
else if (tick == 1) ...
else if (tick == 2) ...
else ...
tick <= 0
sub:
...
default:
endcase
Now i'm curious what hardware theese designs infer and which of them is
the better one. Maybe booth are crap and there's a much more clever way
to achieve this (i would like to know .
Even a FSM with a 15 bit wide state register (binary coded) is reencoded
by the synthesis tool as one-hot. My target is an FPGA, but there are
32K possible states at 15 bit!
Does anyone know a source on this?
Regards,
Markus
I'm about to describe a big state machine in Verilog. Most of the
states (let's call them "opcodes") need more than one clock cycle to
finish. So each of theese states do have a number of 'sub-states' on
it's own (let's call them "ticks").
To accomplish this i've come up with two design ideas:
1) The state is a concatenation of {opcode,tick} and leads to one big
FSM with many states with some of them undefined.
case {opcode,tick}
{add,0}: ... next <= {add,1}
{add,1}: ... next <= {add,2}
{add,2}: ... next <= {fetchOP,0}
{sub,0}: ... next <= {sub,1}
...
default:
endcase
2) The other solution i found is to create a reg "tick" which counts up
each clock cycle if not otherwise set to zero. The states of the FSM
now only consist of {opcode} thus it is smaller and undefined opcodes
could be avoided. The inferred hardware in each state depends on the
actual tick:
case opcode
add:
if (tick == 0) ...
else if (tick == 1) ...
else if (tick == 2) ...
else ...
tick <= 0
sub:
...
default:
endcase
Now i'm curious what hardware theese designs infer and which of them is
the better one. Maybe booth are crap and there's a much more clever way
to achieve this (i would like to know .
Even a FSM with a 15 bit wide state register (binary coded) is reencoded
by the synthesis tool as one-hot. My target is an FPGA, but there are
32K possible states at 15 bit!
Does anyone know a source on this?
Regards,
Markus