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 : 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 . 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 , a rising edge (), a falling edge (), 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 . If its output is fed back to its input and the input is held for , the output keeps that value: the element stores a bit. The usual way is two inverters in a loop, each with delay (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: and .
| function | |||
|---|---|---|---|
| 0 | 0 | hold | |
| 0 | 1 | 0 | reset |
| 1 | 0 | 1 | set |
| 1 | 1 | undefined | forbidden: |
is forbidden: it drives both outputs to 0, violating the requirement that be the complement of ; moreover when going from to the outputs cannot be predicted (they depend on which of switches first and on gate delays).
Evolution example (start with ):
| 1 | 1 | 0 | 0 | 1 | 0 | |
| action | set | hold | reset | hold | set | reset |
latch (NAND). With NAND gates the inputs are active low: sets (); resets; holds; is forbidden (both outputs 1).
SR latch with control input. With a control (enable) input : for the latch holds whatever are; for it behaves as an SR latch.
D latch
Definition (D latch). The D latch removes the forbidden state with a single data input (plus control ): internally and , so and can never be 1 together.
| 0 | X | (hold) |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
For the latch is transparent: copies every change of (after the gate delay). It is level-sensitive: as long as 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 (enabled when ), slave with control (enabled when ):
- with the master is transparent and copies ; the slave is disabled and holds ;
- on the rising edge the master closes (keeps the last value of ) and the slave opens: the value sampled by the master is passed to ;
- with the master is closed and does not change even if does.
Negative-edge-triggered (NET): the opposite; 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). , evaluated at the active edge.
Latch versus flip-flop
Clock with period ns, high in ns; is 0 until 2, 1 in , 0 in , 1 in , 0 afterwards; outputs initially 0.
| interval (ns) | |||||
|---|---|---|---|---|---|
| of D latch ( = clock) | 0 | 1 | 0 | 1 | 0 |
| of PET flip-flop | 0 | 1 | 1 | 1 | 0 |
The latch follows while (at 8 ns drops and follows); the FF samples only on rising edges (5, 15, 25 ns: values ) and ignores it in between. The electrical constraints on 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): , . hold, reset, set, forbidden (both outputs 0, unpredictable after going to ). NAND version: active-low inputs, forbidden. With control the latch holds.
- D latch: , . hold; gives (transparent, level-sensitive).
- PET D flip-flop: two D latches (master enabled with , slave with ). Samples on the rising edge only: . NET changes on the falling edge. PET is assumed throughout.
- Latch vs FF: with period 10 ns and the given , latch gives on , the FF gives .
- SR evolution from : gives .
- Mistakes: treating 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).