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 -bit register uses copies of the cell; if the microoperations act on several bits, part of the logic can be shared between cells.
Example. Register implementing three logic microoperations with data ( bits), each enabled by a control signal: 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 , data input , present state , 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, is the next state. Table for the combinations of and controls:
| 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 (, , ; the case is always 0) the output is the sum of the control signals for which the bit is 1. With (hold):
Formula (flip-flop input with three logic microoperations).
Example. With and the others 0: , , , so .
Writing the equation with two literals per product on the data makes depend only on control signals and be equal for all bits, so they are built once and shared; only the part with is per-bit. Using the "at most one active" assumption, , , .
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 bits; outputs z, busy, clock):
- accepts a sequence of integers and produces a sequence ;
- when
startis asserted (synchronously) it sums the next five values of ; - at the end is updated to the sum;
- then the system waits for a new
start; during a sum furtherstartassertions are ignored; busyduring the sum, while waiting;resimmediately 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; withacc_load=1at the clock edge ; withacc_clear=1it is cleared;OUT_REG: holds the final result, sent to output ; without_load=1: .
Definition (microoperation). A op is a set of elementary operations on several signals realising an action: each op is a combination of control signals.
acc_load |
acc_clear |
out_load |
op |
|---|---|---|---|
| 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 (cnt_reload); a comparator with 0 produces the signal zero, a status signal (datapath output, control-unit input).
cnt_load |
cnt_clear |
cnt_reload |
op |
|---|---|---|---|
| 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 op | counting op | 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 .
How it counts. After init, . With start=1 in ready the first value is already accumulated () and the count decrements (). In acc with the values are accumulated (). With (zero=1) one cycle of op_acc_upd_out copies into 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, 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 |
| 3 | 1 | 4 | 1 | 5 | - | - | - | |
| (at start of cycle) | 5 | 4 | 3 | 2 | 1 | 0 | 0 | 5 |
zero |
0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 |
| 0 | 3 | 4 | 8 | 9 | 14 | 14 | 0 | |
| 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 and appears on from cycle 9; the partial totals of are .
VHDL description
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; cells per register, shared logic. Example , , (at most one control, else hold): with , , . With only : .
- 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; outputsz,busy; five values afterstart,startignored while busy,resclears. - Datapath:
ACC_REG(acc_load: ;acc_clear),OUT_REG(out_load: ; clear wired tores),CNT_REGwith decrementer, MUX (decremented count orNCOUNT,cnt_reload) and comparator giving status signalzero. - ops: control-signal combinations:
op_acc_idle/clr/acc/upd_out;op_cnt_idle/cnt/reload. - Control unit (Mealy, 3 states):
ready:start=0stay,start=1go toaccwithop_acc_accandop_cnt_cnt, busy 1.acc:zero=0stay;zero=1doop_acc_upd_out, go toinit.init:op_acc_clr,op_cnt_reload, go toready.resleads toinit. - Counting: first value accumulated in the
startcycle; inacc; then . : , . - VHDL:
sum5with genericsNCOUNT,W; process for datapath, for state register, and for Mealy control with defaults. - Mistakes:
zerois a status signal (datapath to control unit), the others are control signals; five values, not six;startdoes not restart a sum in progress; programmable vs non-programmable confusion.