eet3350lec15 counters

64
1 EET 3350 Digital Systems Design Textbook: John Wakerly Chapter 8: 8.4 Counters

Upload: frg2410

Post on 08-Apr-2015

738 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: EET3350Lec15 Counters

1

EET 3350 Digital Systems Design

Textbook: John WakerlyChapter 8: 8.4

Counters

Page 2: EET3350Lec15 Counters

Agenda for Today

• Counters – Definition– Types– Characteristics

• Asynchronous Counters• Synchronous Counters• MSI Counters

– Especially the 74LS163

• Counters in VHDL• Other Counter Types

2

Clock Count

optional inputs

Counter

Sm

S1 S2S3

S4S5

Page 3: EET3350Lec15 Counters

Counters

• A counter is a circuit that produces a numeric count each time an input clock pulse makes an active transition

3

Clock Count

optional inputs

Counter

Load an initial value, reset Load an initial value, reset to starting count, etc.to starting count, etc.

May also enable count, May also enable count, select direction, etc.select direction, etc.

Page 4: EET3350Lec15 Counters

Counter• From another viewpoint, a counter is any sequential

circuit whose state diagram is a single cycle– in other words, counters are a special case of a finite state

machine

• Output is usually the state value, Moore machine

4

Sm

S1 S2S3

S4

S5

EN EN

EN

ENEN

EN

RESET

EN

EN

EN EN

EN

ENEN

Page 5: EET3350Lec15 Counters

5

Counters

Characteristic Description

Modulus Length of sequence

Coding Count sequence

Direction Up or down

Resetable Reset to zero

Loadable Load a specific value

• Counters differ by a number of basic characteristics, including:

Page 6: EET3350Lec15 Counters

Counters

• Applications include:– system clock– timer, delays– watches, clocks, alarms– counting events– memory addressing – frequency division – sequence control– cycle control– protocols

6

Present State Next State A B A B

0 0 0 1 0 1 1 0 1 0 1 1 1 1 0 0

00 01

1011

Page 7: EET3350Lec15 Counters

Counter Types

• Asynchronous– Ripple

• Synchronous– Clocked

• Modulus – Binary– Decade – etc.

• Ring • Johnson

– Twisted ring

• Up/Down• LFSR

7

001

010

011

100

101

000

Page 8: EET3350Lec15 Counters

Counters

• Some examples of modulus and coding sequence for counters

8

Page 9: EET3350Lec15 Counters

Counters

• Modulus– number of states in a counter’s cycle

• Given m states– modulo-m counter or divide-by-m counter

• Power-of-2 counters use all states• Non-power-of-2 counters have extra, unused

states

9

Sm

S1 S2S3

S4

S5

Page 10: EET3350Lec15 Counters

10

Example 4-bit Counters

• 4-bit Binary / Hex / Mod-16 Counter– 0000, 0001, 0010, … 1110, 1111, 0000, 0001, …

• 4-bit BCD / Decade / Mod-10 Counter– 0000, 0001, 0010, … 1000, 1001, 0000, 0001, …

• 4-bit Ring Counter– 1000, 0100, 0010, 0001, 1000, 0100, …

all states used

six unused states

twelve unused states

Page 11: EET3350Lec15 Counters

Counters

• Ripple counters– asynchronous– an n-state counter that is formed from n cascaded

flip-flops – the clock input to each of the individual flip-flops,

with the exception of the first, is taken from the output of the preceding one

– the count thus ripples along the counter's length due to the propagation delay associated with each stage of counting

11

Page 12: EET3350Lec15 Counters

Asynchronous Ripple Counter

Q3 Q2 Q1 Q0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0

Q0

Q1

Q2

Q3

...

12

Page 13: EET3350Lec15 Counters

Ripple Counter Timing• The ideal count sequence for the ripple counter

yields the timing diagram below

13

Q0

Q1

Q2

Q3

Q0 Q1 Q2 Q3

CLOCK

Page 14: EET3350Lec15 Counters

Ripple Counter Timing

CLK

Q0

0 1 2 3 4

1

2

3Q2

Q1

• But there is delay ( ) as shown below:

14

Page 15: EET3350Lec15 Counters

Asynchronous Ripple Counter

Q0

Q1

Q2

Q3

15

divide-by-2

divide-by-4

divide-by-8

divide-by-16

a T flip-flop is a a T flip-flop is a natural frequency natural frequency divider …divider …

Page 16: EET3350Lec15 Counters

Synchronous Counters

• Asynchronous counters are easy to understand, but avoid their use– slow, limited by propagation delays– error prone

