Professional Documents
Culture Documents
CE
In the first, if you’re not invited you can’t go so the second input is irrelevant.
In the second you can’t have both at the same time so the outcome can be any-
thing convenient.
The resultant logic may then be simple enough to apply an ad-hoc approach (i.e.
it’s ‘obvious’) as we did with the adder previously. If not some form of logic
CE reduction is needed.
Some people can do this with Boolean algebra. Another way is to use a graphi-
cal approach such as Karnaugh maps which work well for up to four or five
inputs. Beyond that, CAD tools are very helpful at implementing (e.g.) the
Because the clock is common to all registers, sometimes it may be omitted on Quine-McCluskey algorithm.
‘informal’ drawings. (We will try to keep it visible in this course!)
Espresso is a logic reduction programme that has been around for many years
(since at least 1986) which uses a different algorithm. It is a useful, but some-
what user-unfriendly, tool.
In later lab. exercises we will express the problem in a Hardware Design Lan-
guage (HDL) and leave it to the compiler to minimise the logic to the actual
gates.
University of Manchester School of Computer Science
Inputs
Outputs
Register
from one ‘state’ to another Combinatorial
according to some well-defined
rules. Logic
Definition
A register is simply a collection of flip-flops which are acting together.
Implementation
❏ To remember its history the machine must contain some state
holding devices Moore machine
(i.e. flip-flops).
❏ To represent each state unambiguously there must be at least
log2(states) flip-flops. (N flip-flops allow the representation of 2N
states.)
Number of Number of
states flip-flops
1 0
2 1
3-4 2
5-8 3
9-16 4 Differences
(2N-1+1) - 2N N
University of Manchester School of Computer Science
initial state
0
6
4
3
Design Process
The complete design process for simple sequential systems usually works some- State Transition Table
thing like this:.
Current state Next state
❏ First, decide on the inputs and outputs, and determine the different State No. C B A C′ B′ A′
internal states required. Draw a state transition diagram1. 0 0 0 0 0 0 1
❏ Perform state assignment (i.e. label each state with a unique No,). 1 0 0 1 0 1 0
2 0 1 0 0 1 1
❍ State assignment is arbitrary but the particular state assign-
3 0 1 1 1 0 0
ment chosen may influence the complexity of the finished
4 1 0 0 1 0 1
design; as you gain experience optimal state assignment
5 1 0 1 1 1 0
becomes easier.
6 1 1 0 0 0 0
❍ Often some of the state bits can be used as output bits directly. 7 1 1 1 δ δ δ
This summarises the state transition diagram, showing what happens next in
In a manual process, proceed as follows:
each state. Note that (in this case) seven states were required but the implemen-
❏ Complete a state transition table. tation needs a whole number of bits. Three bits is the minimum which can be
❏ Extract (and simplify) all the logic equations – Karnaugh maps may used (23 = 8) – the minimum number of state bits is usually preferred – so there
help. are eight states in the state transition table.
❏ Draw the logic diagram as gates and connect to the appropriate The undefined state should never be reached, so it doesn’t really matter what its
flip-flops. next state is. However in this example it would be preferable if it did not remain
❏ Test! in state #7 (i.e. the ‘don’t cares’ all end up as “1”; this would ensure that the cir-
cuit would recover if it reached this ‘illegal’ state (e.g. at switch on).
If using a HDL: A state transition table is not, strictly speaking, a truth table, but it can be
reduced to logic equations using the same methods.
❏ Usually the FSM can be translated directly into HDL code
❏ Compile
❏ Test!
When does a state machine move from one state to the next?
❏ In principle this can happen as a result of any input change.
❏ In practice it is normal to change only in response to a clock transition
A′
A
Register
Combinatorial
B′
E.g. our modulo-7 counter B
C′
Logic C
Design process
❏ The state transition diagram is given on slide 4.
❏ State assignment for a counter is self-selecting; the numbers repre-
sent binary codes in an ascending sequence. (Note that a descending
modulo-7 counter is also possible, as would be a number of bizarre ❏ Test!
variations.)
❏ The state transition table. is shown on slide 5.
❏ For output A′, we select the entries where A′ is true (1), and write
down the Boolean equation:
A′ = (A and B and C) or (A and B and C) or (A and B and C)
A Karnaugh map will reduce this to:
A′ = (A and B) or (A and C)
Boolean algebra can take this a bit further:
A′ = A and (B or C)
A′ = A and (B and C)
University of Manchester School of Computer Science
External Inputs
❏ A typical state machine will allow some external control
❏ Some or all of the transitions will be conditional
e.g. a modulo-7 counter with a (synchronous) reset
0 reset = 0
6
reset = 1
reset = 0 1
reset = 1
5 reset = 1 reset = 0
reset = 0 reset = 1 2
reset = 1
4
3 reset = 0
reset = 0
The synchronous reset forces the counter to state #0 when the next active clock transition occurs.
up=1 0 up=1
6 5
up=0
up=0 1 2
up=1 up=0
4
up=1
5 up=0 3
up=0
up=0 2 Triggerable counter
up=1 up=0
4
3 up=1
up=1 Set-up and hold times
Synchronous up-down counter Note that external inputs should not violate the set-up and hold times of the
FSM’s registers. This usually requires that they are synchronized to the same
A finite state machine will always behave in some way (even if that behaviour is clock.
‘do nothing’) each time it has an opportunity to change state (usually corre-
sponding to a clock pulse).
A state diagram is supposed to represent the behaviour of the state machine. It is
therefore essential that it shows the behaviour under all conditions. Note that
this may show that the FSM remains in the current state (see example below). Exercise
Not all arcs need be conditional. In most cases some (or even all) of the inputs Complete the state transition table for a modulo-4 up/down counter:
will not influence the behaviour in certain states.
State Up Next
In the example above the counter is started by a particular input (Go=1) after 0 up=1
up=1 0 0 0
which the input is ignored until the FSM has completed its counting cycle.
up=0 up=0 0 0 1
0 1 0
3 1
0 1 1
up=0 up=0 1 0 0
up=1 up=1 1 0 1
2
1 1 0
1 1 1
University of Manchester School of Computer Science
The FSM model represents the behaviour of the processor quite well …
addr mem.
branch
… but duplicating each state 21024 times for each possible value
of the register bank state would make the bubble diagram unreadable!
However the two subsystems separate at well defined boundaries and this is
For example a processor fetches, decodes and executes instructions:
important in keeping the complexity manageable.
❏ Fetch: output an address, input an instruction
❏ Decode: decide what the instruction should do
Further subdivision of the datapath may be done: an obvious subdivision here
❏ Execute: change the processor’s register (or control) state
would be to build separate units for each instruction processing stage. This
❍ the details of execution depend on the instruction fetched approach is common in high-performance processors.
The fetch will normally involve some control sequencing but is totally inde- In the MU0 processor we will look at later this approach is not taken in order
pendent of the value (instruction) fetched. to keep the size of the design down. Instead a single arithmetic unit is made
to serve the needs of fetch and decode at different times.
The decode may be different for different instructions, but there will be fewer
than 232 categories of operation1 so there will still be a large amount of commo-
The control may also be subdivided as appropriate to keep its complexity under
nality (e.g. the control probably doesn’t care which registers are being used).
control. An common example application could be a traffic light controller.
Execution may have a (small) number of different behaviours. However the
Traffic lights follow a fixed sequence but typically spend different amounts of
controller may order an ADD instruction but will not care what numbers (from
time in each phase. One approach is to have several states which all appear
the 264 possible combinations) the datapath adds. the same. Another approach is to have an FSM which cycles the phases and
another which handles the timing. When the first enters a new state it signals
Register Transfer Level (RTL) is a means of exploiting this separation of data this to the timing together with the number of cycles it should remain there; it
and control in order to simplify the design process. RTL effectively ignores the then waits for the timing FSM to signal that that time has elapsed.
different values (states) of the data, instead treating them as individual variables. All the second machine does is input a time, count off that number of cycles
RTL is therefore a hierarchical ‘level’ of abstraction ‘higher’ than a gate level and output a ‘finished’ signal.
design.
Here the system state changes on the rising edge of every clock cycle, and the functionality can be
described by:
f1{reg2} ⇒ reg3; f2{reg1} ⇒ reg2
Note: synchronous operation means changes occur in parallel. This corresponds to pipelined
data processing; in general we want more flexible control of the register behaviour, so:
❏ all registers are updated at the same point in the clock cycle
❏ some registers may not change in particular clock cycles
It is assumed that the clock cycle is long enough for all logic between registers to stabilise before
the next active clock edge
Note a ‘pipeline’ is not the only possible structure; feedback of data values is
typical in most computing machines.
Register
Register
Logic Logic
University of Manchester School of Computer Science
Datapath Fetch
Decode
Registers
Control
Memory
Shift
ALU
The slide shows a possible implementation of an ARM microprocessor, similar Don’t try and memorise this picture! However, later in the course or at revision
to the simpler versions available. The processor occupies the right-hand three time, you might like to consider how some of the ARM instructions you have
quarters of the figure, a memory has been shown on the left hand side. used in COMP10031 use the various buses shown here. Here’s a few to try:
❏ SUB R0, R1, R2
The ARM is a 32-bit microprocessor, so the thick lines normally show 32-bit ❏ LDR R5, [R6, R7]
buses. The thinner lines show control paths. ❏ STR R8, [R9], #&20
The datapath has been shown subdivided into its major blocks such as instruc-
tion fetch, instruction decode, the register bank and the Arithmetic Logic Unit
(ALU) which performs the actual calculations. Multiplexers allow the selection
of inputs at various places.
The control logic is less easy to draw at this scale, so has been concealed.
0 X 0 0
0 X 1 1
1 0 X 0
1 1 X 1
Truth tables
Schematics
addr mem.
branch
Timing diagrams
State diagrams
Revision
To summarise the major classes of design aids to date:
A hierarchy is typical so that subcircuits can be ‘hidden’ to keep complexity Truth tables can be a useful design aid in specifying what you want to happen.
under control. This also promotes the reuse of components. They are especially good at forcing all possible input combinations to be consid-
ered.
Timing diagrams are also used as simulation outputs to show what a circuit State diagrams are frequently used to document the behaviour of finite state
would really do under a set of test circumstances. This can be compared with machines. Note that FSMs are frequently implemented in software too; this is
what was wanted. When there are errors these can be traced back in time to find not just for hardware.
the cause.
University of Manchester School of Computer Science
In Out
❏ Cars may enter at any time, unless the car park is full
❍ Cars attempting to be entered will be sensed
if the car park is not full they will be admitted and counted in
else the car park is full so they will not be admitted From the foregoing we can sketch a preliminary state diagram.
Interface
❏ Sensors
❍ an input sensor
❍ an output sensor
❏ Actuators
❍ a ‘full’ light
❍ an input barrier control
❍ an output barrier control
(The following design neglects the barrier controls. You are encouraged to add
outputs to control them.)
University of Manchester School of Computer Science
dec tot
out
not full
in
C H
ready inc tot cmp
E T Y
full K N L
out
S O
dec tot full
where in indicates a car entering, out a car exiting, and full is true when the total equals the
maximum capacity of the car park.
❏ need a constant to represent the ‘maximum capacity’
The ready and full states are exited only when out or in is true.
In practice …
Nowadays, in practice, no one would build a logic circuit to control a car
park barrier. The preferred method would be to use an off-the-shelf micro-
controller (single chip computer) and use software to customise its func-
tion.
Specific hardware (e.g. ASICs – Application Specific Integrated Circuits)
are only used when software would be too slow for the job. As a guide hard-
ware should be about 100x faster than a software solution; for a car park bar-
rier this hardly matters!
Note that software may implement an FSM, designed this way, though.
University of Manchester School of Computer Science
Datapath Design
The preceding diagram suggests that we need to be able to:
❏ keep a running total
❏ increment the total
❏ decrement the total
❏ compare the total with the maximum allowed capacity
ce sel add/sub Z
This suggests an RTL picture something like:
zero
max 1 detect
The data buses connecting the register, mux, mux b
adder and zero detector are all N bits wide
‘1’ 0 add/
where 2N > max. sub
total
register a
The ‘datapath’ is controlled by 3 input wires
(ce, sel and add/sub) and produces one
control output (Z).
Can you simplify the datapath to avoid (most of) the comparison?
(Hint: the car park occupancy data may be stored in a different way.)
Control Specification
The control FSM can now be defined more specifically:
inputs outputs
next
state
add
out
sel
full
state
ce
in
Z
1 0 x inc 0 x x 0
ready x 1 x dec1 0 x x 0
0 0 x ready 0 x x 0
inc x x x cmp 1 0 1 0
x x 0 ready 0 1 0 0
cmp
x x 1 full 0 1 0 0
x 0 x full 0 x x 1
full
x 1 x dec2 0 x x 1
dec1 x x x ready 1 0 0 0
dec2 x x x ready 1 0 0 0
Note:
❏ there is no initialisation procedure to ensure this system starts in a defined state
❏ each ‘in’ and ‘out’ event must be seen exactly once – this needs more thought
❏ we must assign a ‘number’ to each state before we can complete the logic design
Control Specification
The ‘first cut’ of the control specification takes the names of the various states Exercise
from the earlier ‘bubble’ diagram. Some states – for example inc – occur only Check that the value assigned to any ‘x’ in the output side of the table cannot
once because there is only one possible succeeding state; others - e.g. ready – affect the behaviour of the system.
have several possible successors.
Exercise
Verify that all possible input conditions are covered in the table.
System Initialisation
We must add control to ensure that the system starts from a known state; this must put the FSM
into a known state, but it must also reset the total count to zero.
We can also observe from the state transition table that the dec1 and dec2 states are identical and
can be merged, so we can now draw a bubble diagram with initialisation:
reset
reset
Note: decision
not full
zero
in
ready inc tot cmp
full
out out
dec tot full
This system loops in the ‘reset’ state (not shown!) decrementing the total (subtracting 1 from it) until
the total is zero, then it enters the ‘ready’ state and begins normal operation.
(An alternative would be to add a reset input to the total register.)
Initialisation
Reset Physical input and output devices
On the slide this (somewhat informal) notation Handling the physical input and output devices can often be a problem. There
has been used to show that the FSM remains in may be a wide variety of different sensors, actuators, etc. which are not neces-
reset the reset state until the zero input becomes sarily digital.
zero active. The assumption is made that the state is
unaltered unless otherwise shown. We will look a bit more at I/O later in the course. Here we will look at some
machinery to keep the problem separate from out control machine.
Strictly speaking the behaviour when the zero zero How can we sense the presence of a car at the car park entrance or exit?
input is inactive should also be shown explic-
itly. This tends to clutter the diagram, but it How can we control the barriers safely?
does give an added check that all behaviours How can we keep the system complexity under control?
reset
have been specified.
zero
System Partitioning
So far we have assumed that a car arriving (or leaving) does so in one state; this is unlikely!
However this is a a convenient abstraction – like to keep this model.
up
Let’s have a ‘barrier’ machine which handles the
up details of sensing cars and raising and lowering
raise the barrier.
car count
done
car Copies of this machine could be made for each
barrier.
waiting done
There is a functional bug in the complete system as described: can you spot it?
System Partitioning
This machine does not need a datapath as all its state is in the figure above.
The five states function as follows: reset full
❏ waiting remain idle until a car is sensed, then go to …
❏ raise raise barrier until sensor indicates it’s up, then go to … car car
❏ count signal main FSM that car is entering/leaving; raise datapath raise
only when the main FSM acknowledges, go to … in out
up up
❏ clear wait until the car is not sensed before going to … done done
lower lower
❏ lower lower barrier until sensor indicates it’s down down control down
and return to waiting state
This machine deals with the motors, actuators, sensors etc. and simplifies the
overall design by appropriate partitioning. The ability to reuse the same design
for both barriers is a bonus.
Exercises
It’s I/O is:
Can you add a payment system to the state diagram?
❏ car sense presence of a vehicle
❏ raise move barrier up (during ‘raise’ state)
❏ up barrier is fully raised
❏ lower move barrier down (during ‘lower’ state) Can you find the bug mentioned in the slide? (Not trivial!)
❏ down barrier is fully lowered
❏ in/out ready to count
❏ done count has been done
Can you suggest a solution?
Note: in this case ‘up’ and ‘down’ are separate because there is also a range of
intermediate positions.
University of Manchester School of Computer Science
Handshaking
The different state machines need to communicate.
❏ Assume a synchronous model: their clock is the same
❏ Sometimes need to synchronize states.
clk
done
in
up
This is a possible timing scenario from the barrier being raised to the car being counted.
Clearly it is important to register only a single ‘clean’ signal here, so the signal
must be “debounced”.
Several methods of debouncing are possible; perhaps the easiest way is to sam-
ple the signal periodically and wait until several sequential samples have the
Handshaking same value. The time/number of samples depends on the mechanical properties
of the switch; ~1ms is typical but for a specific application you should consult
Handshaking is a means of communicating between subsystems which the switch manufacturer’s data.
may be asynchronous, i.e. not always sharing the same clock.
For simple systems this sampling can be done in hardware, using flip-flops. In
The principle of handshaking is that one partner initiates a communication systems with a large number of switches this becomes prohibitively expensive
(in this case asserting req) and then waits for some sort of an acknowl- and a processor is usually used with the debounce being done in software. The
edgement. In this example req remains asserted until acknowledged by ‘classic’ example of this is a computer keyboard.
ack.
req
ack
University of Manchester School of Computer Science
State Assignment
Now, examine the full specification again
inputs outputs
next ❏ There are six states: need
doneout
state
donein
reset
add
out
sel
full
state (at least) 3 state bits
ce
in
Z
0 0 0 x 0 x x 0 0 0 ready ❏ States are assigned ‘numbers’
ready 0 x 1 x 0 x x 0 0 0 dec (binary codes)
0 1 0 x 0 x x 0 0 0 inc ❍ e.g. 000 for ‘ready’
inc 0 x x x 1 0 1 0 1 0 cmp
0 x x 0 0 1 0 0 0 0 ready ❍ choice is arbitrary, but …
cmp
0 x x 1 0 1 0 0 0 0 full
❏ Choice may make output
0 x 0 x 0 x x 1 0 0 full
full derivation easier
0 x 1 x 0 x x 1 0 0 dec
dec 0 x x x 1 0 0 0 0 1 ready ❏ Some legitimate codes may
x x x 0 1 0 0 0 1 1 reset be unused
reset
0 x x 1 1 0 0 0 1 1 ready
xxxx 1 x x x 0 x x 0 0 0 reset ❏ Outputs may be derived from
current state
(xxxx is used as shorthand for ‘any state’)
State Assignment
Assigning binary codes (numbers) to states is an arbitrary process, but sensible This needs an example. Consider the two outputs ‘ce’ and ‘add’:
choice can make the logic simpler. Even if the gate-level logic is generated auto-
matically using CAD tools (more on this later) a sensible choice can make the state ce add state coding
logic simpler and, probably, therefore smaller, faster and lower power.
ready 0 x 000
The first and only essential rule is that there must be enough bits to code for all
the states. Remember ‘N’ bits can code for up to 2N states: with this six state inc 1 1 111
machine 2 bits are insufficient, 3 bits will suffice. (More bits could be used; cmp 0 0 001
sometimes this is justifiable for later simplifications but we will not investigate
that here.) full 0 x 010
Note that there is some freedom in deciding what some outputs are. If we don’t dec 1 0 100
care about the datapath output in some state it doesn’t matter what it evaluates
reset 1 0 101
to. We only care if we are latching the output (‘ce’ is ‘true’) or the ‘Z’ flag needs
to be evaluated.
The state codings have been chosen so that their first two bits can be used as the
Can any of the state bits also be used as outputs? i.e. are any of the outputs ‘true’ two chosen outputs (except for the reset case we were ignoring). Note that the
for half of the states (or about half if not all the states are used)? state codings are all unique.
In this case, yes; there is enough freedom in outputs like ‘sel’ to choose patterns Let’s call the state bits ‘state<2:0>’
which obey this for the ‘don’t care (x) states.
ce = state<2> . reset
‘ce’ is another ‘obvious’ candidate although be careful reading the slide
because, for example, ‘ce’ can be ‘0’ in the ‘inc’ state if the ‘reset’ input is add = state<1>
asserted. However this can still help a bit; we’ll ignore ‘reset’ for a moment. The other outputs are not difficult to derive, now:
We can repeat this process of subdivision into halves if other outputs have the sel = state<2>
same property and are orthogonal – i.e. they divide our previous ‘halves; inde-
pendently. full = state<2> . state<1> . reset
donein = state<2> . state<0> . reset
Unused states
doneout = state<2> . state<1> . reset
In an example like this, three bits specify one of six states. Two states are
unused and should never occur. [We remembered the reset input again!]
It is normally good practice to ensure that, if these states are encountered,
they return to a defined state as soon as feasible.
The next state bits can also be derived in a similar fashion. However this is an
More on this topic later. illustration – let’s not get too deep into hand-designed logic here.
University of Manchester School of Computer Science
RTL Conclusions
We have seen how digital systems can be designed by splitting the functionality up into appropriate
areas and using different approaches for the different areas:
❏ Controller
❍ FSMs give a good representation of the flow of control in, and the behaviour of, a system
❍ state assignment can be arbitrary, but intelligent choice can simplify logic design
❍ the FSM can be combined with the state assignment in a state transition table
❍ logic equations can be read directly from the state transition table
❏ Datapath
❍ RTL modelling represents the movement of data around a system where the data has a
limited influence on the flow of control
❏ System
❍ the two approaches blend conveniently by connecting the RTL register and functional
control lines as FSM outputs, and using the results of data operations (e.g. compares)
as FSM inputs
This will be applied later in COMP10211 to the design of a general purpose processor for a
computer.
❏ A controller, which
❍ causes the datapath to fetch instructions
❍ receives and decodes these instructions
❍ causes the datapath to obey the instructions
Differences
❏ One (major) difference is the addition of a memory for storing more
values outside the Central Processing Unit (CPU).
❏ One (minor) difference here is that most of the Input and Output (I/O)
is dealt with as part of the memory; this allows the programmer access
in software.
More later …