刚刚在Quartus上编写完我的第一个VHDL程序,有挺多踩坑的地方,这里写出来给大家看一下,同时还有怎么去看仿真图。
首先,整个新建工程到编译完成查看结果的说明,都可以参考这篇博客:
(210条消息) Quartus ii 软件仿真基本流程(使用VHDL)_nachr的博客-CSDN博客_quartus仿真
这里讲讲编译时遇到的问题:
1.这个软件不像其他的IDE平台,在编译前就可会提示错误。所以需要对VHDL的语法烂熟于心。
2.我用的结构化风格来编写的,大致模板如下:
library IEEE;
use IEEE.std_logic_1164.all;
entity xxxx is
port
(
语句1;
语句2;
.
.
语句3); --整个程序中头的输入和尾的输出的声明
end xxxx;
library IEEE;
use IEEE.std_logic_1164.all; --注意,每次定义一个entity时都要带上这个
entity xxx1 is --器件的定义
port
(...);
end xxx1;
architecture xxx1_arch of xxx1 is
begin
--器件的行为描述
end xxx1_arch;
...
archtechiture xxxx_arch of xxxx is
signal xx1,xx2,xx3:std_logic; --器件的中间量
component xxx1 : port(...); end component; --器件的声明
...
begin
U1:xxx1 port map(...);--器件的实现,将形式引脚与实际引脚对应起来
U2:xxx1 port map(...);
...
end xxxx_arch;
可以看看这:VHDL Structural Modeling Style (surf-vhdl.com)
具体的全加器代码实现:
library IEEE;
use IEEE.std_logic_1164.all;
entity myfull_adder is
port(
X:in STD_LOGIC;
Y:in STD_LOGIC;
CIN:in STD_LOGIC;
S:out STD_LOGIC;
COUT:out STD_LOGIC
);
end myfull_adder;
library ieee;
use ieee.std_logic_1164.all;
entity XOR2 is
port(
l1,l2:in STD_LOGIC;
O:out STD_LOGIC);
end XOR2;
architecture XOR2_arch of XOR2 is
begin
O<=(l1 and NOT l2) OR (NOT l1 AND l2);
end XOR2_arch;
architecture myfull_adder_arch of myfull_adder is
signal X_xor_Y,X_CIN,Y_CIN,X_Y:STD_LOGIC;
component XOR2 port(l1,l2:in STD_LOGIC; O:out STD_LOGIC) ;end component;
component OR3 port(IN1,IN2,IN3:in STD_LOGIC; \OUT\:out STD_LOGIC) ;end component;
component AND2 port(IN1,IN2:in STD_LOGIC; \OUT\:out STD_LOGIC) ;end component;
begin
U1:XOR2 port map(l1=>X,l2=>Y,O=>X_xor_Y);
U2:AND2 port map(IN1=>X,IN2=>CIN,\OUT\=>X_CIN);
U3:AND2 port map(IN1=>Y,IN2=>CIN,\OUT\=>Y_CIN);
U4:AND2 port map(IN1=>X,IN2=>Y,\OUT\=>X_Y);
U5:XOR2 port map(l1=>X_xor_Y,l2=>CIN,O=>S);
U6:OR3 port map(IN1=>X_CIN,IN2=>Y_CIN,IN3=>X_Y,\OUT\=>COUT);
end myfull_adder_arch;
注意咯:我们肯定会比较好奇的是我怎么没定义component中的AND2和OR2?答案是这两个是Quartus的内置component,你不需要再定义,但是!!!
你形式引脚必须写成IN1,IN2,...这种,输出必须是\OUT\,不然识别不了!名字也必须一样!
可以看这里的博客讨论:
Error: Port "B" does not exist in primitive "OR2" of instance - Intel Communities