设计中心 Active-HDL4.2 FPGA Express Foundation 设计中心 Training Introduction ?一个简单频率计的设计(带BCD计数器、LED 七段码显示控制) ?频率计的基本原理:将输入信号频率与基准时钟 频率进行比较 ?频率计在测量输入频率时,即测量状态下 START信号为‘1’ ?该设计采用3三种描述模式:VHDL行为代码模 式(HDE)、状态图模式(FSM)、框图模式(BDE) ?顶层框图将所有模块拼接起来 设计中心 简单频率计框图 设计中心 频率计主要模块 ? The following blocks are used in the design: – HEX2LED -LED七段码显示转换模块(HDE) – CNT_BCD -4位十进制BCD计数器模块(BDE) (包含AND2和CNT_4b俩子模块) – CONTROL -频率计控制模块(FSM) – Top_frqm -顶层设计(BDE) 设计中心 创建Project (New Design) ? In the Type the design name field, enter FRQ_METER 设计中心 设计环境调整 ?在Design Browser点鼠标右键 选择New Folder选项可以创建 自己的文件夹 ?新文件夹省却名为“Folder 1”、 “Folder 2”等,可以自行改名 ?比如,我们可以创建名为 FUNCTIONAL的文件夹,以便 归档我们接下来的设计 设计中心 1. HEX2LED -LED七段码显示转换模块 (HDE) 2. CNT_BCD - 4位十进制BCD计数器模(BDE) (包含AND2和CNT_4b俩子模块) 3. Top_frqm -顶层设计(BDE) 4. CONTROL -频率计控制模块(FSM) 设计内容 设计中心 设计中心 1.2创建HEX2LED显示模块 ? HEX2LED architecture: 用Language Assistant功能 ?调取Language Assistant窗口:Tools | Language Assistant ?选择Synthesis templates / HEX2LED Converter,用Use 选项将代码放入 architecture 的begin 与end之间. Note: The code is inserted where the cursor is located in your file. Check this before you invoke the use command. 设计中心 设计中心 1.3创建HEX2LED显示模块 ? Save the HEX2LED.VHD file ( Ctrl+S ) ?鼠标选中HEX2LED.VHD拖进FUNCTIONAL文件夹 ?打开在FUNCTIONAL文件夹中的HEX2LED.VHD, 编译( F11 ) 设计中心 1. HEX2LED -LED七段码显示转换模块(HDE) 2. CNT_BCD - 4位十进制BCD计数器模块 (BDE) (包含AND2和CNT_4b俩子模块) 3. Top_frqm -顶层设计(BDE) 4. CONTROL -频率计控制模块(FSM) 设计内容 设计中心 2. CNT_BCD 计数器模块描述 ? CNT_BCD是一个同步BCD计数器。 input ports: – CLK –系统时钟 – GATE –计数器使能端 – RESET –非同步RESET and output ports: – BCD_A, BCD_B, BCD_C, BCD_D –四输出四元组 设计中心 创建CNT_BCD 计数器模块 ? CNT_BCD 有4个四元组(CNT_4b 十进制计数器)。 计数范围(0 ~ 9999)。当GATE=‘1’时开始计数。 当RESET=‘1’计数器复位。 设计中心 2.1-1 CNT_4b 子模块描述(HDE) ?十进制计数器CNT_4b: – input ports (std_logic): ? CLK (clock) ? RESET (非同步reset) ? ENABLE (计数使能端) – output ports: ? FULL (std_logic:FULL=1 when Q=9; FULL=0 when Q=others) ? Q (std_logic_vector (3 downto 0):output) 设计中心 2.1-2创建CNT_4b子模块 (HDE) ?Add the in direction type ports: (STD_LOGIC): – CLK – ENABLE – RESET ?Add the out direction type ports: (STD_LOGIC_VECTOR) – Q[3:0] (STD_LOGIC): – FULL ? Click Finish 设计中心 2.1-3 创建CNT_4b子模块 ? Add the IEEE use clause for the std_logic_unsigned package (before the entity declaration): ? The libraries and entity declaration should look as above 设计中心 2.1-4 创建CNT_4b子模块 ?将左边的代码输入 CNT_4b的 architecture 。 ? Yes, that's right: type it in! ? No, there is no exact template for this in the language assistant architecture CNT_4B of CNT_4B is signal Qint: STD_LOGIC_VECTOR(3 downto 0); begin process (CLK, RESET) begin if RESET = '1' then Qint <= (others => '0'); elsif CLK='1' and CLK'event then if ENABLE = '1' then if Qint = 9 then Qint <= (others => '0'); else Qint <= Qint + 1; end if; end if; end if; end process; Q <= Qint; FULL <= '1' when (Qint = 9) else '0'; end CNT_4B; architecture CNT_4B of CNT_4B is signal Qint: STD_LOGIC_VECTOR(3 downto 0); begin process (CLK, RESET) begin if RESET = '1' then Qint <= (others => '0'); elsif CLK='1' and CLK'event then if ENABLE = '1' then if Qint = 9 then Qint <= (others => '0'); else Qint <= Qint + 1; end if; end if; end if; end process; Q <= Qint; FULL <= '1' when (Qint = 9) else '0'; end CNT_4B; 设计中心 2.1-5创建CNT_4b子模块 ? Force命令用于console控制台或用在macro文件(*.do)中, 它可用来创建任何波形作为仿真激励。基本句法如下: -r选项用于非周期波形序列的循环 ?选择File | New | Macro可以创建macro文件(*.do) ?在宏文件编辑窗中输入以下三行: Note:宏文件区分大小写。 force CLK 0 0, 1 10 ns -r 20 ns force RESET 1 0, 0 25 ns force ENABLE 0 0, 1 50 ns force value1 time1, value2 time2 -r period 设计中心 2.2创建与门AND2子元件(HDE) ?利用New Source File Wizard创建与门 AND2元件(VHDL file)。它有两输入A0、 A1和一输出Y ?在AND2.VHD 输入一行代码(between begin and end AND2 in the architecture body): Y<=A0 and A1; ? Save the file, close it, drag it to the Functional folder, then compile it. 设计中心 2.3-1 创建CNT_BCD模块(BDE) ? File | New | Block Diagram ?选择Block Diagram Wizard ? Next > ?在New Source File Wizard-Language窗口选择VHDL ? Next > ? New Source File Wizard – Name窗口输入CNT_BCD ? Next > BDE的操作步骤: 设计中心 创建CNT_BCD模块(续) (BDE) ? Add the in direction ports (STD_LOGIC): – CLK – GATE – RESET ? Add the out direction ports: (STD_LOGIC_VECTOR): – BCD_A[3:0] – BCD_B[3:0] – BCD_C[3:0] – BCD_D[3:0] 设计中心 设计中心 2.3-2 创建CNT_BCD模块(添加元件) ?进入添加元件状态,用鼠标左键点中cnt_4b symbol 从工具箱 中拖入框图区域四次;此后框图区域如下所示: ?将and2 symbol从Symbol工具箱中拖入框图区域三次。 NOTE:进入添加元件状态的方法是,在框图编辑器工具条点击 Show Symbol Toolbox按钮,即可添加上面的元件。 设计中心 2.3-3 创建CNT_BCD模块 ?用同样的方法添加3个and2 symbol ,然后即可关闭右侧 the Symbol Toolbox 对应子窗口,接下来就是画元 件间的互连线了。 设计中心 2.3-4 创建CNT_BCD模块 ? Wire按钮( )画一位互连线(and2与cnt_4b间互连线), Bus按钮( ) 画总线bus(计数器输出端口) 设计中心 2.3-5 创建CNT_BCD模块 ?用Global Wire button ( ) 在CLK和 RESET输入端口右边化两个黄圈。 ?分别双击黄圈输入名字CLK和RESET ? global wire定义完成后如下图所示: 设计中心 设计中心 1. HEX2LED -LED七段码显示转换模(HDE) 2. CNT_BCD - 4位十进制BCD计数器模(BDE) (包含AND2和CNT_4b俩子模块) 3. Top_frqm -顶层设计(BDE) 4. CONTROL -频率计控制模块(FSM) 设计内容 设计中心 3.1 创建顶层框图Top_frqm ? File | New | Block Diagram ?选择Block Diagram Wizard ? Next > ?在New Source File Wizard-Language窗口选择VHDL ? Next > ?在New Source File Wizard – Name窗口输入Top_frqm ? Next > 在这一部分我们将实现频率计的顶层框图设计,我们还将采用 top-down的设计方法创建FSM模块(Control)。 设计中心 3.2创建顶层框图Top_frqm ? Define the following ports of the Top_frqm block diagram: Input Ports: -F_INPUT - F_PATTERN - RESET - START Output Ports: - LED_A[6:0] - LED_B[6:0] - LED_C[6:0] - LED_D[6:0] ? Click Finish Block Diagram Editor (BDE) screen with an empty diagram will appear. 设计中心 3.3 创建顶层框图Top_frqm(虚拟元件) ?点击Fub button ( ) ,在F_PATTERN, RESET and START输入端口右边创建一个Fub符号,如下 图所示: 设计中心 3.4 创建顶层框图Top_frqm ?点击Wire button ( )化三条水平连线,连接F_PATTERN, RESET and START 端口到U1 fub;三个输入pin在Fub中自 动创建。 ?按Esc键回到选择模式。 ?双击“Fub1” label,更改fub name 为CONTROL ?右击fub body, 选择Edit进入 Fub编辑状态 设计中心 3.5 创建顶层框图Top_frqm ?拖动Add New Pin窗口中的Out pin到Fub右 边界,创建Pin1;重复操作创建Pin2。 ?双击Pin1更名为 GATE ?双击Pin2更名为 END_RESET ?点击Fub外面, 回答Yes保存。 设计中心 3.6 创建顶层框图Top_frqm ?完成后的Fub如右图所示 (完成顶层设计后,待 后续再完善该Fub设计) ?接下来完善Top_frqm框图设计: - one CNT_BCD module -four HEX2LED module ( 用Show Symbol Toolbox button 将对应元件 拖入框图编辑框) 设计中心 3.7 创建顶层框图Top_frqm ? The diagram with all six symbols placed should look like this: 设计中心 3.8 创建顶层框图Top_frqm ? The completed Top_frqm block diagram should look like this: ? Please save the diagram, close it, drag it to the Functional folder in the Design Browser and reopen it 设计中心 1. HEX2LED -LED七段码显示转换模(HDE) 2. CNT_BCD - 4位十进制BCD计数器模(BDE) (包含AND2和CNT_4b俩子模块) 3. Top_frqm -顶层设计(BDE) 4. CONTROL -频率计控制模块(选做) (FSM) 设计内容