Файл: Digital design with CPLD applications and VHDL (R. Dueck, 2000).pdf
ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 13.06.2025
Просмотров: 8174
Скачиваний: 6
10.4 • Switch Debouncer for a Normally Open Pushbutton Switch |
475 |
FIGURE 10.22
Example 10.3
Simulation of a Single-pulse Generator (VHDL)
The simulation of the VHDL design entity sngl_pls is shown in Figure 10.22 |
|
SECTION 10.3 REVIEW PROBLEM
10.3 Briefly explain why the single-pulse circuit in Figure 10.20 has a flip-flop on its output.
10.4 Switch Debouncer for a Normally
Open Pushbutton Switch
www.electronictech.com
K E Y T E R M S
Form A contact A normally open contact on a switch or relay.
Form B contact A normally closed contact on a switch or relay.
Form C contact A pair of contacts, one normally open and one normally closed, that operate with a single action of a switch or relay.
A useful interface function is implemented by a digital circuit that removes the mechanical bounce from a pushbutton switch. The easiest way to debounce a pushbutton switch is with a NAND latch, as shown in Figure 10.23.
Vcc
S
Q
Vcc
Q
R
FIGURE 10.23
NAND Latch as a Switch Debouncer
The latch eliminates switch bounce by setting or resetting on the first bounce of a switch contact and ignoring further bounces. The limitation of this circuit is that the input switch must have Form C contacts. That is, the switch has normally open, normally closed, and common contacts. This is so that the switch resets the latch when pressed (i.e.,
476 |
C H A P T E R |
1 0 • State Machine Design |
||||||||||||||||||||||||||||
when the normally open contact closes) and sets the latch when released (normally closed |
||||||||||||||||||||||||||||||
contact recloses). Each switch position activates an opposite latch function. |
||||||||||||||||||||||||||||||
If the only available switch has a single set of contacts, such as the normally open |
||||||||||||||||||||||||||||||
(Form A) pushbuttons on the Altera UP-1 Education Board, a different debouncer circuit |
||||||||||||||||||||||||||||||
must be used. We will look at two solutions using VHDL: one based on an existing device |
||||||||||||||||||||||||||||||
(the Motorola MC14490 Contact Bounce Eliminator) and another that implements a state |
||||||||||||||||||||||||||||||
machine solution to the contact bounce problem. |
||||||||||||||||||||||||||||||
Switch Debouncer Based on a 4-bit Shift Register |
||||||||||||||||||||||||||||||
The circuit in Figure 10.24 is based on the same principle as the Motorola MC14490 Con- |
||||||||||||||||||||||||||||||
tact Bounce Eliminator, adapted for use in an Altera CPLD, such as the EPM7128S or the |
||||||||||||||||||||||||||||||
EPF10K20 on the Altera UP-1 Education Board. |
||||||||||||||||||||||||||||||
Vcc |
||||||||||||||||||||||||||||||
PBIN |
||||||||||||||||||||||||||||||
External |
||||||||||||||||||||||||||||||
pushbutton |
||||||||||||||||||||||||||||||
Clock divider |
Load |
D0 D1 |
D2 D3 |
|||||||||||||||||||||||||||
CTR DIV 216 |
Shift in |
SGR4 |
Shift out |
PBOUT |
||||||||||||||||||||||||||
System clock |
CLOCK Q15 |
CLOCK |
||||||||||||||||||||||||||||
(25.175 MHZ) |
||||||||||||||||||||||||||||||
FIGURE 10.24
Switch Debouncer Based on a 4-bit Shift Register
The heart of the debouncer circuit in Figure 10.24 is a 2-bit comparator (an Exclusive NOR gate) and a 4-bit serial shift register, with active-HIGH synchronous LOAD. The XNOR gate compares the shift register serial input and output. When the shift register input and output are different, the input data are serially shifted through the register. When input and output of the shift register are the same, the binary value at the serial output is parallel-loaded back into all bits of the shift register.
Figure 10.25 shows the timing of the debouncer circuit with switch bounces on both make and break phases of the switch contact. The line labeled 4-bit delay refers to the shift register flip-flop outputs. Pushbutton input is pb_in, debounced output is pb_out and clk is the UP-1 system clock, divided by 216. (Time values in Figure 10.25 are not to scale and should be disregarded.)
FIGURE 10.25
Simulation of the Shift Register-Based Debouncer
478 C H A P T E R 1 0 • State Machine Design
ENTITY debounce IS
PORT(
clk : IN STD_LOGIC; pb_in : IN STD_LOGIC; pb_out : OUT STD_LOGIC);
END debounce;
ARCHITECTURE debouncer OF debounce IS
-- Internal signals required to interconnect counter and shift register
SIGNAL srg_ser_out, |
srg_ser_in, srg_clk, srg_load : STD_LOGIC; |
||
SIGNAL |
srg_data |
: |
STD_LOGIC_VECTOR(3 DOWNTO 0); |
SIGNAL |
ctr_q |
: |
STD_LOGIC_VECTOR (15 DOWNTO 0); |
BEGIN
--Instantiate 16-bit counter clock_divider: lpm_counter
GENERIC MAP (LPM_WIDTH |
=> 16) |
|
PORT MAP (clock |
=> |
clk, |
q |
=> |
ctr_q(15 DOWNTO 0)); |
--Instantiate 4-bit shift register four_bit_delay: lpm_shiftreg
GENERIC MAP (LPM_WIDTH |
=> 4) |
PORT MAP (shiftin |
=> srg_ser_in, |
clock |
=> srg_clk, |
load |
=> srg_load, |
data |
=> srg_data(3 downto 0), |
shiftout |
=> srg_ser_out); |
-- Shift register is clocked by counter output -- (divides system clock by 2ˆ16)
srg_clk <= ctr_q(15);
--Undebounced pushbutton input to shift register srg_ser_in <= not pb_in;
--Shift register is parallel-loaded with output data if
--shift register input and output are the same.
--If input and output are different,
--data are serial-shifted. srg_data(3) <= srg_ser_out;
srg_data(2) |
<= srg_ser_out; |
srg_data(1) |
<= srg_ser_out; |
srg_data(0) |
<= srg_ser_out; |
pb_out |
<= srg_ser_out; |
srg_load |
<= not((not pb_in) xor srg_ser_out); |
END debouncer; |
Figure 10.26 shows a fairly easy way to test the switch debouncer. The debouncer output is used to clock an 8-bit counter whose outputs are decoded by two seven-segment decoders. (The decoders are VHDL files developed in a similar way to the seven-segment decoders in Chapter 5.)
Pin numbers are given for the EPM7128S CPLD on the Altera UP-1 circuit board. Since the clock and seven segment displays are hardwired on the Altera board, the only external connections required for the circuit are wires for the two pushbutton inputs, reset and pb_in.