组合电路的VHDL设计优先编码器编码器-Read

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

组合电路的VHDL设计

优先编码器

编码器(encoder)也属于码制转换器一类

(BCD—1-out-of-10)( p.49 表2-9 )

优先编码器属于多对1转换关系,没有一一对应关系,难以采用上述方式描述;

74148 优先编码器真值表见p.278 表5-23,表中含有大量‘x’项,目前VHDL还不能直接对其进行运算处理;

在p.384 表5-26中,显示了行为设计的一种形式:采用for-loop语句;

也可以采用数据流设计中的条件代入语句实现:

例:简化74148优先编码器的数据流设计

数据输入 i[7..0] 低电平有效控制输入el 低电平有效数据输出a[2..0] 反函数输出

library ieee;

use ieee.std_logic_1164.all;

entity kencoder is

port (i: in std_logic_vector (7 downto 0);

el: in std_logic;

a: out std_logic_vector(2 downto 0));

end kencoder;

architecture rtl of kencoder is

signal a1:std_logic_vector(2 downto 0);

begin

a1 <="000" when i(7)= '0' else

"001" when i(7 downto 6)="10" else

"010" when i(7 downto 5)="110" else

"011" when i(7 downto 4)="1110" else

"100" when i(7 downto 3)="11110" else

"101" when i(7 downto 2)="111110" else

"110" when i(7 downto 1)="1111110" else

"111";

a<=a1 when el='0' else "111";

end rtl;

奇偶校验电路 parity checker

奇偶校验电路是实现数据错误检验的一种基本电路,其方式是检测在9位输入数据中‘1’的个数是奇数还是偶数; 3输入端异或门可以看作3位奇偶校验电路:

‘1’的个数为奇数时输出为‘1’,为偶数时输出为‘0’; 利用该电路可以构成9位奇偶校验电路;

p.418 表5-47 9位奇偶校验电路的行为设计

p.419 表5-48 9位奇偶校验电路的结构设计

例 9位奇偶校验电路的数据流设计

library ieee;

use ieee.std_logic_1164.all;

entity kparity9 is

port (i: in std_logic_vector ( 1 to 9);

even,odd : out std_logic);

end kparity9 ;

architecture rtl of kparity9 is

signal y1,y2,y3,y: std_logic;

begin

y1<= i(1) xor i(2) xor i(3) ;

y2<= i(4) xor i(5) xor i(6) ;

y3<= i(7) xor i(8) xor i(9) ;

y<= y1 xor y2 xor y3 ;

odd<= y ; even<= not y;

end rtl;

运算电路

运算电路主要包括比较器(comparator)、加法器(add)、乘法器(multipliers)和算术逻辑单元(ALU)等电路。

在运算电路中,运算量经常需要进行算术运算;

在VHDL中,算术运算不能对bit、 std_logic、std_logic_vector等类型进行;

此外,二进制的数值表达方式本身也存在符号表达方式问题,不同表达方式的运算规则不同;

为了解决类型与运算的相容问题,统一符号运算问题,在包集合IEEE.std_logic_arith中,定义了signed和 unsinged 两种类型,以及与这两种类型相应的转换函数和对这些类型进行的运算,其规则如下(针对加/减运算):

若运算量中存在signed类型,结果就为signed类型;否则为unsinged 类型;

若结果被指定为std_logic、std_logic_vector等类型,则signed或unsigned 类型的结果自动转为指定类型;

运算结果的长度为最长运算量的长度,但若unsigned 类型与signed类型运算,会自动变为后一类型,其长度会增加1以在最高位增加符号位'0';

对于通常所用的sdt_logic_vector类型的数据d,需要进行算术运算时,可以采用函数signed(d)将其转换为signed类型,或采用函数unsigned(d)将其转换为unsigned类型,运算完毕后,通过代入语句将结果直接赋值给sdt_logic_vector类型的信号,即可恢复通用的类型;

例 P.445 表5-55 各种运算结果的类型

8位不同类型数据的加/减法器

数据流设计

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_arith.all;

entity vadd is

port (a,b: in unsigned( 7 downto 0 );

c : in signe

d ( 7 downto 0 );

d : in std_logic_vector( 7 downto 0 );

s : out unsigned (8 downto 0);

t : out signed (8 downto 0);

u : out signed (7 downto 0);

v : out std_logic_vector(8 downto 0));

end vadd;

相关文档
最新文档