Salta al contenuto
Note per Studenti Sequential Systems - State, Latches and Flip-Flops Report

Sequential Systems - State, Latches and Flip-Flops

In questa pagina 5

So far every circuit had outputs depending only on the present inputs. A computer also needs memory: elements that keep information between successive operations. This note introduces sequential systems, state variables and their basic building blocks, latches and flip-flops.

Sequential systems and state variables

Definition (sequential circuit). In a sequential circuit the outputs depend on the present inputs and on the past history, summarised by the state. It is built by connecting a combinational network with one or more memory elements (here, flip-flops) through a feedback path: the outputs of the memory elements return to the inputs of the combinational network. Combinational circuits are acyclic, sequential ones are cyclic.

  • Present state: the values at the outputs of the memory elements (the state variables).
  • Next state: the values at the inputs of the memory elements; at the next clock event it becomes the present state.
  • The combinational network computes outputs and next state from inputs and present state.
            inputs ──►┌──────────────┐──► outputs
                      │ combinational│
        ┌────────────►│   network    │──┐ next state
        │ present     └──────────────┘  │
        │ state          ┌──────────┐   │
        └────────────────│ memory   │◄──┘
                         │ (FFs)    │◄── clock
                         └──────────┘

Example. A 2-bit counter with only the clock input goes through the states 00,01,10,1100,01,10,11: for the same input the output depends on the state.

Synchronous and asynchronous. A circuit is synchronous if inputs are evaluated and state and outputs are updated only in step with a periodic signal, the clock; its behaviour is determined at discrete, periodic instants …tN−1,tN,tN+1…\dots t_{N-1},t_N,t_{N+1}\dots. A synchronous sequential circuit is also called a finite state machine (FSM, see Finite State Machines - AnalysisAnalysing a synchronous sequential circuit means deriving from the circuit the flip-flop input equations (next state) and output equations, the state table (2^(m+n) rows for m flip-flops and n inputs), the state diagram (circles are states, arrows carry input/output) and a timing simulation. Mealy: output depends on state and input (written on the arrows, may change between clock edges); Moore: output depends only on the state (written in the circle, changes only at the clock edge). Two states are equivalent if they give the same outputs and lead to equivalent states, and can be merged to save flip-flops.Finite State Machines - Analysis →). An asynchronous circuit has no clock: the state changes when the inputs change. Almost all modern digital systems are synchronous: simpler to design and more robust.

Clock. A periodic square wave (duty cycle not necessarily 50%) distributed to all memory elements, with period TT, a rising edge (0→10\to1), a falling edge (1→01\to0), a high and a low level. Memory elements update only on certain clock events (for instance the rising edge). At every period the state is updated (not necessarily changed).

How a bit is stored

A buffer has delay tGt_G. If its output is fed back to its input and the input is held for tGt_G, the output keeps that value: the element stores a bit. The usual way is two inverters in a loop, each with delay tG/2t_G/2 (the principle of the SRAM cell, see Memories - ROM, RAM, SRAM and DRAMA memory is a set of cells organised in words, with control circuitry. It is classified as read-only (ROM) or read/write, random access (RAM), serial (SAM) or hybrid (Flash), volatile (SRAM, DRAM) or non-volatile. A RAM 2^k x n has k address bits (independent of n), n data bits, read/write and chip select. SRAM uses a bistable latch cell, is fast and needs no refresh; DRAM stores charge on a capacitor, is denser and needs refresh. Chips are organised as a row/column matrix with coincident selection and tri-state outputs, and combined in arrays for more words or more bits per word.Memories - ROM, RAM, SRAM and DRAM →). Extra inputs are needed to impose the value: this gives latches.

SR latch (NOR)

A latch is a bistable circuit (two stable states) that stores one bit and is not controlled by a clock (it is level-sensitive). The SR (Set-Reset) latch is obtained from the two-inverter loop by replacing the inverters with NOR gates: Q=R+Q‾‾Q=\overline{R+\overline Q} and Q‾=S+Q‾\overline Q=\overline{S+Q}.

SS RR Q(t+1)Q(t+1) function
0 0 Q(t)Q(t) hold
0 1 0 reset
1 0 1 set
1 1 undefined forbidden: Q=Q‾=0Q=\overline Q=0

S=R=1S=R=1 is forbidden: it drives both outputs to 0, violating the requirement that Q‾\overline Q be the complement of QQ; moreover when going from (1,1)(1,1) to (0,0)(0,0) the outputs cannot be predicted (they depend on which of S,RS,R switches first and on gate delays).

Evolution example (start with Q=0Q=0):

(S,R)(S,R) (1,0)(1,0) (0,0)(0,0) (0,1)(0,1) (0,0)(0,0) (1,0)(1,0) (0,1)(0,1)
QQ 1 1 0 0 1 0
action set hold reset hold set reset

S‾ R‾\overline S\,\overline R latch (NAND). With NAND gates the inputs are active low: S‾=0,R‾=1\overline S=0,\overline R=1 sets (Q=1Q=1); S‾=1,R‾=0\overline S=1,\overline R=0 resets; S‾=R‾=1\overline S=\overline R=1 holds; S‾=R‾=0\overline S=\overline R=0 is forbidden (both outputs 1).

SR latch with control input. With a control (enable) input CC: for C=0C=0 the latch holds whatever S,RS,R are; for C=1C=1 it behaves as an SR latch.

D latch

Definition (D latch). The D latch removes the forbidden state with a single data input DD (plus control CC): internally S=DS=D and R=D‾R=\overline D, so SS and RR can never be 1 together.

CC DD Q(t+1)Q(t+1)
0 X Q(t)Q(t) (hold)
1 0 0
1 1 1

