Salta al contenuto
Note per Studenti Datapath and Control Unit Report

Datapath and Control Unit

In questa pagina 3

Two design examples that put together registers, adders and multiplexers: a register cell and a complete digital system divided into datapath and control unit (Registers and Load ControlAn n-bit register is n flip-flops with a common clock, and a counter is a register that steps through a sequence of states. Loading can be controlled by clock gating (an OR with the clock, which saves power but adds delays and clock skew) or, preferably, by load enable (a 2-to-1 MUX before each D input selecting the new data or the flip-flop's own output). Complex systems are split into a datapath (registers and arithmetic-logic blocks) and a control unit (an FSM that sends control signals and receives status signals).Registers and Load Control →, Microoperations and RTLA microoperation is an elementary operation on register data, written in Register Transfer Language (RTL), for example K1: R2 <- R1 meaning that when K1 is 1 the content of R1 is copied into R2 at the clock edge. Microoperations are transfers (simultaneous ones separated by commas exchange contents), arithmetic (add, subtract, increment, decrement), logic bit by bit with masks (AND clears, OR sets to 1, XOR complements) and shifts (sl towards the MSB doubles, sr towards the LSB halves).Microoperations and RTL →).

Register cell

Definition (register cell). A register cell is a flip-flop with combinational logic to perform microoperations on the register content. An nn-bit register uses nn copies of the cell; if the microoperations act on several bits, part of the logic can be shared between cells.

Example. Register AA implementing three logic microoperations with data BB (nn bits), each enabled by a control signal: AND: A←A∧B,EXOR: A←A⊕B,OR: A←A∨B.AND:\ A\leftarrow A\wedge B,\qquad EXOR:\ A\leftarrow A\oplus B,\qquad OR:\ A\leftarrow A\vee B . At most one of the three signals is 1; if all are 0 the register holds. Operations are bitwise, so one bit is enough to design.

Method. The register is an FSM: control inputs AND,EXOR,ORAND,EXOR,OR, data input BiB_i, present state AiA_i, next state the value to be written (Finite State Machines - SynthesisSynthesis of a synchronous sequential circuit follows specifications, state diagram, state table (merging equivalent states), binary state encoding, choice of D flip-flop, flip-flop input and output equations, minimisation, circuit and verification. A state summarises the useful part of history; a sequence recogniser has one state per recognised prefix, reusing states for overlaps. A reset gives a known initial state. Gray encoding (minimum flip-flops) versus one-hot (one flip-flop per state, simpler logic): for the 1101 recogniser Gray costs about half.Finite State Machines - Synthesis →). With D FFs, DiD_i is the next state. Table for the combinations of (Ai,Bi)(A_i,B_i) and controls:

AiBiA_i B_i ANDAND EXOREXOR OROR none (hold)
00 0 0 0 0
01 0 1 1 0
10 0 1 1 1
11 1 0 1 1

For each data minterm (Ai‾Bi\overline{A_i}B_i, AiBi‾A_i\overline{B_i}, AiBiA_iB_i; the case 0000 is always 0) the output is the sum of the control signals for which the bit is 1. With H=AND‾ EXOR‾ OR‾H=\overline{AND}\ \overline{EXOR}\ \overline{OR} (hold):

Formula (flip-flop input with three logic microoperations). Di=Ai‾Bi C1+AiBi‾ C2+AiBi C3,C1=EXOR+OR, C2=EXOR+OR+H, C3=AND+OR+H.D_i=\overline{A_i}B_i\,C_1+A_i\overline{B_i}\,C_2+A_iB_i\,C_3,\quad C_1=EXOR+OR,\ C_2=EXOR+OR+H,\ C_3=AND+OR+H .

Example. With AND=1AND=1 and the others 0: C1=0C_1=0, C2=0C_2=0, C3=1C_3=1, so Di=AiBiD_i=A_iB_i.

Writing the equation with two literals per product on the data makes C1,C2,C3C_1,C_2,C_3 depend only on control signals and be equal for all bits, so they are built once and shared; only the part with Ai,BiA_i,B_i is per-bit. Using the "at most one active" assumption, C1=EXOR+ORC_1=EXOR+OR, C2=EXOR+OR+AND‾C_2=EXOR+OR+\overline{AND}, C3=AND+OR+EXOR‾C_3=AND+OR+\overline{EXOR}.

Programmable and non-programmable systems

Definition.

  • In a programmable system the control-unit inputs carry a stream of instructions (a program). Each instruction triggers a sequence of microoperations in the datapath and specifies which, with which data and where to store results. The program is in a memory (RAM or ROM) and the control unit contains a register, the program counter (PC), holding the address of the next instruction to fetch. Example: the CPU.
  • In a non-programmable system the control unit executes no instructions: it determines microoperations only from input signals and datapath status signals. It performs one single task; it is a state machine with fixed logic (like digital-watch chips).

Example: sum of five values

Specifications. A synchronous system (inputs start, res, a of WW bits; outputs z, busy, clock):

  • accepts a sequence of integers aa and produces a sequence zz;
  • when start is asserted (synchronously) it sums the next five values of aa;
  • at the end zz is updated to the sum;
  • then the system waits for a new start; during a sum further start assertions are ignored;
  • busy =1=1 during the sum, 00 while waiting;
  • res immediately clears the output and reinitialises (synchronously) the system.

Partition. A datapath performing the sums and a control unit managing the sequence. The datapath has two sub-blocks: one accumulates the numbers, one counts them.

Datapath, sub-block 1: accumulation

An adder and two registers with load and clear:

  • ACC_REG: holds the intermediate sum; with acc_load=1 at the clock edge ACC←ACC+aACC\leftarrow ACC+a; with acc_clear=1 it is cleared;
  • OUT_REG: holds the final result, sent to output zz; with out_load=1: OUT←ACCOUT\leftarrow ACC.

Definition (microoperation). A μ\muop is a set of elementary operations on several signals realising an action: each μ\muop is a combination of control signals.

acc_load acc_clear out_load μ\muop
0 0 0 op_acc_idle
0 1 0 op_acc_clr
1 0 0 op_acc_acc
0 0 1 op_acc_upd_out

out_clear is not in the table because it is wired directly to res.

Datapath, sub-block 2: counting

A register CNT_REG (with load and clear) holds the current count; an adder decrements it by 1; a multiplexer chooses between the decremented count and the initial value NCOUNT =5=5 (cnt_reload); a comparator with 0 produces the signal zero, a status signal (datapath output, control-unit input).

cnt_load cnt_clear cnt_reload μ\muop
0 0 0 op_cnt_idle
1 0 0 op_cnt_cnt (decrement)
1 0 1 op_cnt_reload (reload 5)

Control unit

An FSM with inputs start and status signal zero, and outputs the control signals and busy. Three states, Mealy machine. x == don't care.

state start, zero accumulation μ\muop counting μ\muop busy next state
ready start=0 op_acc_idle op_cnt_idle 0 ready
ready start=1 op_acc_acc op_cnt_cnt 1 acc
acc zero=0 op_acc_acc op_cnt_cnt 1 acc
acc zero=1 op_acc_upd_out op_cnt_idle 1 init
init x op_acc_clr op_cnt_reload 1 ready

res is wired to out_clear and brings the machine to init, which clears ACC_REG and reloads the counter with 55.

How it counts. After init, cnt=5cnt=5. With start=1 in ready the first value is already accumulated (ACC←a1ACC\leftarrow a_1) and the count decrements (cnt=4cnt=4). In acc with cnt≠0cnt\ne0 the values a2,a3,a4,a5a_2,a_3,a_4,a_5 are accumulated (cnt=3,2,1,0cnt=3,2,1,0). With cnt=0cnt=0 (zero=1) one cycle of op_acc_upd_out copies ACCACC into OUTOUT and the machine goes to init, which clears the accumulator and reloads the counter: back to ready.

Simulation (res=1 in cycle 0; start=1 in cycles 3 and 7, a=3,1,4,1,5a=3,1,4,1,5 in cycles 3 to 7; the second start is ignored because the system is busy):

cycle 3 4 5 6 7 8 9 10
state ready acc acc acc acc acc init ready
start 1 0 0 0 1 0 0 0
aa 3 1 4 1 5 - - -
cntcnt (at start of cycle) 5 4 3 2 1 0 0 5
zero 0 0 0 0 0 1 1 0
ACCACC 0 3 4 8 9 14 14 0
OUT=zOUT=z 0 0 0 0 0 0 14 14
busy 1 1 1 1 1 1 1 0

(Values are those at the start of each cycle, before the clock edge.) The final sum is 3+1+4+1+5=143+1+4+1+5=14 and appears on zz from cycle 9; the partial totals of ACCACC are 3,4,8,9,143,4,8,9,14.

VHDL description

vhdl
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;

entity sum5 is
  generic ( NCOUNT : integer := 5; W : integer := 8 );
  port ( clk, res, start : in  std_logic;
         a    : in  std_logic_vector(W-1 downto 0);
         z    : out std_logic_vector(W-1 downto 0);
         busy : out std_logic );
end sum5;

architecture beh of sum5 is
  type state_type is (ready, acc, init);
  signal state, next_state : state_type;
  signal acc_load, acc_clear, out_load, cnt_load, cnt_reload : std_logic;
  signal acc_reg, out_reg : unsigned(W-1 downto 0) := (others => '0');
  signal cnt  : integer range 0 to NCOUNT := 0;
  signal zero : std_logic;
begin
  zero <= '1' when cnt = 0 else '0';
  z    <= std_logic_vector(out_reg);

  -- datapath: registers ACC_REG, OUT_REG, CNT_REG
  datapath : process (clk)
  begin
    if clk'event and clk = '1' then
      if res = '1' then out_reg <= (others => '0');          -- out_clear = res
      elsif out_load = '1' then out_reg <= acc_reg; end if;
      if acc_clear = '1' then acc_reg <= (others => '0');
      elsif acc_load = '1' then acc_reg <= acc_reg + unsigned(a); end if;
      if cnt_load = '1' then
        if cnt_reload = '1' then cnt <= NCOUNT; else cnt <= cnt - 1; end if;
      end if;
    end if;
  end process;

  -- control unit: state register (res leads to init)
  state_register : process (clk)
  begin
    if clk'event and clk = '1' then
      if res = '1' then state <= init; else state <= next_state; end if;
    end if;
  end process;

  -- control unit: next state and control signals (Mealy)
  control : process (state, start, zero)
  begin
    acc_load <= '0'; acc_clear <= '0'; out_load <= '0';
    cnt_load <= '0'; cnt_reload <= '0'; busy <= '0';
    next_state <= state;                                      -- default: stay
    case state is
      when ready =>
        if start = '1' then
          acc_load <= '1'; cnt_load <= '1'; busy <= '1'; next_state <= acc;
        end if;
      when acc =>
        busy <= '1';
        if zero = '0' then
          acc_load <= '1'; cnt_load <= '1';
        else
          out_load <= '1'; next_state <= init;
        end if;
      when init =>
        acc_clear <= '1'; cnt_load <= '1'; cnt_reload <= '1'; busy <= '1'; next_state <= ready;
    end case;
  end process;
end beh;

The default values at the start of the control process avoid unwanted memory: every output is assigned on every path (VHDL - Finite State Machines and Sequential TestbenchesA finite state machine is described in behavioral VHDL with an enumerated type for the states and three processes: the state register (reset and state <= next_state on the clock edge), the next state as a combinational function of state and input (case state, with default next_state <= state), and the output as a combinational function of the state alone (Moore) or of state and input (Mealy). The testbench has a clock process and an input process (initial reset, then a test sequence that visits all states).VHDL - Finite State Machines and Sequential Testbenches →).

Versione ripasso

  • Register cell: FF plus logic for microoperations; nn cells per register, shared logic. Example A←A∧BA\leftarrow A\wedge B, A⊕BA\oplus B, A∨BA\vee B (at most one control, else hold): Di=Ai‾BiC1+AiBi‾C2+AiBiC3D_i=\overline{A_i}B_iC_1+A_i\overline{B_i}C_2+A_iB_iC_3 with C1=EXOR+ORC_1=EXOR+OR, C2=EXOR+OR+AND‾C_2=EXOR+OR+\overline{AND}, C3=AND+OR+EXOR‾C_3=AND+OR+\overline{EXOR}. With only AND=1AND=1: Di=AiBiD_i=A_iB_i.
  • Programmable (CPU): instructions from memory, program counter. Non-programmable: control unit uses only inputs and datapath status signals; one task.
  • Sum of 5 values: inputs start, res, a; outputs z, busy; five values after start, start ignored while busy, res clears.
  • Datapath: ACC_REG (acc_load: ACC←ACC+aACC\leftarrow ACC+a; acc_clear), OUT_REG (out_load: OUT←ACCOUT\leftarrow ACC; clear wired to res), CNT_REG with decrementer, MUX (decremented count or NCOUNT=5=5, cnt_reload) and comparator giving status signal zero.
  • μ\muops: control-signal combinations: op_acc_idle/clr/acc/upd_out; op_cnt_idle/cnt/reload.
  • Control unit (Mealy, 3 states): ready: start=0 stay, start=1 go to acc with op_acc_acc and op_cnt_cnt, busy 1. acc: zero=0 stay; zero=1 do op_acc_upd_out, go to init. init: op_acc_clr, op_cnt_reload, go to ready. res leads to init.
  • Counting: first value accumulated in the start cycle; a2..a5a_2..a_5 in acc; then OUT←ACCOUT\leftarrow ACC. a=3,1,4,1,5a=3,1,4,1,5: ACC=3,4,8,9,14ACC=3,4,8,9,14, z=14z=14.
  • VHDL: sum5 with generics NCOUNT, W; process for datapath, for state register, and for Mealy control with defaults.
  • Mistakes: zero is a status signal (datapath to control unit), the others are control signals; five values, not six; start does not restart a sum in progress; programmable vs non-programmable confusion.

Teoria collegata