Part 3: Regular Sequential Circuit

Objective

This tutorial contains information about sequential circuit and several design examples of sequential circuit.

Source Code

This repository contains all of the code required in order to follow this tutorial.

References

1. Synchronous Design Methodology

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.

1.1. D Flip-Flop and Register

The most basic storage component in a sequential circuit is a D-type flip-flop (D FF) as shown in the following figure.

Figure 1. D flip-flop

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.

clk
rst_n
q*

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.

1.2. Synchronous System

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.

Figure 2. Synchronous system

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.

1.3. Timing Parameters

There are three main timing parameters of a D FF: TsetupT_{setup} (setup time), TholdT_{hold} (hold time), and TcqT_{cq}. TsetupT_{setup} is the time before the active clock edge, when the data signal is not allowed to change its value. TholdT_{hold} is the time after the active clock edge, when the data signal is not allowed to change its value. TcqT_{cq} is the time required to propagate the value of d to q at the rising edge of the clock signal.

Figure 3. Setup and hold time

The d signal must be stable during TsetupT_{setup} and TholdT_{hold} to prevent the FF from entering the metastable state.

1.4. Maximal Operating Frequency

The timing of a sequential circuit is characterized by the maximal clock frequency, fmaxf_{max}. The reciprocal of fmaxf_{max} specifies TclockT_{clock}, 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:

Tclock=Tcq+Tcomb+TsetupT_{clock}=T_{cq}+T_{comb}+T_{setup}

and the maximal clock rate is the reciprocal:

fmax=1Tclock=1Tcq+Tcomb+Tsetupf_{max}=\frac{1}{T_{clock}}=\frac{1}{T_{cq}+T_{comb}+T_{setup}}
Figure 4: Launch and Capture D FF

1.5. Timing Constraint in Vivado

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:

fmax=1Tclock_constr−WNSsetup f_{max}=\frac{1}{T_{clock\_constr}-WNS_{setup}}

2. Design Examples

2.1. Register

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.

Figure 5. Register

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.

Figure 6. Simulation waveform of the register

2.2. Counter

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.

Figure 7. Counter

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.

Figure 8. Simulation waveform 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.

Figure 9. Vivado block design for counter module

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.

Figure 10. Summary of resource utilization after synthesis

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.

Figure 11. The details of resource utilization after synthesis

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.

Figure 12. Timing constraint of the counter module

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.

Figure 13. Testing the counter module using the ILA interface in Vivado

2.3. Counter as FSM

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.

Figure 14. Timing diagram design

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.

Figure 15. Counter as FSM module

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.

Figure 16. Simulation waveform of the counter module as FSM

3. Conclusion

In this tutorial, we covered the sequential circuit and several design examples of sequential circuit.

Last updated