简单数字系统的VHLD应用设计
双优先编码器
电路要求 kbencoder
数据输入 i[7..0] 低电平有效 控制输入el 低电平有效
数据输出a[2..0] 反函数输出:表达最高位优先编码
数据输出b[2..0] 反函数输出:表达次高位优先编码
设计思想:
利用优先编码器先确定a,将a译码后与输入进行同或运
算,消去最高编码位后,再用优先编码器确定b;
利用前面的优先编码器(kencoder),用选择代入语句进行
二进制译码,利用代入语句进行连接运算(隔离、反相、同
或);
library ieee;
use ieee.std_logic_1164.all;
entity kbencoder is
port (e: in std_logic;
i: in std_logic_vector(7 downto 0);
a: out std_logic_vector(2 downto 0);
b: out std_logic_vector(2 downto 0));
end kbencoder;
architecture mixt of kbencoder is
signal a0:std_logic_vector(2 downto 0);
signal d: std_logic_vector(2 downto 0);
signal k: std_logic_vector(7 downto 0);
signal m: std_logic_vector(7 downto 0);
component kencoder is
port (i: in std_logic_vector (7 downto 0);
el: in std_logic;
a: out std_logic_vector(2 downto 0));
end component ;
begin
u1: kencoder port map (i,e, a0 );
d(0)<= not a0(0); d(1)<= not a0(1); d(2)<= not a0(2);
a<=a0;
with d select k<=
"01111111" when "000",
"10111111" when "001",
"11011111" when "010",
"11101111" when "011",
"11110111" when "100",
"11111011" when "101",
"11111101" when "110",
"11111110" when "111",
"11111111" when others;
m(0)<= k(0) xnor i(0); m(1)<= k(1) xnor i(1);
m(2)<= k(2) xnor i(2); m(3)<= k(3) xnor i(3);
m(4)<= k(4) xnor i(4); m(5)<= k(5) xnor i(5);
m(6)<= k(6) xnor i(6); m(7)<= k(7) xnor i(7);
u2: kencoder port map (m,e,b);
end mixt;
移位相加乘法器
利用移位寄存器的乘法功能,可以设计移位相加乘法器;
设计思想:
从低到高依次检查乘数的每一位是否为1,若为1则将被
乘数移位相加,若为0则被乘数只移位不相加;
使用部件:
加法器(16位),不需要进位输出(假定没有溢出);
具有控制端的16位寄存器,存放加法结果;
16位移位寄存器,使被加数移位(乘2);
8位移位寄存器,使加数左移串出,用于控制寄存器输入;
加数通过时钟开关送到寄存器控制端,控制寄存器数据
的变化;
设计框图:
实体设计:
entity shfmult8 is
port (a: in std_logic_vector(7 downto 0);
b: in std_logic_vector(7 downto 0);
clk,ld,clr: in std_logic;
q: out std_logic_vector(15 downto 0));
end shfmult8;
结构体设计
architecture str of shfmult8 is
signal as: unsigned(15 downto 0);
signal si: unsigned(15 downto 0);
signal qi: unsigned(15 downto 0);
signal bs: std_logic;
component adder16
port ( a : in unsigned(15 downto 0);
b: in unsigned(15 downto 0);
s: out unsigned(15 downto 0);)
end component;
component reg16
port ( d : in std_unsigned(15 downto 0);
clk,clr,en: in std_logic;
q: out unsigned(15 downto 0);)
end component;
component shfreg8
port ( d : in std_logic_vector(7 downto 0);
clk,clr,ld: in std_logic;
ql: out std_logic);
end component;
component shfreg16
port ( d : in std_logic_vector(16 downto 0);
clk,clr,ld: in std_logic;
ql: out unsigned(16 downto 0));
end component;
begin
process (clk)
begin
u1: shfreg16 port map (a,clk,clr,ld,as);
u2: shfreg8 port map (b,clk,clr,ld,bs);
u3: reg16 port map (si,clk,clr,bs,qi);
u4: adder16 port map (as,qi,si);
end process;
q<=qi+0;
end str;
在上述设计中,已对需要的4个元件的实体作出了具体规定,
下一步就可以根据这些规定,分头设计具体器件;
上述电路元件也可以采用进程和赋值语句分别描述如下:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
entity shfmult8 is
port ( a: in std_logic_vector(7 downto 0);
b: in std_logic_vector(7 downto 0);
clk,ld,clr: in std_logic;
q: out std_logic_vector(15 downto 0));
end shfmult8;
architecture beh of shfmult8 is
signal as: unsigned(15 downto 0);
signal si: unsigned(15 downto 0);
signal qi: unsigned(15 downto 0);
signal bi: std_logic_vector(7 downto 0);
signal bs: std_logic;
begin
shfreg16:process (clk,clr)
begin
if clr='1' then as<=(others=>'0');
elsif (clk'event and clk='1') then
if ld='1' then as<="00000000" & unsigned(a);
else
as<=as(14 downto 0) & '0'; --shift to hign bit
end if;
end if;
end process;
shfreg8:process (clk,clr)
begin
if clr='1' then bi<=(others=>'0');
elsif (clk'event and clk='1') then
if ld='1' then bi<= b;
else
bi<='0' & bi(7 downto 1); --shift to low bit
end if;
end if;
bs<=bi(0);
end process;
reg16:process (clk,clr)
begin
if clr='1' then qi<=(others=>'0');
elsif (clk'event and clk='1') then
if bs<= '1' then
qi<=si; --shift to low bit
end if;
end if;
end process;
si<=qi+as;
q<=qi+0;
end beh;
循环码编码器的设计
在通信系统中,为减小信道噪声和干扰导致的误码,大
量采用信道编码技术进行差错控制。循环码就是其中经常采
用的一种编码方式。
原理:
将信息码(n位)输入循环检验码发生器,由发生器产生
m位检验码,然后输出编码数据(n+m位),前面为信息码,
后面为检验码;(以下设n=4,m=3)
设计思想:
初始时刻将系统各功能块清零;
将输入数据(4位)通过并口送入7位移位寄存器,在后
面附加3个0,形成7位输入序列;
将数据逐位送入发生器,同时送到2选1MUX;
将发生器输出也送到2选1MUX;
利用一个7进制计数器控制MUX:前4个周期输出输入
序列,后3个周期输出检验序列;进位脉冲作为输出信号,
表明一组数据处理完毕;
设计框图:
实体设计
entity ccoder is
port ( d: in std_logic_vector (0 to 3);
clr, clk,ld: in std_logic;
z,co: out std_logic);
end ccoder;
结构体设计
architecture beh of ccoder is
signal q: std_logic_vector(2 downto 0);
signal s,y: std_logic;
mux: process (q,s,y)
case q is
when "000|001|010|011"=>z<=s;
when "100|101|110"=>z<=y;
when others=>z<='0';
end case;
end process;
cout7:process(clk,clr)
……
end process;
shfreg7:process(clk,clr)
……
end process;
checker:process(clk,clr)
……
end process;
end beh;
课外作业:
1 完成循环码编码器所要求的7进制计数器、7位右移并入串
出移位寄存器的设计;(每个功能块用一个进程表达)
2 典型的循环检验码发生器原理图如下图所示:
电路由3个d触发器和两个半加器构成;
为此功能块设计一个进程,要求满足课堂例题所指定的规
范;