18
1 1 Elec 326 Registers & Counters Registers & Counters Objectives This section deals with some simple and useful sequential circuits. Its objectives are to: Introduce registers as multi-bit storage devices. Introduce counters by adding logic to registers implementing the functional capability to increment and/or decrement their contents. Define shift registers and show how they can be used to implement counters that use the one-hot code. Reading Assignment Sections 4.4 and 5.4 2 Elec 326 Registers & Counters 1. Registers A register is a memory device that can be used to store more than one bit of information. A register is usually realized as several flip-flops with common control signals that control the movement of data to and from the register. Common refers to the property that the control signals apply to all flip-flops in the same way A register is a generalization of a flip-flop. Where a flip- flop stores one bit, a register stores several bits The main operations on a register are the same as for any storage devices, namely Load or Store: Put new data into the register Read: Retrieve the data stored in the register (usually without changing the stored data

Register dan Counter

Embed Size (px)

Citation preview

Page 1: Register dan Counter

1

1Elec 326 Registers & Counters

Registers & Counters ObjectivesThis section deals with some simple and useful sequential circuits. Its objectives are to:

Introduce registers as multi-bit storage devices.Introduce counters by adding logic to registers implementing the functional capability to increment and/or decrement their contents.Define shift registers and show how they can be used to implement counters that use the one-hot code.

Reading AssignmentSections 4.4 and 5.4

2Elec 326 Registers & Counters

1. Registers

A register is a memory device that can be used to store more than one bit of information. A register is usually realized as several flip-flops with common control signals that control the movement of data to and from the register.

Common refers to the property that the control signals apply to all flip-flops in the same way A register is a generalization of a flip-flop. Where a flip-flop stores one bit, a register stores several bits The main operations on a register are the same as for any storage devices, namely

Load or Store: Put new data into the registerRead: Retrieve the data stored in the register (usually without changing the stored data

Page 2: Register dan Counter

2

3Elec 326 Registers & Counters

Control SignalsWhen they are asserted, they initiate an action in the registerAsynchronous Control Signals cause the action to take place immediately Synchronous Control Signals must be asserted during a clock assertion to have an effect

ExamplesOn the following three registers, which control signals are asynchronous and which are synchronous? How are the control signals asserted?

4Elec 326 Registers & Counters

D Q

QCLR

STO

D0

D1

Dn-1 Qn-1

Q0

Q1

D Q

QCLR

D Q

QCLR

CLR

module reg1 (STO, CLR, D, Q);parameter n = 16;input STO, CLR;input [n-1:0] D;output [n-1:0] Q;reg [n-1:0] Q;

always @(posedge STO or negedge CLR)if (CLR ==0) Q <= 0;else Q <= D;

endmodule

Page 3: Register dan Counter

3

5Elec 326 Registers & Counters

J Q

QK

J Q

QK

J Q

QK

D0

D1

Dn-1 Qn-1

Q0

Q1

LD

CLKCLR

OE

6Elec 326 Registers & Counters

D Q

Q

D Q

Q

D Q

QD0

D1

Dn-1

Qn-1

Q0

Q1

LD

CLKCLR

OE

Page 4: Register dan Counter

4

7Elec 326 Registers & Counters

Verilog description of previous two registers

module reg2 (CLK, CLR, LD, OE, D, Q);parameter n = 4;input CLK, CLR, LD, OE;input [n-1:0] D;output [n-1:0] Q;reg [n-1:0] IQ, Q;integer k;

always @(posedge CLK)if (CLR) IQ <= 0;else if (LD) IQ <= D;

always @(OE)if (OE) Q = IQ;else Q = 'bz;

endmodule

8Elec 326 Registers & Counters

2. CountersA counter is a register capable of incrementing and/or decrementing its contents

Q ← Q plus nQ ← Q minus n

The definition of "plus" and "minus" depend on the way the register contents encode the integersBinary Counters: Encode the integers with the binary number code

Page 5: Register dan Counter

5

9Elec 326 Registers & Counters

Example: 3-bit binary counter:

What does the counter count?The output signals are just the state variables

0 0 00 0 10 1 00 1 11 0 01 0 11 1 01 1 10 0 0

minus

plus

•••

Count Sequence

0 0 00 0 10 1 00 1 11 0 01 0 11 1 01 1 1

0 0 10 1 00 1 11 0 01 0 11 1 01 1 10 0 0

Transistion Table

01234567

12345670

State Table

10Elec 326 Registers & Counters

Example: 3-bit binary up/down counter

Example: Binary mod 6 counter

0 0 00 0 10 1 00 1 11 0 01 0 11 1 01 1 1

1 1 10 0 00 0 10 1 00 1 11 0 01 0 11 1 0

TransistionTable

0 0 10 1 00 1 11 0 01 0 11 1 01 1 10 0 0

0 1

0 0 00 0 10 1 00 1 11 0 01 0 11 1 01 1 1

0 0 10 1 00 1 11 0 01 0 10 0 0x x xx x x

Transistion Table

0 1 2

345

State Diagram

Page 6: Register dan Counter

6

11Elec 326 Registers & Counters

Design of a Binary Up Counter

Qi toggles on every clock cycle where Qj = 1, for i > j ≥ 0

12Elec 326 Registers & Counters

Binary Up Counter

1

J Q

QK

CK

J Q

QK

J Q

QK

J Q

QK

Page 7: Register dan Counter

7

13Elec 326 Registers & Counters

Design of a Binary Down Counter

Qi toggles on every clock cycle where Qj = 0, for i > j ≥ 0

14Elec 326 Registers & Counters

Binary Down Counter

Page 8: Register dan Counter

8

15Elec 326 Registers & Counters

Synchronous, Series-Carry Binary Counter

1

CK

Q0 Q1 Q2 Q3J Q

QK

J Q

QK

J Q

QK

J Q

QK

TW ≥ tPFF + (n-2)tPG + tsu (for n≥2)

tsu

CKTW

Q3

Q2

Q1

Q0 = JK1

Q=14 Q=15 Q=0

JK2

JK3

tPFF

tPG

tPG

16Elec 326 Registers & Counters

Synchronous, Parallel-Carry Binary Counter

1

CK

Q0 Q1 Q2 Q3J Q

QK

J Q

QK

J Q

QK

J Q

QK

TW ≥ tPFF + tPG + tsu (for n≥3)

CKTW

Q3Q2

Q1Q0 = JK1

Q=14 Q=15 Q=0

JK2

JK3

tPFF

tPG

tPG

tsu

Page 9: Register dan Counter

9

17Elec 326 Registers & Counters

Asynchronous Counters

Typical MSI counter chip

LD and CLR are synchronousLD asserted during the rising edge of the clock loads the register from ABCD.CLR asserted during the rising edge of the clock clears the counterCLR overrides LDLD overrides ENRCO = QD•QC • QB • QA • ENT, used for cascading chips

CKJ Q

QK

J Q

QK

J Q

QK

J Q

QK

1

1

1

1

1

11

1

CLRLDENPENTABCD

RCO

QAQBQCQD

74LS163

18Elec 326 Registers & Counters

Verilog description of the 74x163

module V74x163 (CLK, CLR_L, LD_L, ENP, ENT, D, Q, RCO);input CLK, CLR_L, LD_L, ENP, ENT;input [3:0] D;output RCO;output [3:0] Q;reg [3:0] Q;reg RCO;

always @(posedge CLK)if (CLR_L == 0) Q <= 4'b0000;else if (LD_L == 0) Q <= D;else if (ENT & ENP) Q <= Q +1;

always @(Q or ENT)if (Q == 15 && ENT == 1) RCO = 1;else RCO = 0;

endmodule

Page 10: Register dan Counter

10

19Elec 326 Registers & Counters

Verilog description of an up/down counter

module updowncount (R, Clock, L, E, up_down, Q);parameter n = 8;input [n-1:0] R;input Clock, L, E, up_down;output [n-1:0] Q;reg [n-1:0] Q;integer direction;

always @(posedge Clock)begin

if (up_down) direction = 1;else direction = -1;if (L) Q <= R;else if (E) Q <= Q + direction;end

endmodule

-

20Elec 326 Registers & Counters

Verilog description of mod-n counters

module upmodn (Ck, Q);parameter n = 6;input Ck;output [3:0] Q;reg [3:0] Q;

always @(posedge Ck)if (Q == n)

Q <= 0;else

Q <= Q + 1;

endmodule

module dwnmodn (Ck, Q);parameter n = 5;input Ck;output [3:0] Q;reg [3:0] Q;

always @(posedge Ck)if (Q == 0)

Q <= n;else

Q <= Q -1;endmodule

Page 11: Register dan Counter

11

21Elec 326 Registers & Counters

Design of Mod n CountersMod 6 Up Counter

Mod 5 Down Counter

CK

Q0

Q1Q2

0 1 2 3 4 5 0 1 2/CLR

CK

Q0

Q1

Q2

01234 234/LD

CLRLDENPENTABCD

RCO

QAQBQCQD

74LS163CLK

11

1

U/DLDENPENTABCD

RCO

QAQBQCQD

74LS169CLK

0

0000

01

22Elec 326 Registers & Counters

Decoding Binary Counter States

The decoding spikes are hazzards that can not be designed outThe following circuit will mask the decoding spikes, at the cost of delaying the outputs one clock cycle.

QAQBQC

ABC

Y0Y1Y2Y3Y4Y5Y6Y7

/S0/S1/S2/S3/S4/S5/S6/S7

CK

Q0

Q1

Q2

/S0

/S1

/S2

CLK

REGQAQBQC

ABC

Y0Y1Y2Y3Y4Y5Y6Y7

Page 12: Register dan Counter

12

23Elec 326 Registers & Counters

3. Shift Registers

How would you add a control signal to control when the shift register shifted?How would you add parallel input capability and why would you want to?

What kind of control signals are needed?Is the shift register drawn above a left shifter or a right shifter?How would you make a shift register that could shift either left or right and what control signals would you need?

24Elec 326 Registers & Counters

Example: 74LS194

Shift left is from A to DShift right is from D to ACLR is asynchronous

CLR

S0S1

RIN

LINDBCA

QDQCQBQA

S1 S0 QA* QB* QC* QD*0011

0101

holdshift rightshift leftload

QA RINQBA

QBQA QCB

QCQB QDC

QDQC LIND

Action

Page 13: Register dan Counter

13

25Elec 326 Registers & Counters

Verilog Description Of A Shift Registermodule shift4 (D, LD, LI, Ck, Q);

input [3:0] D;input LD, LI, Ck;output [3:0] Q;reg [3:0] Q;

always @(posedge Ck)if (LD)

Q <= D;elsebegin

Q[0] <= Q[1];Q[1] <= Q[2];Q[2] <= Q[3];Q[3] <= LI;

end

endmodule

26Elec 326 Registers & Counters

Ring Counters

Page 14: Register dan Counter

14

27Elec 326 Registers & Counters

Self-Correcting Ring Counter

28Elec 326 Registers & Counters

Johnson counter, switch-tail counter, moebius counter

Page 15: Register dan Counter

15

29Elec 326 Registers & Counters

Self-Correcting Johnson Counter

Odd Length Johnson Counter

This counter is also self-correcting

0001

1000 1110

01110011

11000000

30Elec 326 Registers & Counters

4. Review

Register control signals and assertions.Binary counters and their operations.

Reset, Load, Output Enable.Counter timing; maximum clock frequency.

Mod-n counters Synchronous vs. asynchronous load and reset signals.

Shift registers and shift register counters.Ring counters, Johnson counters, etcSelf-correcting counters

Counter realization of sequential circuits

Page 16: Register dan Counter

Registers & Counters

1. Registers

Sebuah register adalah perangkat memori yang dapat digunakan untuk

menyimpan informasi lebih dari satu bit.

Sebuah register biasanya merupakan beberapa flip-flop dengan sinyal kontrol

umum yang mengontrol pergerakan data dari dan ke register.

Secara umum, perangkat ini memiliki sinyal kontrol yang memasang semua

flip-flop di jalur yang sama.

Sebuah register adalah bentuk generalisasi dari sebuah flip-flop. Di mana

sebuah flip-flop menyimpan satu bit, sebuah register menyimpan beberapa

bit.

Operasi utama dalam sebuah register untuk perangkat penyimpanan

apapun adalah sama, yang disebut

Load atau Store: Menyimpan data baru ke dalam register

Read: Mendapatkan kembali data yang tersimpan di dalam register

(biasanya tanpa mengubah data yang tersimpan)

Sinyal Kontrol

Ketika sinyal kontrol dinyatakan, mereka menginisiasi aksi di dalam register

Asynchronous Control Signals menyebabkan aksi untuk segera dilaksanakan

Synchronous Control Signals harus dinyatakan selama pernyataan untuk

mendapatkan efek

2. Counters

Sebuah counter adalah sebuah register yang mampu meningkatkan dan/atau

menurunkan isinya

Q Q plus n

Q Q minus n

Definisi “plus” dan “minus” bergantung pada jalur yang digunakan isi

register untuk menyandikan bilangan bulat

Binary Counters: Menyandikan bilangan bulat dengan kode bilangan biner

Desain dari sebuah Binary Up Counter

Page 17: Register dan Counter

Q0 berubah setiap siklus waktu

Q1 berubah setiap siklus waktu saat Q0=1

Q2 berubah setiap siklus waktu saat Q0=Q1=1

Qi berubah setiap siklus waktu saat Qj = 1, selama i > j >= 0

Desain dari sebuah Binary Down Counter

Q0 berubah setiap siklus waktu

Q1 berubah setiap siklus waktu saat Q0=0

Q2 berubah setiap siklus waktu saat Q0=Q1=0

Qi berubah setiap siklus waktu saat Qj = 0, selama i > j >= 0

Page 18: Register dan Counter

MSI counter chip Tipikal

LD dan CLR saling sinkron.

LD dinyatakan selama pinggir atas dari jam memuat register dari

ABCD.

CLR dinyatakan selama pinggir atas dari jam membersihkan counter

CLR bertolakan dengan LD

LD bertolakan dengan EN

RCO = QD . QC . QB . QA . ENT, digunakan untuk chip yang mengalir.

Decoding Binary Counter States

Penghentian pemecahan kode sangat berisiko yang tak dapat didesain

Sirkuit berikut akan menutupi penghentian pemecahan kode, dengan

membutuhkan penundaan keluaran selama satu siklus waktu.