[VHDL] 案例模板 您所在的位置:网站首页 FPGA的原理图转VHDL代码 [VHDL] 案例模板

[VHDL] 案例模板

2023-08-10 07:30| 来源: 网络整理| 查看: 265

前言

刚刚看到群里有人问要VHDL模板,我都快忘了这事了,VHDL的语法再不记下来就忘了。趁现在还有印象,复习一下几个FPGA实验中写的VHDL代码。

简单还是复杂,这要看受众了。文章目标人群就是忘了或者完全的不会的人,让你马上可以使用起来VHDL。这个语言我并不喜欢,太死板了。在了解Verilog前我还对Verilog有所期望,但是那个语言的设计也是一坨屎。设计一些非人 性的东西,考虑了特别多的问题但是语言变得很难用。

简短了解一下 注释 --和lua和SQL一样。用两个连续的减号 程序结构 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity A is port( ... ); end entity xx; entity B is port( ... ); end entity xx; arthitecture hello of A is begin process(...) begin ... end process; end arthitecture hello; arthitecture hi of B is begin process(...) begin ... end process; end arthitecture hi;

要定义元件XX,引脚的输入输出定义在port之中。process中是输入信号,信号一旦改变就会执行后面的内容。

entity是元件定义部分,arthitecture是调用部分。

写在几个文件里和写在一个文件里是一样的!

大小写不敏感

引脚定义

VHDL中有四种端口,分别是IN,OUT,BUFFER,INOUT。

IN                                      \;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\; 单向只读OUT                                \;\;\;\;\;\;\;\;\;\;\;\;\;\;\; 单向输出INOUT                          \;\;\;\;\;\;\;\;\;\;\;\; 双向BUFFER                    \;\;\;\;\;\;\;\;\; 缓冲。与INOUT类似,但是当需要输入数据时,只允许内部回读输                                              \;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\; 出的信号,即允许反馈。 数据类型 BIT                                  \;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\; 一位的 ‘1’ or ‘0’BOOLEAN              \;\;\;\;\;\; 一位的“TRUE” or “FALSE”STD_LOGIC          \;\;\;\; 一位的’1’ or ‘0’ or ‘Z’ or ‘X’ or ‘H’ or ‘L’ or ‘W’ or ‘-’STD_LOGIC_VECTOR                        \;\;\;\;\;\;\;\;\;\;\; STD_LOGIC的数组INTEGER                  \;\;\;\;\;\;\;\; 整数 port( clk,a,b,cin : in std_logic; --输入定义 cout,y : out std_logic --输出定义 ); 信号

信号定义语句放在process前面,也可以放在arthitecture的begin前面。

signal a,b,c : integer range 0 to 255; signal d : std_logic := '0'; --使用:=初始化 signal e : std_logic_vecotr(8 downto 0) 引脚和信号一样 变量

变量定义语句放在process的begin前面。

variable a : std_logic_vector(3 downto 0); variable b : integer range 255 downto 0; variable c : Bit8; variable d : integer := 100; --使用:=初始化 variable e : boolean; 案例1:数码管译码器

输入是四条线,输出是8条线。

引脚定义后要加分号

因为light是引脚不是变量,赋值使用 ... when 2 | 4 to 7 => ... when others => ... end case; 案例2 : 全加器

全加器的公式 C o u t = ( A ⊗ B ) C i n + A B S = A ⊗ B ⊗ C i n C_{out}= (A\otimes B)C_{in} + AB\\S=A\otimes B\otimes C_{in} Cout​=(A⊗B)Cin​+ABS=A⊗B⊗Cin​

半加器的公式 C o u t = A B S = A ⊗ B C_{out}=AB\\S=A\otimes B Cout​=ABS=A⊗B

全减器的公式 C o u t = ( A ‾ + B ) C i n + A ‾ B D = A ⊗ B ⊗ C i n C_{out} = (\overline{A} + B)C_{in} + \overline{A}B \\D=A\otimes B\otimes C_{in} Cout​=(A+B)Cin​+ABD=A⊗B⊗Cin​

半减器的公式 C o u t = A ‾ B D = A ⊗ B C_{out}=\overline{A}B\\D=A\otimes B Cout​=ABD=A⊗B

library ieee; use ieee.std_logic_1164.all; entity completed_adder is port( a,b,cin:in std_logic; s,cout:out std_logic ); end entity completed_adder; architecture hello of completed_adder is begin sb0,cin=>mycin,cout=>net0,s=>s0); u1:completed_adder port map(a=>a1,b=>b1,cin=>net0,cout=>net1,s=>s1); u2:completed_adder port map(a=>a2,b=>b2,cin=>net1,cout=>net2,s=>s2); u3:completed_adder port map(a=>a3,b=>b3,cin=>net2,cout=>mycout,s=>s3); --end process; end architecture hello1; 案例4:7人表决器 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity eda_7voters is port( a0,a1,a2,a3,a4,a5,a6 : in std_logic; yellow,green : out std_logic ); end entity eda_7voters; architecture hello of eda_7voters is begin process(a0,a1,a2,a3,a4,a5,a6) variable counter : integer range 7 downto 0; begin counter := a0+a1+a2+a3+a4+a5+a6; if(counter


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有