Hardware Reference
In-Depth Information
The auxiliary-register-related declarations are in line 13. It is assumed that there is
only one output and that it must be stored, but recall that the circuit might have
several outputs, not all registered. The actual number of auxiliary registers is deter-
mined by the number of outputs that depend on past output values.
To implement the auxiliary register, an
always_ff
block is employed in lines
21-23.
Finally, note in the
always_comb
block of lines 29-49 that
outp
(lines 32 and 39)
is no longer a function of itself but rather a function of
outp_reg
. This removes the
recursiveness, allowing the output to be computed by a combinational circuit.
As explained in section 11.3, an interesting aspect of category 3 FSMs is that the
auxiliary register can also play the role of output register (for glitch-free and/or pipe-
lined construction) when the output is one of the signals stored in an auxiliary register.
To do so, simply send
outp_reg
out instead of
outp
.
1 //Part 1: Module header:-----------------------------
2
(same as for categ. 1 and 2, sections 7.3 and 10.2)
3
4 //Part 2: Declarations:------------------------------
5
6
//FSM-related declarations:
7
(same as for category 1 Moore, Section 7.3)
8
9
//Timer-related declarations:
10
(same as for category 2 Moore, section 10.2)
11
12
//Auxiliary-register-related declarations:
13
logic [N-1:0] outp, outp_reg;
14
15 //Part 3: Statements:--------------------------------
16
17
//Timer:
18
(same as for category 2 Moore, section 10.2)
19
20
// Auxiliary register:
21
always_ff @(posedge clk, posedge rst)
22
if (rst) outp_reg <= <initial_value>;
23
else outp_reg <= outp;
24
25
//FSM state register:
26
(same as for category 2 Moore, section 10.2)
27
28
//FSM combinational logic:
29
always_comb
30
case (pr_state)
31
A: begin
32
outp <= outp_reg;
33
tmax <= T1-1; //if using strategy #2
34
if (condition) nx_state <= B;
35
else if (condition) nx_state <= ...;
36
else nx_state <= A;