• Characteristics of synchronous counters– use a common clock pulse to trigger all flip-flops

simultaneously– have a higher clock speed– hardware is more complex but more reliable

16

Page 17: EET3350Lec15 Counters

17

LSB

MSB

Synchronous counter

serial enable logic

4-Bit Counter

Page 18: EET3350Lec15 Counters

18

Synchronous counter

LSB

MSB

parallel enable logic

4-Bit Counter

Page 19: EET3350Lec15 Counters

MSI Counters

• Counters can be built from individual SSI Flip-Flops, e.g.,– 7470– 7474– 7479

• Counters may also be built using MSI components– 74x90, 74x92, 74x93– 74x160, 74x161, 74x162, 74x163– 74x168, 74x169– 74x190, 74x191– 74x196, 74x197

19

and many others …

74x163

we’ll look at this onewe’ll look at this one

D1 D2

Page 20: EET3350Lec15 Counters

MSI Counter

• 4-bit synchronous counter– edge-triggered– synchronously

presettable– cascadable

• Typical Count Rate of 35 MHz

• ‘160 and ‘162, Mod-10• ‘161 and ‘163, Mod-16

20

Page 21: EET3350Lec15 Counters

MSI Counter

• 74LS163 4-bit synchronous counter

21

16-pin DIP16-pin DIP

Page 22: EET3350Lec15 Counters

MSI Counter

• 74LS163 characteristics– edge-triggered– synchronously presettable– cascadable– count modulo 16 (binary)

• Synchronous Reset (Clear) input that overrides all other control inputs– active only during the rising

clock edge

22

74x163

Page 23: EET3350Lec15 Counters

MSI Counter

• 74LS163 logic symbols

23

74x163texttext

datasheetdatasheet

Page 24: EET3350Lec15 Counters

MSI Counter

• 74LS163 state diagram and logic equations

24

Page 25: EET3350Lec15 Counters

MSI Counter

• 74LS163 mode select table• All signals must be high ( H ) to enable the

count sequence to begin

25

Page 26: EET3350Lec15 Counters

MSI Counter• 74x163 is a synchronous

4-bit binary counter• RCO=1 when all count

bits are 1 and ENT is asserted

26

Page 27: EET3350Lec15 Counters

MSI Counter

• The control inputs for the 74x163 have the following effects:

27

clear

loadhold

hold

Page 28: EET3350Lec15 Counters

MSI Counters• 7458: Dual 4-bit Decade Counter

• 7459: Dual 4-bit Binary Counter

• 7468: Dual 4 Bit Decade or Binary Counters

• 7469: Dual 4 Bit Decade or Binary Counters

• 7490: Decade Counter (separate Divide-by-2 and Divide-by-5 sections)

• 7492: Divide-by-12 Counter (separate Divide-by-2 and Divide-by-6 sections)

• 7493: 4-bit Binary Counter (separate Divide-by-2 and Divide-by-8 sections)

• 74142: Decade Counter/Latch/Decoder/Nixie Tube Driver

• 74143: Decade Counter/Latch/Decoder/7-segment Driver, 15 mA Constant Current

• 74144: Decade Counter/Latch/Decoder/7-segment Driver, 15V open collector outputs

• 74160: Synchronous 4-bit Decade Counter with Asynchronous Clear

• 74161: Synchronous 4-bit Binary Counter with Asynchronous Clear

• 74162: Synchronous 4-bit Decade Counter with Synchronous Clear

• 74163: Synchronous 4-bit Binary Counter with Synchronous Clear

• 74168: Synchronous 4-Bit Up/Down Decade Counter

• 74169: Synchronous 4-Bit Up/Down Binary Counter

• 74176: Presettable Decade (Bi-Quinary) Counter/Latch

• 74177: Presettable Binary Counter/Latch

• 74190: Synchronous Up/Down Decade Counter

• 74191: Synchronous Up/Down Binary Counter

• 74192: Synchronous Up/Down Decade Counter with Clear

• 74193: Synchronous Up/Down Binary Counter with Clear

• 74196: Presettable Decade Counter/Latch

• 74197: Presettable Binary Counter/Latch

• 74290: Decade Counter (separate divide-by-2 and divide-by-5 sections)

• 74291: 4-bit Universal Shift register, Binary Up/Down Counter, Synchronous

• 74293: 4-bit Binary Counter (separate divide-by-2 and divide-by-8 sections)

• 74390: Dual 4-bit Decade Counter

• 74393: Dual 4-bit Binary Counter

• 74452: Dual Decade Counter, Synchronous

• 74453: Dual Binary Counter, Synchronous

