Файл: Digital design with CPLD applications and VHDL (R. Dueck, 2000).pdf

ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 13.06.2025

Просмотров: 8166

Скачиваний: 6

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

9.5 • Control Options for Synchronous Counters

399

4bit_dir.gdf 4bit_dir.scf

FIGURE 9.39

Simulation of 4-bit Bidirectional Counter

Decoding the Output of a Counter

Figure 9.40 shows a graphic design file of a 4-bit bidirectional counter with an output decoder. The counter is the one shown in Figure 9.38, represented as a logic circuit symbol. The decoder component decode16 is a module written in VHDL, as listed below.

4bit_dir

INPUT

Q3

Q3

DIR

DIR

Q3

INPUT

Q2

OUTPUT

CLOCK

CLOCK

Q2

Q2

INPUT

Q1

OUTPUT

RESET

RESET

Q1

Q1

Q0

OUTPUT

Q0

Q0

DECODE16

Q [3..0]

sel [3..0] y [0..15]

FIGURE 9.40

4-bit Bidirectional Counter with Output Decoder

—— decode16.vhd

LIBRARY ieee;

USE ieee.std_logic_1164.ALL;

ENTITY decode16 IS

PORT(

sel

:

IN

INTEGER RANGE

0 to 15;

y

:

OUT

BIT_VECTOR (0

to 15));

END decode16;

ARCHITECTURE a OF decode16 IS

BEGIN

WITH sel SELECT

y <=

x“7FFF” WHEN 0,

x“BFFF” WHEN 1,

x“DFFF” WHEN 2,

x“EFFF” WHEN 3,

x“F7FF” WHEN 4,

x“FBFF” WHEN 5,

OUTPUT

Y [0..15]


400 C H A P T E R 9 • Counters and Shift Registers

WHEN 6,

WHEN 7,

CD: decode16.vhd WHEN 8,

4bit_dcd.gdf

x“FFBF” WHEN 9,

4bit_dcd.scf

x“FFDF” WHEN 10, x“FFEF” WHEN 11, x“FFF7” WHEN 12, x“FFFB” WHEN 13, x“FFFD” WHEN 14, x“FFFE” WHEN 15, X“FFFF” WHEN others;

END a;

The decoder has 16 outputs, one for each state of the counter. For each state, one and only one output will be low. (Refer to the section on binary decoders in Chapter 5 for a more detailed description of n-line-to-m-line binary decoders.)

Figure 9.41 shows a portion of the simulation waveforms (i.e., only the count value and the decoder outputs) for the circuit in Figure 9.40. As the count progresses up or down, as shown by the waveform for Q[3..0], the decoder outputs respond by going LOW in sequence.

Output decoders for binary counters can also be configured to have active HIGH outputs. In this case, one and only one output would be HIGH for each output state of the counter.

Terminal Count and RCO

A special case of output decoding is a circuit that will detect the terminal count, or last state, of a count sequence and activate an output to indicate this state. The terminal count depends on the count sequence. A 4-bit binary UP counter has a terminal count of 1111; a 4-bit binary DOWN counter has a terminal count of 0000. A circuit to detect these conditions must detect the maximum value of an UP count and the minimum value of a DOWN count.

FIGURE 9.41

Simulation of 4-bit Decoder

9.5 •

Control Options for Synchronous Counters

401

VCC

AND6

Q3

INPUT

INPUT

Q2

INPUT

Q1

INPUT

Q0

OR2

INPUT

DIR

OUTPUT

BAND6

MAX_MIN

GND

FIGURE 9.42

Terminal Count Decoder for a 4-bit Bidirectional Counter

term_dcd.gdf

4bit_rco.gdf 4bit_rco.scf

inup- gate

generates a HIGH when DIR 0 AND Q3Q2Q1Q0 0000.

Figure 9.43 shows the terminal count decoder combined with a 4-bit bidirectional counter. The decoder is also used to enable a NAND gate output that generates an RCO signal. RCO stands for ripple carry out or ripple clock out. The purpose of RCO is to produce exactly one clock pulse upon terminal count and have the positive edge of RCO at the end of the counter cycle, for a counter that has a positive edge-triggered clock.

