Вы находитесь на странице: 1из 43

DIGITAL LOGIC DESIGN

(DLD)

Lecture # 12

Registers, Counters

UMT SIALKOT

REGISTERS

Today well see another common sequential device:


registers.

Theyre a good example of sequential analysis and design.

They are also frequently used in building larger sequential


circuits.

Registers hold larger quantities of data than

individual flip-flops.

Registers are central to the design of modern processors.

There are many different kinds of registers.

Well show some applications of these special registers.

WHAT GOOD ARE REGISTERS?

Flip-flops are limited because they can store only


one bit.
We

had to use two flip-flops for our two-bit counter

examples.
Most

computers work with integers and single-

precision floating-point numbers that are 32-bits


long.

A register is an extension of a flip-flop that can


store multiple bits.

WHAT GOOD ARE REGISTERS?

Registers are commonly used as temporary


storage in a processor.
They

are faster and more convenient than main

memory.
More

registers can help speed up complex

calculations.

Well discuss RAM next time, and later well also


see how registers are used in designing and
programming CPUs.

A BASIC REGISTER

Basic registers are easy to build. We can store


multiple bits just by putting a bunch of flip-flops
together!

A 4-bit register from Logic Works, Reg-4, is on


the right, and its internal implementation is
below.
This

register uses D flip-flops, so its easy to store

data without worrying about flip-flop input


equations.
All

the flip-flops share a common CLK and CLR

signal.

A BASIC REGISTER

A BASIC REGISTER

A simple 4-bit register


can be made with 4 DFF
Common Clock

At each positive-edge, 4
bits are loaded in
parallel
Previous data is
overwritten

I0

Asynchronous clear
When Clear = 0, all FFs
are cleared; i.e. 0 is
stored.

A0

A1

A2

A3

R
I1

D
R

I2

D
R

Common Clear

I3
CLK
Reset

D
R

ADDING A PARALLEL LOAD


OPERATION

The input D3-D0 is copied to the output Q3-Q0 on


every clock cycle.

How can we store the current value for more than


one cycle?

Lets add a load input signal LD to the register.


If

LD = 0, the register keeps its current contents.

If

LD = 1, the register stores a new value, taken from

inputs D3-D0.

ADDING A PARALLEL LOAD


OPERATION

LD
0
1

Q(t+1)
Q(t)
D3-D0

CLOCK GATING

We could implement the load ability by playing


games with the CLK input, as shown below.
When

LD = 0, the flip-flop C inputs are held at 1.

There is no positive clock edge, so the flip-flops keep


their current values.
When

LD = 1, the CLK input passes through the OR

gate, so the flip-flops can receive a positive clock edge


and can load a new value from the D3-D0 inputs.

CLOCK GATING

CLOCK GATING IS BAD

This is called clock gating, since gates are added to


the clock signal.

There are timing problems similar to those of latches.


Here, LD must be kept at 1 for the correct length of
time (one clock cycle) and no longer.

The clock is delayed a little bit by the OR gate.

In more complex scenarios, different flip-flops in the system


could receive the clock signal at slightly different times.

This clock skew can lead to synchronization problems.

SHIFT REGISTERS

A shift register shifts its output once every clock cycle.

Q0(t+1) = SI
Q1(t+1) = Q0(t)
Q2(t+1) = Q1(t)
Q3(t+1) = Q2(t)

SHIFT REGISTERS

SI is an input that supplies a new bit to shift into the


register.

For example, if on some positive clock edge we have:


SI = 1
Q0-Q3 = 0110
then the next state will be:
Q0-Q3 = 1011

The current Q3 (0 in this example) will be lost on the next


cycle.

SHIFT DIRECTION

The circuit and example make it look like the


register shifts right.

Present Q0-Q3
ABCD

SI
X

Next Q0-Q3
XABC

SHIFT DIRECTION

But it really depends on your interpretation of


the bits. If you consider Q3 to be the most
significant bit instead, then the register is
shifting in the opposite direction!

Present Q3-Q0
DCBA

SI
X

Next Q3-Q0
CBAX

TYPES OF SHIFT REGISTERS


Logical

shifts Standard shifts like


we just saw. In the absence of a SI
input, 0 occupies the vacant position.
Left:

0110 -> 1100


Right: 0110 -> 0011

TYPES OF SHIFT REGISTERS


Circular

shifts (also called ring


counters or rotates) The shifted out
bit wraps around to the vacant
position.
Left:

1001 -> 0011


Right: 1001 -> 1100

SERIAL DATA TRANSFER

One application of shift registers is converting


between serial data and parallel data.

Computers

typically

work

with

multiple-bit

quantities.
ASCII

text characters are 8 bits long.

Integers,

single-precision floating-point numbers, and

screen pixels are up to 32 bits long.

SERIAL DATA TRANSFER

But sometimes its necessary to send or receive data


serially, or one bit at a time. Some examples include:
Input

devices such as keyboards and mice.

Output
Any

devices like printers.

serial port, USB or Fire-wire device transfers data serially.

Recent

switch from Parallel ATA to Serial ATA in hard drives.

RECEIVING SERIAL DATA

To receive serial data using a shift register:

The serial device is connected to the registers SI input.

The shift register outputs Q3-Q0 are connected to the computer.

The serial device transmits one bit of data per clock cycle.

These bits go into the SI input of the shift register.

After four clock cycles, the shift register will hold a four-bit word.

The computer then reads all four bits at once from the Q3-Q0

computer

SUMMARY

A register is a special state machine that stores multiple bits of data.

Several variations are possible:

Parallel loading to store data into the register.

Shifting the register contents either left or right.

Counters are considered a type of register too!