• 74454: Dual Decade Up/Down Counter, Synchronous, Preset Input

• 74455: Dual Binary Up/Down Counter, Synchronous, Preset Input

• 74461: 8-bit Presettable Binary Counter with three-state outputs

• 74490: Dual Decade Counter

• 74491: 10-bit Binary Up/Down Counter with Limited Preset and three-state logic outputs

• 74560: 4-bit Decade Counter with three-state outputs

• 74561: 4-bit Binary Counter with three-state outputs

• 74568: Decade Up/Down Counter with three-state outputs

• 74569: Binary Up/Down Counter with three-state outputs

• 74590: 8-Bit Binary Counter with Output Registers and three-state outputs

• 74592: 8-Bit Binary Counter with Input Registers

• 74593: 8-Bit Binary Counter with Input Registers and three-state outputs

• 74668: Synchronous 4-bit Decade Up/Down Counter

• 74669: Synchronous 4-bit Binary Up/Down Counter

• 74690: 4-bit Decimal Counter/Latch/Multiplexer with Asynchronous Reset, Three-State Outputs

• 74691: 4-bit Binary Counter/Latch/Multiplexer with Asynchronous Reset, Three-State Outputs

• 74692: 4-bit Decimal Counter/Latch/Multiplexer with Synchronous Reset, Three-State Outputs

• 74693: 4-bit Binary Counter/Latch/Multiplexer with Synchronous Reset, Three-State Outputs

• 74694: 4-bit Decimal Counter/Latch/Multiplexer with Synchronous and Asynchronous Resets, three-state outputs

• 74695: 4-bit Binary Counter/Latch/Multiplexer with Synchronous and Asynchronous Resets, three-state outputs

• 74696: 4-bit Decimal Counter/Register/Multiplexer with Asynchronous Reset, three-state outputs

• 74697: 4-bit Binary Counter/Register/Multiplexer with Asynchronous Reset, three-state outputs

• 74698: 4-bit Decimal Counter/Register/Multiplexer with Synchronous Reset, three-state outputs

• 74699: 4-bit Binary Counter/Register/Multiplexer with Synchronous Reset, three-state outputs

• 74716: Programmable Decade Counter

• 74718: Programmable Binary Counter

28

Page 29: EET3350Lec15 Counters

Counters in VHDL

• VHDL code for a 74x163 like 4-bit binary counter

29

library IEEE;use IEEE.std_logic_1164.all;use IEEE.std_logic_arith.all;

entity V74x163 isport ( CLK, CLR_L, LD_L, ENP, ENT: in STD_LOGIC; D: in UNSIGNED (3 downto 0); Q: out UNSIGNED (3 downto 0); RCO: out STD_LOGIC );end V74x163;

