【FPGA学习笔记】VHDL:GENERATE语句

generate语句

是一种可以建立重复结构或者是在多个模块的表示形式之间进行选择的语句。由于生成语句可以用来产生多个相同的结构,因此使用生成语句就可以避免多段相同结构的VHDL程序的重复书写。
有两种用途:
1、生成相同的元件,多次例化

--异步加法计数器
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;

ENTITY DFFR IS                       --定义一个D触发器DFFR
	PORT(clk , clr, d : IN STD_LOGIC;
		Q ,BQ : OUT STD_LOGIC);
END DFFR;
ARCHITECTURE art OF DFFR IS
	SIGNAL Q_IN :STD_LOGIC;
BEGIN
	Q <= Q_IN;
	BQ <= NOT Q_IN;
	PROCESS(clk,clr)
	BEGIN
		IF (clr = '1')THEN
			Q_IN <= '0';
		ELSIF (clk'EVENT AND clK = '1')
			Q_IN <= d;
		END IF;
	END PROCESS;
END art;

ENTITY rplcounter IS
	PORT(clK,clr : IN STD_LOGIC;
		count :OUT STD_LOGIC_VECTOR(7 DOWNTO 0));
END rplcounter;
ARCHITECTURE art1 OF DFFR IS
	SIGNAL COUNT_IN : STD_LOGIC_VECTOR(7 DOWNTO 0);
	COMPONENT DFFR                        --说明元件
		PORT(clk , clr, d : IN STD_LOGIC;
		Q ,BQ : OUT STD_LOGIC);
	END COMPONENT;
BEGIN
	COUNT_IN(0) <= clK;
	GEN1: FOR i IN 0 TO 3 GENERATE--元件例化并定义引脚连接:低位触发器的输出作为下一级的时钟信号
		U:DFFR PORT MAP
		(clK => COUNT_IN(i);
		 clr => clr;
		 d => COUNT_IN(i+1);
		 Q => COUNT_IN(i);
		 BQ => COUNT_IN(i+1));
	END GENERATE;
END art1;

2、生成结构相同的多次赋值、组合逻辑;

FOR i IN 0 TO 99 GENERATE

a(i)<=b(i)+c(i);

END GENERATE;

你可能感兴趣的:(FPGA)