One application of shift registers is converting between serial and


parallel data.

Most programs need more storage space than registers provide.

Well introduce RAM to address this problem.

Registers are a central part of modern processors, as we will see in


coming weeks.

COUNTERS

Counters are a specific type of sequential circuit.

Like registers, the state, or the flip-flop values


themselves, serves as the output.

The output value increases by one on each clock


cycle.

After the largest value, the output wraps


around back to 0.

COUNTERS

Using two bits, wed get something like this:

Present State
A
B
0
0
1
1

0
1
0
1

Next State
A
B
0
1
1
0

1
0
1
0

00

1
11

01
1

10

BENEFITS OF COUNTERS

Counters can act as simple clocks to keep track of time.

You may need to record how many times something has


happened.

How many bits have been sent or received?

How many steps have been performed in some computation?

All processors contain a program counter, or PC.

Programs consist of a list of instructions that are to be executed one


after another (for the most part).

The PC keeps track of the instruction currently being executed.

The PC increments once on each clock cycle, and the next program
instruction is then executed.

ASYNCHRONOUS COUNTERS

This counter is called asynchronous because not


all flip flops are hooked to the same clock.

Look at the waveform of the output, Q, in the


timing diagram. It resembles a clock as well. If
the period of the clock is T, then what is the
period of Q, the output of the flip flop? It's 2T!

ASYNCHRONOUS COUNTERS

ASYNCHRONOUS COUNTERS
If the clock has period T. Q0 has period 2T. Q1
period is 4T
With n flip flops the period is 2n.

SYNCHRONOUS COUNTERS

To eliminate the "ripple" effects, use a common clock for each


flip-flop and a combinational circuit to generate the next
state.
For an up-counter,
use an incrementer =>
Incremente
S3
A3
r

Clock

D3 Q3

A2

S2

D2 Q2

A1

S1

D1 Q1

A0

S0

D0 Q0

FINITE STATE MACHINE (FSM)


DESIGN
MEALY AND MOORE DESIGN

FSMs are different from counters in the sense


that they have external

I/Ps, and state transitions are dependent on


these I/Ps and the current

state.

MEALY AND MOORE DESIGN

We're going to implement Mealy and Moore


machines. These are finite state machines with
output.

AMealymachine has outputs that depend on the


state and input (thus, the FSM has the output
written on edges)

AMooremachine has outputs that depend on


state only (thus, the FSM has the output written
in the state itself)

EXAMPLE : PROBLEM STATEMENT


There is a bit-serial I/P line. Design an FSM that
outputs a 0 if an even # of 1s have been received
on the I/P line and the outputs a 1 otherwise.
Note : If a synchronous sequential circuit is being
designed, the counting of the # of 1s occur every
clock cycle.

SOLUTION 1: (MEALY)

SOLUTION 2: (MOORE)

DIFFERENCE BETWEEN MEALY AND MOORE MACHINE

WHAT IS RAM?

RAM is extra memory that provides space for the


Central Processing Unit (CPU) to read and write
data.

The more RAM your computer has, the less the


CPU has to read data from your hard disk. This
usually allows your computer to run faster since
RAM is faster than the hard disk.

INTRODUCTION TO RAM

Random-access

memory,

or

RAM,

provides

large

quantities of temporary storage in a computer system.

Remember the basic capabilities of a memory:

It should be able to store a value.

You should be able to read the value that was saved.

You should be able to change the stored value.

A RAM is similar, except that it can store many values.

An address will specify which memory value were interested


in.

Each value can be a multiple-bit word (e.g., 32 bits).

ABOUT RAM

Ram is volatile, meaning is does not retain data


when the electric power is turned off or fails, so if
you turn of your computer, all memory stored in
RAM is lost.

When your computer is turned on again, the BIOS


reads your operating system and related files from
the hard disk and loads them back into RAM.

ABOUT RAM CONT.

RAM stores its data in a series of memory cells


that can be accessed in any order, thus why it is
called Random.

SAM (serial access memory) is much the same as


RAM, but can only access its memory cells in a
specific order.

PICTURE OF MEMORY

You can think of computer memory as being


one big array of data.

The address serves as an array index.

Each address refers to one word of data.

You can read or modify the data at any given


memory address, just like you can read or
modify the contents of an array at any given
index.

If youve worked with pointers in C or C++,


then youve already worked with memory
addresses.

Address
00000000
00000001
00000002
.
.
.
.
.
.
.
.
.
.
FFFFFFFD
FFFFFFFE
FFFFFFFF

Data

CACHE MEMORY
A

cache is a block of memory for temporary storage

of data likely to be used again. The CPU and hard


drive frequently use a cache, as do web browsers
and web servers.
A

cache is made up of a pool of entries. Each entry

has a datum (a nugget of data) which is a copy of


the datum in some backing store. Each entry also
has a tag, which specifies the identity of the datum
in the backing store of which the entry is a copy.

HOW RAM WORKS


RAM

generally stores its bits of information in a state

of electronic flip-flop (SRAM), which requires a ground


connection, or as a charge in capacitors (DRAM).
RAM

is needed whenever you want to perform an

operation on your computer. Ex: When you type on


Word, each letter is temporarily recorded in a file in
RAM. Again, if the power to the RAM is cut off, there
is little to no chance that the memory stored on RAM
at the time the power was lost will still be there.

HOW RAM WORKS CONT.

If you have multiple programs running at once, and


they start running slower and slower, your RAM is
probably reaching its limits. If you were to reach
the limit, which is hard to do if youre just using
your

computer

normally,

your

computer

will

probably just shut down. Ex: Bens Macro.

Background programs, such as operating system


updates, also take up RAM.

Вам также может понравиться