architecture V74x163_arch of V74x163 issignal IQ: UNSIGNED (3 downto 0);beginprocess (CLK, ENT, IQ) begin if (CLK'event and CLK='1') then if CLR_L='0' then IQ <= (others => '0'); elsif LD_L='0' then IQ <= D; elsif (ENT and ENP)='1' then IQ <= IQ + 1; end if; end if; if (IQ=15) and (ENT='1') then RCO <= '1'; else RCO <= '0'; end if; Q <= IQ; end process;end V74x163_arch;

Page 30: EET3350Lec15 Counters

Counters in VHDL

• VHDL code for counting in the excess-3 sequence

30

library IEEE;use IEEE.std_logic_1164.all;use IEEE.std_logic_arith.all;

entity V74xs3 is port ( CLK, CLR_L, LD_L, ENP, ENT: in STD_LOGIC; D: in UNSIGNED (3 downto 0); Q: out UNSIGNED (3 downto 0); RCO: out STD_LOGIC );end V74xs3;

architecture V74xs3_arch of V74xs3 issignal IQ: UNSIGNED (3 downto 0);beginprocess (CLK, ENT, IQ) begin if CLK'event and CLK='1' then if CLR_L='0' then IQ <= (others => '0'); elsif LD_L='0' then IQ <= D; elsif (ENT and ENP)='1' and (IQ=12) then IQ <= ('0','0','1','1'); elsif (ENT and ENP)='1' then IQ <= IQ + 1; end if; end if; if (IQ=12) and (ENT='1') then RCO <= '1'; else RCO <= '0'; end if; Q <= IQ; end process;end V74xs3_arch;

Page 31: EET3350Lec15 Counters

Counters in VHDL

• Component of the previous code

31

library IEEE;use IEEE.std_logic_1164.all;

entity Vdffqqn is port( CLK, D: in STD_LOGIC; Q, QN: out STD_LOGIC );end Vdffqqn;

architecture Vdffqqn_arch of Vdffqqn isbeginprocess(CLK) begin if (CLK'event and CLK='1') then Q <= D; QN <= not D; end if; end process;end Vdffqqn_arch;

Page 32: EET3350Lec15 Counters

Counters in VHDL

• VHDL program for 8-bit 74x163 like synchronous serial counter

32

library IEEE;use IEEE.std_logic_1164.all;

entity V74x163s is port( CLK, CLR_L, LD_L, ENP, ENT: in STD_LOGIC; D: in STD_LOGIC_VECTOR (7 downto 0); Q: out STD_LOGIC_VECTOR (7 downto 0); RCO: out STD_LOGIC );end V74x163s;

architecture V74x163s_arch of V74x163s iscomponent syncsercell port( CLK, LDNOCLR, NOCLRORLD, CNTENP, D, CNTEN: in STD_LOGIC; CNTENO, Q: out STD_LOGIC );end component;signal LDNOCLR, NOCLRORLD: STD_LOGIC; -- common signalssignal SCNTEN: STD_LOGIC_VECTOR (8 downto 0); -- serial count-enable inputsbegin LDNOCLR <= (not LD_L) and CLR_L; -- create common load and clear controls NOCLRORLD <= LD_L and CLR_L; SCNTEN(0) <= ENT; -- serial count-enable into the first stage g1: for i in 0 to 7 generate -- generate the eight syncsercell stages U1: syncsercell port map ( CLK, LDNOCLR, NOCLRORLD, ENP, D(i), SCNTEN(i), SCNTEN(i+1), Q(i)); end generate; RCO <= SCNTEN(8); -- RCO is equivalent to final count-enable outputend V74x163s_arch;

Page 33: EET3350Lec15 Counters

33

74x163 Internal Logic Diagram• XOR gates

embody the “T” function

• Mux-like structure for loading

One of the four bit “cells”One of the four bit “cells”

Page 34: EET3350Lec15 Counters

Counters in VHDL

• 1-bit cell of a synchronous serial, 74x163 like counter

34

Page 35: EET3350Lec15 Counters

Counters in VHDL

• 1-bit cell of a synchronous serial, 74x163 like counter

35

library IEEE;use IEEE.std_logic_1164.all;

entity syncsercell is port( CLK, LDNOCLR, NOCLRORLD, CNTENP, D, CNTEN: in STD_LOGIC; CNTENO, Q: out STD_LOGIC );end syncsercell;

architecture syncsercell_arch of syncsercell iscomponent Vdffqqn port( CLK, D: in STD_LOGIC; Q, QN: out STD_LOGIC );end component;signal LDAT, CDAT, DIN, Q_L: STD_LOGIC;begin LDAT <= LDNOCLR and D; CDAT <= NOCLRORLD and ((CNTENP and CNTEN) xor not Q_L); DIN <= LDAT or CDAT; CNTENO <= (not Q_L) and CNTEN; U1: Vdffqqn port map (CLK, DIN, Q, Q_L); end syncsercell_arch;

Page 36: EET3350Lec15 Counters

36

Counter Operation• Free-running 16• Count if ENP and

ENT both asserted• Load if LD is asserted

(overrides counting)• Clear if CLR is asserted

(overrides loading and counting)

• All operations take place on rising CLK edge

• RCO is asserted if ENT is asserted andCount = 15

makes it free-runningmakes it free-running

Page 37: EET3350Lec15 Counters

37

Free-Running 4-Bit ’163 Counter• “divide-by-16” counter• RCO is asserted if ENT is asserted and Count = 15

Page 38: EET3350Lec15 Counters

38

Modified Counting Sequence

• Load 0101 (5) after Count = 15• 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 5, 6, …• “divide-by-11” counter

DCBA

Page 39: EET3350Lec15 Counters

39

Another Way

• Clear after Count = 1010 (10)• 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 1, 2, 3, …• “modulo-11” or “divide-by-11” counter

saves gate saves gate inputsinputs

Page 40: EET3350Lec15 Counters

40

Counting from 3 to 12

Page 41: EET3350Lec15 Counters

41

Cascading Counters

• RCO (ripple carry out) is asserted in state 15, if ENT is asserted

Page 42: EET3350Lec15 Counters

42

Decoding Binary-Counter States

Page 43: EET3350Lec15 Counters

43

Decoder Waveforms

• Glitches may or may not be a concern

Page 44: EET3350Lec15 Counters

44

Glitch-Free Outputs

• Registered outputs delayed by one clock cycle

Page 45: EET3350Lec15 Counters

Modulo-10 Counters

• From the 74LS163 “family” – the 74LS160– 74LS160 in free-running mode– Duty cycle of QC and QD is not 50%

45

Page 46: EET3350Lec15 Counters

Modulo-10 Counters

• 74LS160 state diagram• The 74LS160 (and

74LS162) can be preset to any state, but will not count beyond 9.

• If preset to state 10, 11, 12, 13, 14, or 15, it will return to its normal sequence within two clock pulses.

46

Page 47: EET3350Lec15 Counters

Ring Counter

47

• A ring counter is a loop of flip-flops interconnected in such a manner that only one of the devices may be in a specified state at one time

• If the specified state is HIGH, then only one device may be HIGH at one time.

• As the clock, or input, signal is received, the specified state will shift to the next device at a rate of 1 shift per clock, or input, pulse.

Page 48: EET3350Lec15 Counters

Ring Counter• A typical four-stage ring

counter

• Composed of R-S FFs. – J-K FFs may be used as well

• Output of each AND gate is input to the R, or reset side, of the nearest FF and to the S, or set side, of the next FF

• Q output of each FF is applied to the B input of the AND gate that is connected to its own R input

48

Page 49: EET3350Lec15 Counters

Another MSI Device• 74LS194 is a 4-Bit

Bidirectional Universal Shift Register

• may be used in serial-serial, shift left, shift right, serial-parallel, parallel-serial, and parallel-parallel data register transfers

49

Page 50: EET3350Lec15 Counters

Another MSI Device

• The ‘194 has the circuitry needed to count

50

Page 51: EET3350Lec15 Counters

51

Shift-Register Counters

• Ring counter

Page 52: EET3350Lec15 Counters

52

Johnson Counter

• “Twisted ring” counter

Page 53: EET3350Lec15 Counters

53

LFSR Counters• Pseudo-random number generator• 2n - 1 states before repeating• Same circuits used in CRC error checking in

Ethernet networks, etc.

Page 54: EET3350Lec15 Counters

54

LFSR Counters

• Feedback equations for all values of n

Page 55: EET3350Lec15 Counters

Decade Counters• A decade counter is a binary counter that is designed to

count to 1010, or 10102

• An ordinary four-stage counter can be easily modified to a decade counter by adding a NAND gate as shown below

• Notice that FF2 and FF4 provide the inputs to the NAND gate

• The NAND gate output is connected to the CLR input of each of the FFs

55

Page 56: EET3350Lec15 Counters

Counter Applications

• Digital Clock

56

Page 57: EET3350Lec15 Counters

Up/Down Counters

• A 3-bit binary up/down counter

57

Clock Count

UP / DOWN

Counter

QA

QB

QC

Page 58: EET3350Lec15 Counters

Up/Down Counters• This circuit is a 3-bit

UP/DOWN synchronous counter using JK flip-flops configured to operate as toggle or T-type flip-flops giving a count of zero (000) to seven (111) and back to zero again.

• An additional input determines the direction of the count, either UP or DOWN and the timing diagram gives an example of the counters operation as this UP/DOWN input changes state.

58

Page 59: EET3350Lec15 Counters

Up/Down Counters

• The 74LS169 is a fully synchronous 4-stage up/down counter

• Includes:– a preset capability for

programmable operation

– carry lookahead for easy cascading

– a U/ D input to control the direction of counting

59

Page 60: EET3350Lec15 Counters

Up/Down Counters

• The SN74LS169 operates in a Modulo-16 binary sequence

60

Page 61: EET3350Lec15 Counters

Up/Down Counters

• 74LS169 logic circuit diagram

61

Page 62: EET3350Lec15 Counters

Counter Applications

• 3-Bit Gray Code Counter

62

Page 63: EET3350Lec15 Counters

Counter Applications

• 3-Bit Gray Code Counter in VHDL

63

library ieee;use ieee.std_logic_1164.all;

entity StateCounter is port(clock: in std_logic; Q: buffer std_logic_vector(0 to 2) );end entity StateCounter;

architecture CounterBehavior of StateCounter isbeginprocess (Clock)begin if Clock = ‘1’ and Clock’event then case Q is when “000” => Q <= “010”; when “010” => Q <= “110”; when “110” => Q <= “100”; when “100” => Q <= “101”; when “101” => Q <= “001”; when “001” => Q <= “000”; when others => Q <= “000”; end case; end if;end process;end architecture CounterBehavior;

Page 64: EET3350Lec15 Counters

Next Time

• Midterm returned

• Start MIPs design

• Counter design using FSM approach

64