当前位置:文档之家› VHDL语言设计入门

VHDL语言设计入门


常用的4种语句
二、if 语句 3、例子2—16位寄存器的另一种形式 --Signal reset, clk, wen :std_logic; --Signal d, q :std_logic_vector(15 downto -- 0); If reset = „0‟ then q <= x”0000”; Elsif clock‟event and clock = „1‟ then if wen = „1‟ then q <= d; end if; End if;
算术运算符
常用的算术运算符有:+ Signal a,b :std_logic_vector(15 downto 0); a + b a + „1‟ A + “01”
并运算符 &
并置运算符用于位的连接,形成矢量。也可连接 矢量形成更大的矢量。 Signal a,b:std_logic_vector(3 downto 0); Signal c,d: a,b:std_logic_vector(2 downto 0); a and („1‟ & c) c&a
常用的4种语句
二、if 语句 4、例子3—16位寄存器的第三种形式 --Signal reset, clk, wen :std_logic; --Signal d, q :std_logic_vector(15 downto -- 0); If reset = „0‟ then q <= ”0000000000000000”; Elsif clock‟event and clock = „1‟ then if wen = „1‟ then q <= d; end if; End if;
常用的4种语句
三、进程(process)语句 PROCESS语句是VHDL语言中描述硬 件系统行为的最基本的语句。本质上描述 了一个功能独立的电路块。 1、process语句的基本形式 PROCESS [(敏感信号1,敏感信号2,…)] BEGIN ┇ END PROCESS;
常用的4种语句
三、process语句 2、说明 敏感信号表中的任何一个发生变化,都 启动process语句工作。敏感信号表中的信 号是一部分输入信号,或者在process语句 中形成的反馈信号;纯粹输出的信号或者 在本语句中不发生变化的信号不能放入敏 感信号表。
常用的4种语句
三、process语句 4、改造后的2选一多路开关
--Signal sel: std_logic; --Signal a, b, c : std_logic_vector(15 -- downto 0); process(sel, a, b) begin If sel = „0‟ then c <= a; Else c <= b; End if; end process;
常用的4种语句
三、process语句 我们在if语句中介绍的电路如果不和 PROCESSS语句结合起来,不能构成一个 功能独立的电路,编译时就会出错。 下面是改造后的16位寄存器和2选1多路开 关。 3、改造后的16位寄存器
--Signal reset, clk, wen :std_logic; --Signal d, q :std_logic_vector(15 downto 0); register_pro:process(reset, clock) begin If reset = „0‟ then q <= x”0000”; Elsif clock‟event and clock = „1‟ then if wen = „1‟ then q <= d; end if; End if; end process; 注意:敏感信号表中没有信号D,因为只需要reset和clock启动 这个process语句;信号q是个输出信号,因此不能放入process 语句的敏感信号表中。 Register_pro:表示一个标号,标号可有可无。
信号和变量
信号(signal)是硬件中连线的抽象描 述,信号在元件的端口连接元件。 变量(varable)在硬件中没有类似的对 应关系,它们主要用于硬件特性的高层次 建模所需的计算中。
信号在逻辑电路 设计中最常用的数据类型
在VHDL语言中有10种数据类型,但 是在逻辑电路设计中最常用的是std_logic 和std_logic-vector提供的数据类型。 Std_logic类型分为布尔(boolean)型、 位(bit)型、位矢量(bit_vector)型。
VHDL入门需掌握的基本知识
一、信号(signal)的含义和信号的2种最常 用类型:std_logic和td_logic_vector 二、四种常用语句的基本用法 赋值语句、if语句、case语句和process语句 三、实体(entity)、结构体(architecture)和一个实 体和一个结构体组成的设计实体。 四、层次结构的设计 掌握元件(component)语句和端口映射(port map)语句。 五、库(library)和程序包(pachage)的基本使用。 有了上述的入门知识,一般的设计没有什么问题。
关系运算符
关系运算符有下列几种: = 等于 /= 不等于 < 小于 > 大于 <= 小于等于 >= 大于等于 等于、不等于运算符适用于所有的数据类型, 其他的运算符适用于整数、位及矢量等。在进行 关系运算时,两边的数据类型必须相同,但位长 度可以不同。 关系运算的结果为“真”或者“假”。
常用的4种语句
常用的4种语句
二、if 语句 5、信号沿的几种表示方法 clock‟event and clock = „1‟ 上升沿 clock‟event and clock = „0‟ 下降沿 rising_edge(clock)上升沿 falling_edge(clock) 下降沿
常用的4种语句
二、if 语句 6、例子4—时钟下降沿触发的16位寄存器 --Signal reset, clk, wen :std_logic; --Signal d, q :std_logic_vector(15 downto -- 0); If reset = „0‟ then q <= X”0000”; Elsif falling_edge(clock) then if wen = „1‟ then q <= d; end if; End if;
VHDL有许多类型的语句,我们这里讲4 种。 一、赋值语句 signal a, b, c: std_logic; signal d, e, q :std_logic_vector; c <= not (a and b); q <= d or q;
常用的4种语句
二、if 语句 1、if语句的三种形式 • if 条件 then 若干语句 end if; • if 条件 then 若干语句 else 若干语句 end if;
常用的4种语句
三、process语句 5、程序计数器PC的一种设计
--signal pc, zjmp_pc, cjmp_pc : -- std_logic_vector(15 downhto 0); -- signal t, zj_flag, cj_flag, dw_flag, reset :std_logic; pc_proc: process(pc, zjmp_pc, cjmp_pc, t, zj_flag, cj_flag, dw_flag,reset) begin if reset = „0‟ then pc <= x”0000”; elsif t‟event and t= „1‟ then if zj_flag = „1‟ then pc <= zjmp_pc; elsif cj_flag = „1‟ then pc <= cjmp_pc; elsif dw_flag = „1‟ then pc <= pc + “10”; else pc <= pc + „1‟; end if; end if; end process;
常用的4种语句
三、process语句 7、锁存器设计
--signal reset, set, clk: std_logic; --siganl d, q: std_logic_vector(15 downto 0); process(reset, set, clk) if reset = „0‟ then q <= x”0000”; elsif set = „0‟ then q <= x”ffff”; elsif clk = „1‟ then q <= d; end if; end process;
常用的4种语句
二、if语句
1、if语句的三种形式

if 条件1 then 若干语句 elsif 条件2 then 若干语句

else 条件n 若干语句 end if;
then
常用的4种语句
二、if 语句 2、例子1—16位寄存器 --Signal reset, clk, wen :std_logic; --Signal d, q :std_logic_vector(15 downto 0); If reset = „0‟ then q <= x”0000”; Elsif clock‟event and clock = „1‟ then if wen = „1‟ then q <= d; else q <= q; end if; End if; 说明:--是注释开始的标志,signal语句的存在只是为了说 明这些信号的类型,供阅读方便使用。
常用的4种语句
二、if 语句 7、例子5—二选一多路开关 --Signal sel: std_logic; --Signal a, b, c : std_logic_vector(15 -- downto 0); If sel = „0‟ then c <= a; Else c <= b; End if;
相关主题