VHDL(6)

2019-03-15 12:56

begin—结构体开始, 描述设计功能 --用并行语句描述设计的功能,

--最常用的并行语句是并行信号赋值,进程,元件例化。

--concurrent signal assignment (并行信号赋值的简单形式): <=;

--process:进程模块

process )

--此处声明局部变量,数据类型及其他局部声明(用于进程中)

begin --进程开始

--进程中为顺序语句,如:

--signal and variable assignments 信号与变量的赋值

--if and case statements --if-then-else语句 case-when语句 --while and for loops

--function and procedure calls 函数,过程调用 end process;

--元件例化,句法结构:

< 例化名>:<实体名,即元件名>

generic map (<实际参数,如确定的总线宽度等>) port map (<端口列表>);

end ;

4.1.14 常见错误

·隐含触发器

如以下代码:

library ieee;

use ieee.std_logic_1164.all; entity and2 is port

(a,b :in std_logic; c :out std_logic); end and2;

145 — —

architecture behave of and2 is begin

process(a,b)

begin

if(a='1' and b='1') then c<='1'; end if; end process; end behave;

设计指原意是设计一个二输入与门,但因“IF”语句中无“ELSE”语句,在对此语句逻辑综合时认为“ELSE”语句中为:“C<=C;”,即保持不便。因此可能形成的电路如下:

利用MAX+PLUSII软件仿真时,除了“a=1”及“b=1”时“c=1”外,其他时刻c的值都不确定。为改正此错误,仅需加上

else

c<=’0’; 语句即可。

这类错误在利用“IF-THEN-ELSE”语句设计组合电路时常犯的。

·时钟处理

如以下描述,是为了设计一个带计数使能的计数器,但其将falling_edge(clk)和 ci='1'放在一起,有些综合器可能会生成错误电路或不能综合。 IF (falling_edge(clk) and ci='1') THEN qcnt<=qcnt+1; END IF; 最好如下:

IF falling_edge(clk) THEN if(ci='1') then qcnt<=qcnt+1; end if; END IF;

此外,对于时钟电路,可省略“else”语句,它隐含表示“qcnt<=qcnt;”。可加上此句,

146 — —

但下面的描述则无法综合:

IF (falling_edge(clk)) THEN qcnt<=qcnt+1; else

qcnt<=datain; END IF; 综合时会出现如下错误信息:

“Else Clause following a Clock edge must hold the state of signal”

4.1.15. 保留字

如下为VHDL的保留字,又称关键字,在VHDL语言中有特殊的含义,不能作为标识符出现。此外,不同的综合系统还定义各自的子程序,子程序名也不能作为标识符出现。对于逻辑综合而言,并不是所有的保留字都有意义。 abs else nand then access elsif new severity after end next signal alias entity nor subtype all exit null then and file of to architecture for on transport array function open type assert generate or units attribute generic others util begin guarded process use block if range variable body in record wait buffer inout register when bus is rem while case label report with component library return xor configuration linkage select constant loop severity disconnect map signal downto mod subtype

147 — —

§4.2 常用电路描述

本节给出以下常见电路的VHDL描述。 ·加法器(全加器、BCD码加法器) ·译码器 ·编码器 ·比较器

·MUX数据选择器 ·奇偶校验电路 ·三态输出电路 ·同步化电路 ·M=60的计数器 ·移位寄存器

·状态机(Mealy和Moore型)

加法器(全加器、BCD码加法器)

一位BCD码加法器:

LIBRARY ieee;

USE ieee.std_logic_1164.all; USE ieee.std_logic_unsigned.all;

ENTITY bcdadder IS PORT (op1, op2 : in std_logic_vector(3 downto 0); result : out std_logic_vector(4 downto 0) ); END bcdadder;

ARCHITECTURE behavior OF bcdadder IS

signal binadd :std_logic_vector(4 downto 0);

BEGIN

binadd<=op1+op2; --保存二进制之和

--若出现宽度不匹配错误,可将该句改为:binadd<=(‘0’ & op1) +(‘0’ & op2); --即高位补零。 process(binadd) begin

148

.

if binadd>9 then --进行加6校正 result <= binadd+6; else

result <= binadd; end if;

end process; END behavior;

全加器(12位)

LIBRARY ieee;

USE ieee.std_logic_1164.all; USE ieee.std_logic_unsigned.all;

ENTITY adder14 IS PORT (op1, op2 : IN std_logic_vector (12 downto 0); ci : in bit; result : OUT std_logic_vector (13 downto 0)); END adder14;

ARCHITECTURE maxpld OF adder14 IS signal halfadd : std_logic_vector (13 downto 0); BEGIN

halfadd<=op1+op2;

result<=halfadd when ci='0' else halfadd+1; END maxpld;

译码器

带使能端的七端译码器

library ieee;

use ieee.std_logic_1164.all; entity decode47 is port (adr :in std_logic_vector(3 downto 0); en :in std_logic; decodeout :out std_logic_vector(6 downto 0)); end decode47;

149

.


VHDL(6).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:河北省2015年中考化学试题(word版,含答案)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: