一、VHDL程序的基本结构
library ieee;
use ieee.std_logic_1164.all;
entity test is
port(
d_in: in std_logic;
d_out: out std_logic);
end entity;
architecture behave of test is
begin
process
begin
xxxxx
end process;
end architecture;
1.1 库
1.2 程序包
1.3 实体
1.4 结构体
二、VHDL语言要素
2.1 VHDL的文字规则
2.1.1 标识符
使用关键词做芯片名芯片管脚命名时 \out\
需要加两个反斜杠来界定。
2.1.2 数字
2.1.3 字符和字符串
2.1.4 位串
2.1.5 注释
2.2 数据对象
2.2.1 常量
constant pi: real := 3.14;
2.2.2 变量
2.2.3 信号
2.3 数据类型
2.3.1 VHDL的主要预定义数据类型
2.3.2 IEEE预定义标准逻辑位与矢量
2.3.3 其他预定义标准数据类型
2.3.4 用户自定义数据类型
2.3.5 数据类型的转换
Q := (others => '0')
省略赋值操作符
等效于给变量Q赋值"00000000"
- 如何把
std_logic_vector
中的某一位赋给std_logic
d_out: out std_logic_vector(3 downto 0);
c_out: out std_logic;
variable result: std_logic_vector(4 downto 0);
// 截取向量中的某一段
d_out <= result(3 downto 0);
// 抽取向量中的某一位
c_out <= result(4);
- 位如何赋值,向量如何赋值,单引号还是双引号
单个字符使用
''
,多个字符使用""
2.4 运算符
2.4.1 逻辑运算符
2.4.2 算术运算符
2.4.3 关系运算符
2.4.4 连接运算符
简并 &
2.4.5 VHDL运算符优先级
三、VHDL并行语句
进程语句
并行信号赋值语句
元件例化语句
元件声明
声明之前,先把将要使用的元件的文件路径导入到工程中,以供编译时索引。在结构体内的 begin
前面加入元件声明 component
,注意元件的名称是对应vhdl中的实体名,元件引脚的名称要与实体中的 port
一致。
architecture behave of counter100 is
component freq_divider
port(
clk_in: in std_logic;
clk_out: out std_logic);
end component;
begin
元件例化
在结构体的 begin
之后调用元件
architecture xxxx
xxxx
begin
U1: freq_divider
port map(
clk_in => xxx;
clk_out => xxx);
U2: freq_divider(
clk_in => xxx;
clk_out => xxx);
xxxx
1.U1
U2
是例化后元件的标识,是自定义的,不能重复。标识后面是声明的元件的名称,必须和声明一致,声明的元件可以例化多个元件,标识需要定义成不同的。
2. 端口映射使用 port map
,可以位置映射也可以名称映射。
类属语句
生成语句
四、VHDL顺序语句
if语句
if(d = '1') then
q <= '1';
elsif(d = '0') then
q <= '0';
else
q <= 'z';
end if;
注意: then
elsif
end if
的使用。
case语句
case d is
when "00" => c <= '0';
when "01" => c <= '0';xxx;xxxx;
when "10" => c <= '0';
when others => null;
end case
注意:=>
的使用,不要和信号赋值符号 <=
搞混。
1.case的条件必须不能重合且能覆盖所有的条件,即交集为空且并集为全集
2.每个条件后面可以有多个语句。