For C=1C=1 the latch is transparent: QQ copies every change of DD (after the gate delay). It is level-sensitive: as long as C=1C=1 the output may change several times.

Flip-flop and non-transparency

In a synchronous circuit the input of a memory element partly depends on its own output (feedback). If the element were transparent, a change could propagate to the output and back several times within one clock period. A flip-flop (FF) is a clocked binary memory element that is not transparent: input changes reach the output only between two successive clock periods, at a clock event. Between two edges the FF ignores its inputs, and its new state depends only on the previous state.

Definition (master-slave flip-flop). A flip-flop is built from two D latches in cascade (master and slave) driven by opposite control signals: one is enabled at one clock level, the other at the opposite level. The trigger is the change that enables output variations.

Positive-edge-triggered (PET) D flip-flop. Master with control C‾\overline C (enabled when C=0C=0), slave with control CC (enabled when C=1C=1):

  • with C=0C=0 the master is transparent and copies DD; the slave is disabled and holds QQ;
  • on the rising edge the master closes (keeps the last value of DD) and the slave opens: the value sampled by the master is passed to QQ;
  • with C=1C=1 the master is closed and QQ does not change even if DD does.

Negative-edge-triggered (NET): the opposite; QQ changes on the falling edge. Edge-triggered FFs are faster and simpler to design than level-sensitive ones. From here on a positive-edge-triggered D flip-flop is always assumed; all FFs in a circuit should be of the same type.

Formula (characteristic equation of the D flip-flop). Q(t+1)=D(t)Q(t+1)=D(t), evaluated at the active edge.

Latch versus flip-flop

Clock with period 1010 ns, high in [5,10),[15,20),[25,30)[5,10),[15,20),[25,30) ns; DD is 0 until 2, 1 in [2,8)[2,8), 0 in [8,12)[8,12), 1 in [12,22)[12,22), 0 afterwards; outputs initially 0.

interval (ns) [0,5)[0,5) [5,8)[5,8) [8,15)[8,15) [15,25)[15,25) [25,… )[25,\dots)
QQ of D latch (CC = clock) 0 1 0 1 0
QQ of PET flip-flop 0 1 1 1 0

The latch follows DD while C=1C=1 (at 8 ns DD drops and QQ follows); the FF samples DD only on rising edges (5, 15, 25 ns: values 1,1,01,1,0) and ignores it in between. The electrical constraints on DD around the edge are in Timing of Sequential Systems - Setup, Hold and Maximum Clock FrequencyA flip-flop stores the right value only if its input is stable for the setup time before and the hold time after the clock edge, and its output changes after the propagation delay. In a synchronous circuit the clock period must satisfy T >= t_pd,FF + t_COMB + t_s,FF + t_slack, which fixes the maximum frequency; slowing the clock cures setup violations but not hold violations, which require t_pd,FF,min + t_COMB,min >= t_h. Clock skew modifies both constraints.Timing of Sequential Systems - Setup, Hold and Maximum Clock Frequency →; a VHDL description is in VHDL - Latches, Flip-Flops and ResetsIn VHDL a memory element is a process in which some branch does not assign the signal: the D latch is process(D,C) with if C='1' then Q<=D, the positive-edge-triggered flip-flop is process(CLK) with if CLK'event and CLK='1'. Asynchronous reset: RST is in the sensitivity list and tested first (if RST='1' ... elsif clock edge); synchronous reset: only CLK in the list and RST tested inside the clock-edge branch, so a clock edge is needed for it to act. The testbench of a synchronous circuit has a process generating the clock and one applying inputs away from the active edge.VHDL - Latches, Flip-Flops and Resets →.

Versione ripasso

  • Sequential circuit: outputs depend on inputs and state; combinational network plus memory elements in feedback. Present state = FF outputs, next state = FF inputs. Synchronous = updated only on the clock (an FSM); asynchronous = no clock.
  • Storing a bit: a loop of two inverters (or a buffer fed back) keeps its value; this is the SRAM principle.
  • SR latch (NOR): Q=R+Q‾‾Q=\overline{R+\overline Q}, Q‾=S+Q‾\overline Q=\overline{S+Q}. SR=00SR=00 hold, 0101 reset, 1010 set, 1111 forbidden (both outputs 0, unpredictable after going to 0000). NAND version: active-low inputs, S‾=R‾=0\overline S=\overline R=0 forbidden. With control C=0C=0 the latch holds.
  • D latch: S=DS=D, R=D‾R=\overline D. C=0C=0 hold; C=1C=1 gives Q=DQ=D (transparent, level-sensitive).
  • PET D flip-flop: two D latches (master enabled with C=0C=0, slave with C=1C=1). Samples DD on the rising edge only: Q(t+1)=D(t)Q(t+1)=D(t). NET changes on the falling edge. PET is assumed throughout.
  • Latch vs FF: with period 10 ns and the given DD, latch gives 0,1,0,1,00,1,0,1,0 on [0,5),[5,8),[8,15),[15,25),[25,… )[0,5),[5,8),[8,15),[15,25),[25,\dots), the FF gives 0,1,1,1,00,1,1,1,0.
  • SR evolution from Q=0Q=0: (1,0),(0,0),(0,1),(0,0),(1,0),(0,1)(1,0),(0,0),(0,1),(0,0),(1,0),(0,1) gives Q=1,1,0,0,1,0Q=1,1,0,0,1,0.
  • Mistakes: treating S=R=1S=R=1 as a reset; confusing transparent latch with edge-sampling FF; active-high inputs on a NAND latch; assuming the FF stores on the falling edge (depends on PET/NET).

Teoria collegata