Part 3: Regular Sequential Circuit
Last updated
Last updated
This tutorial contains information about sequential circuit and several design examples of sequential circuit.
This repository contains all of the code required in order to follow this tutorial.
Pong P. Chu, FPGA Prototyping by Verilog Examples, https://onlinelibrary.wiley.com/doi/book/10.1002/9780470374283
Setup And Hold Time, https://semiconshorts.com/2022/12/31/setup-and-hold-time/
Vivado: Finding the "maximal frequency" after synthesis, https://www.01signal.com/vendor-specific/xilinx/vivado-minimal-period/
A sequential circuit is a circuit with memory, which forms the internal state of the circuit. Unlike a combinational circuit, in which the output is a function of input only, the output of a sequential circuit is a function of the input and the internal state.
The synchronous design methodology is the most commonly used practice in designing a sequential circuit. In this methodology, all storage elements are controlled (i.e., synchronized) by a global clock signal and the data is sampled and stored at the rising or falling edge of the clock signal.
The most basic storage component in a sequential circuit is a D-type flip-flop (D FF) as shown in the following figure.
This is the truth table for D FF. The next q
value (q*
) is equal to input d
at the rising edge of the clock and when the reset is 1. Note that this rst_n
signal is active-low, so the D FF is reset to 0 when the rst_n
is 0.
0
-
q
1
-
q
↑
0
0
↑
1
d
This is the implementation of D FF in Verilog. In a sequential circuit, we use non-blocking assignments (<=
) inside the always block.
A register is a collection of D FFs that are controlled by the same clock and reset signals. The Verilog code of the register is the same as D FF, but it has more than 1 bit of input and output. This example shows an 8-bit register.
The following figure shows a block diagram of a synchronous system. It consists of the following parts:
State register: a collection of D FFs controlled by the same clock signal (state_reg
).
Next-state logic: combinational logic that uses the external input and internal state (i.e., the output of register) to determine the new value of the register (state_next
).
Output logic: combinational logic that generates the output signal.
Synchronous system are classified into three groups based on their next-state logic properties:
Regular sequential circuit: the state transitions in the circuit exhibit a "regular" pattern, as in a counter or shift register. The next-state logic is constructed primarily by a predesigned, "regular" component, such as an incrementor or shifter.
Finite state machine (FSM): the state transitions in the circuit do not exhibit a simple, repetitive pattern. The next-state logic is constructed by "random logic" and synthesized from scratch. It should be called a random sequential circuit, but is commonly known as an FSM (finite state machine).
Finite state machine with data path (FSMD): the circuit consists of a regular sequential circuit and an FSM. The two parts are known as a data path and a control path, and the complete circuit is known as an FSMD (FSM with data path).
In this tutorial, we focus on the regular sequential circuit. FSM and FSMD will be the next part's topic.
There are three main timing parameters of a D FF: (setup time), (hold time), and . is the time before the active clock edge, when the data signal is not allowed to change its value. is the time after the active clock edge, when the data signal is not allowed to change its value. is the time required to propagate the value of d to q at the rising edge of the clock signal.
The d signal must be stable during and to prevent the FF from entering the metastable state.
The timing of a sequential circuit is characterized by the maximal clock frequency, . The reciprocal of specifies , the minimal clock period, which can be interpreted as the interval between two sampling edges of the clock. The minimal clock period can be obtained by adding the propagation delays and setup time constraint:
and the maximal clock rate is the reciprocal:
We can specify the desired operating frequency as a synthesis constraint or derived from IP core settings, and the synthesis software will try to obtain a circuit to satisfy this requirement. After synthesis, we can check the relevant timing information to see whether the imposed constraints are met or not.
The synthesis result will also show the worst negative slack (WNS) for setup time. From this slack time, we can calculate the maximal frequency by:
The following figure shows a register block diagram. It consists of a state register and next-state logic. This register has an active-low reset (rst_n
) and a clear signal (clr
). When either one of these signals is active, the register value will be set to 0. The enable signal controls the input either from the previous register value (q
) or the new input (d
). The value of the register will be updated only if the enable signal is 1.
This is the implementation of a register in Verilog. We use parameterized code to specify the register width.
The following code is the testbench for the register.
This is the simulation result of the register. The d
value is loaded to the q
at the rising edge of the clock.
The following figure shows a counter block diagram. It consists of a state register and next-state logic. This counter starts counting up when the start
signal is 1. Then, it will count up from 0 to 5. After that, it resets back to 0 and waits for the start
signal again.
This is the implementation of the counter in Verilog.
The following code is the testbench for the counter.
This is the simulation result of the counter module.
Then, we can add the counter module to the Vivado block design, add a virtual input/output (VIO) IP, and also add an integrated logic analyzer (ILA) IP. The ILA IP functions as an integrated logic analyzer so that we can observe the waveform that actually happens inside the FPGA.
This is the constraints for this block design. We only use clock signal that has a period of 8.0 ns (125 Mhz).
The following figure shows the synthesis result.
We can view the detailed resource utilization. The counter module only uses 5 LUTs and 4 registers. Most of the resources are for the VIO and ILA IP.
From the result, we can see that the timing requirements are met for this 125 MHz clock. There is setup WNS value which is 1.730 ns. This means that we could have asked for a clock period that is shorter by 1.730 ns, and it would still be OK. So the requested clock period could have been 8.0 - 1.730 ns = 6.270 ns, which is about 159 MHz.
The following figure shows how we can observe the waveform of the counter module using the ILA interface in Vivado (after programming the FPGA). First, we have to set up the trigger signal for this ILA, which is the start
signal. Then, on the VIO, we toggle the start to 1.
Suppose we want to create a controller for a system that consists of 1 RAM for data input, 1 PE, and 1 RAM for data output. The RAM has two signals that need to be controlled, which are enable (en_rd
, en_wr
) and address (addr_rd
, addr_wr
) signals. The PE has one signal that needs to be controlled, which is enable (en_pe
) signal. The requirements of the timing diagram are shown below.
In addition to that, there are status signals, which are ready
and done_tick
. The counter starts when the start
signal is 1. We can implement these requirements using a counter module. The following figure shows the circuit implemented for that purpose.
The circuit consists of three counters. One for FSM, and the others for address reading and writing. Then, from the counter FSM output, we can build the output logic. The logic uses comparators and 2-to-1 multiplexers. The logic is based on the current counter FSM value, which starts from 1 to 7. Based on that counter value and output logic condition, the output signals are generated.
This is the implementation of the counter as FSM in Verilog. In this module, we create both combinational and sequential circuits. We use both continuous and procedural assignments.
The following code is the testbench for the counter as FSM.
This is the simulation result of the counter module as FSM.
In this tutorial, we covered the sequential circuit and several design examples of sequential circuit.