Digital design with CPLD applications and VHDL (R. Dueck, 2000)
.pdfAnswers to Selected Odd-Numbered Problems |
819 |
9.39—— lpm8term
——8-bit presettable counter with synchronous clear and load,
——count enable, a directional control port,
——and terminal count decoding
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
LIBRARY lpm;
USE lpm.lpm_components.ALL;
ENTITY lpm8term IS |
|
|
PORT( |
|
|
clk, count_ena |
: IN |
STD_LOGIC; |
clear, load, direction |
: IN |
STD_LOGIC; |
p |
: IN STD_LOGIC_VECTOR(7 downto 0); |
|
max_min |
: OUT STD_LOGIC; |
|
q |
: OUT |
STD_LOGIC_VECTOR(7 downto 0)); |
END lpm8term; |
|
|
ARCHITECTURE a OF lpm8term IS
SIGNAL cnt : STD_LOGIC_VECTOR(7 downto 0);
BEGIN |
|
|
counter1: lpm_counter |
|
|
GENERIC MAP |
(LPM_WIDTH => 8) |
|
PORT MAP ( |
clock |
=> clk, |
|
updown |
=> direction, |
|
cnt_en |
=> count_ena, |
|
data |
=> p, |
|
sload |
=> load, |
|
sclr |
=> clear, |
|
q |
=> cnt); |
q <= cnt;
PROCESS (clk, cnt)
BEGIN
—— Terminal count decoder
IF (cnt = “00000000” and direction = ‘0’) THEN
max_min <= ‘1’;
ELSIF (cnt = “11111111” and direction = ‘1’) THEN max_min <= ‘1’;
ELSE
max_min <= ‘0’; END IF;
END PROCESS;
END a;
822 Answers to Selected Odd-Numbered Problems
9.51—— Left-shift register of generic width LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY slt_bhv IS |
|
|
GENERIC (width : POSITIVE); |
|
|
PORT( |
|
|
serial_in, clk |
: IN |
STD_LOGIC; |
q |
: BUFFER |
STD_LOGIC_VECTOR(width-1 downto 0)); |
END slt_bhv; |
|
|
ARCHITECTURE left_shift of slt_bhv IS
BEGIN
PROCESS (clk)
BEGIN
IF (clk‘EVENT and clk ‘1’) THEN
q(width-1 downto 0) <= q(width-2 downto 0) & serial_in; END IF;
END PROCESS;
END left_shift;
—— 32-bit left-shift register LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY slt32_bhv IS |
|
|
PORT( |
|
|
data_in, clock |
: IN |
STD_LOGIC; |
qo |
: BUFFER |
STD_LOGIC_VECTOR(31 downto 0)); |
END slt32_bhv; |
|
|
ARCHITECTURE left_shift of slt32_bhv IS |
|
|
COMPONENT slt_bhv |
|
|
GENERIC (width : POSITIVE); |
|
|
PORT( |
|
|
serial_in, clk |
: IN STD_LOGIC; |
|
q |
: OUT STD_LOGIC_VECTOR(31 downto 0)); |
|
END COMPONENT; |
|
|
BEGIN |
|
|
Shift_left_32: slt_bhv |
|
|
GENERIC MAP (width=> 32)
PORT MAP (serial_in => |
data_in, |
|
clk |
=> |
clock, |
q |
=> |
qo); |
END left_shift;
Figure ANS9.51 shows a partial simulation of the shift register.
Answers to Selected Odd-Numbered Problems |
823 |
FIGURE ANS9.51
9.53The generic component has a default width of 8 bits. The instantiated component has an assigned width of 16 bits. The generic map in the instantiated component overrides the default parameter.
9.55—— srg10lpm.vhd
—— 10-bit serial shift register (shift right) LIBRARY ieee;
USE ieee.std_logic_1164.ALL; LIBRARY lpm;
USE lpm.lpm_components.ALL;
ENTITY srg10lpm IS |
|
|
PORT( |
|
|
clk |
: IN |
STD_LOGIC; |
serial_in |
: IN |
STD_LOGIC; |
sync_set |
: IN |
STD_LOGIC; |
serial_out |
: OUT STD_LOGIC); |
|
END srg101pm; |
|
|
ARCHITECTURE lpm-shift of srg10lpm IS
COMPONENT lpm_shiftreg
GENERIC(LPM_WIDTH: POSITIVE; LPM_SVALUE: STRING);
PORT( |
|
|
clock, shiftin |
: IN |
STD_LOGIC; |
sset |
: IN |
STD_LOGIC; |
shiftout |
: OUT |
STD_LOGIC); |
END COMPONENT; |
|
|
BEGIN |
|
|
Shift_10: lpm_shifreg
GENERIC MAP (LPM_WIDTH=> 10, LPM_SVALUE => “960”)
PORT MAP (clk, serial_in, sync_set, serial_out);
END lpm_shift;
Answers to Selected Odd-Numbered Problems |
827 |
in1 |
INPUT |
|
|
|
q1 |
|
q0 |
|
|
|
|
|
||
|
NOT |
NOT |
NOT |
|
|
|
|
DFF |
|
|
|
|
AND3 |
q1 |
|
|
|
PRN |
|
|
|
|
D |
Q |
|
|
|
CLRN |
|
|
|
|
DFF |
|
|
|
|
AND2 |
q0 |
|
|
|
PRN |
|
|
|
|
D |
Q |
|
|
|
CLRN |
|
|
|
|
INPUT |
|
|
|
|
clk |
|
|
|
|
AND3 |
|
|
|
|
OUTPUT |
|
|
|
|
out1 |
|
|
|
|
AND3 |
|
|
|
|
OUTPUT |
|
|
|
|
out2 |
|
FIGURE ANS10.7