4bit_dir

INPUT

Q3

OUTPUT

Q3

DIR

OUTPUT

INPUT

Q2

Q2

RESET

OUTPUT

INPUT

Q1

Q1

CLOCK

OUTPUT

Q0

Q0

term_dcd

Q3

Q2

Q1

OUTPUT

MAX_MIN

MAX_MIN

Q0

DIR

NAND2

NOT

OUTPUT

RCO

9.43

Counter with Terminal Count Detection

This function is generally found in counters with a fixed number of bits (i.e., fixedfunction counter chips, not PLDs) and is used to asynchronously clock a further counter stage, as in Figure 9.44. This allows us to extend the width of the counter beyond the number of bits available in the fixed-function device. This is not necessary when designing synchronous counters in programmable logic, but is included for the sake of completeness.


402 C H A P T E R 9 • Counters and Shift Registers

DIR

CTR DIV 16

CTR DIV 16

CLK

DIR

Q2

RCO

DIR

Q2

Q3

Q1 Q0

Q3

Q1 Q0

Q7

Q6

Q5 Q4

Q3

Q2

Q1 Q0

FIGURE 9.44

Counter Expansion Using RCO

The NAND gate in Figure 9.43 is enabled upon terminal count and passes the clock signal through to RCO. The NAND output sits HIGH when inhibited. The clock is inverted in the RCO circuit so that when the NAND gate inverts it again, the circuit generates a clock pulse in true form.

Figure 9.45 shows the simulation of the circuit of Figure 9.43. In the first half of the simulation, the counter is counting DOWN. The terminal count decoder output, MAX_MIN, goes HIGH when Q3Q2Q1Q0 0000. RCO generates a pulse at that time. For the second half, the counter is counting UP. MAX_MIN is HIGH when Q3Q2Q1Q0 1111 and RCO generates a pulse at that time.

FIGURE 9.45

Simulation of a 4-bit Bidirectional Counter with Terminal Count Detection

Note that the RCO pulse appears to be half the width of the MAX_MIN pulse. Although the NAND gate that generates RCO is enabled for the whole MAX_MIN pulse, the clock input is HIGH for the first half-period, which is the same as the RCO inhibit level.

The positive edge of RCO is at the end of the pulse. The idea is to synchronize the positive edge of the clock with the positive edge of RCO. However, since the RCO decoder is combinational, a propagation delay of about 7 ns is introduced.

SECTION 9.5 REVIEW PROBLEM

9.5Figure 9.46 shows two presettable counters, one with asynchronous load and clear, the other with synchronous load and clear. The counter with asynchronous functions has a 4-bit output labeled QA. The synchronously loaded counter has a 4-bit output labeled QS. The load and reset inputs to both counters are active LOW.


9.6

• Programming Presettable and Bidirectional Counters in VHDL

403

4bit_al

INPUT

P3

P3

OUTPUT

INPUT

Q3

QA3

P2

P2

INPUT

OUTPUT

P1

P1

Q2

QA2

INPUT

OUTPUT

P0

P0

Q1

QA1

OUTPUT

LOAD

Q0

QA0

RESET

CLOCK

4bit_sl

P3

Q3

QS3

P2

OUTPUT

P1

Q2

QS2

INPUT

OUTPUT

LOAD

LOAD

Q1

QS1

OUTPUT

P0

Q0

QS0

CLOCK

INPUT

RESET

RESET

INPUT

CLOCK

FIGURE 9.46

Section Review Problem 9.5

Two Presettable Counters

LOAD

RESET

CLOCK

P

0

8

5

QA

0

1

2

3

QS

0

1

2

3

FIGURE 9.47

Timing Diagram for Counters in Figure 9.46

Figure 9.47 shows a partial timing diagram for the counters. Complete the diagram.

9.6Programming Presettable and Bidirectional Counters in VHDL

The presettable counters and bidirectional counters described in the previous section can be easily implemented in VHDL, either as behavioral descriptions or as LPM components. We will initially examine the behavioral descriptions of two counters, one with asynchronous load and clear and one with synchronous load and clear. We will then examine some options available in the module lpm_counter.