testbench实例 vhdl_VHDL testbench 例子,包含向文件中写数据

该博客提供了一个VHDL测试平台(Testbench)的例子,专注于DFFN(D Flip-Flop with Negative Edge-trigger)组件。通过实例展示了如何在时钟信号变化时,将数据从DFFN组件写入文本文件,用于记录和分析仿真结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

LIBRARY ieee;

USE ieee.std_logic_1164.ALL;

use std.textio.all;

use ieee.std_logic_textio.all;

ENTITY DFFNTest IS

END DFFNTest;

ARCHITECTURE behavior OF DFFNTest IS

-- Component Declaration for the Unit Under Test (UUT)

COMPONENT DFFN

GENERIC ( INIT : bit := '0');

PORT(

Q  : OUT  std_logic;

CLK  : IN  std_logic;

D : IN  std_logic

);

END COMPONENT;

--Inputs

signal CLK : std_logic := '0';

signal D : std_logic := '0';

--Outputs

signal Q : std_logic;

file fh_w:text;

BEGIN

-- Instantiate the Unit Under Test (UUT)

uut: DFFN PORT MAP (

Q => Q,

CLK => CLK,

D => D

);

write_proc:process

variable buf_w : line;

begin

wait for 91 ns;

wrtData:LOOP

wait for 10 ns;

write(buf_w,CLK);

write(buf_w,string'("  "));

write(buf_w,D);

write(buf_w,string'("  "));

write(buf_w,Q);

writeline(fh_w,buf_w);

END LOOP wrtData;

end process;

-- Stimulus process

stim_proc: process

variable fstatus:FILE_OPEN_STATUS;

variable buf_wh:line;

variable i :integer :=0;

begin

file_open(fstatus,fh_w,"DFFNtb_out.vrf",write_mode);

write(buf_wh,string'("CLK D  Q"));

writeline(fh_w,buf_wh);

wait for 100 ns;

loop1: while(i<50) loop

wait for 10 ns;

CLK <= not CLK;

if((i rem 3) = 0) then

D <= not D;

end if;

i := i+1;

end loop loop1;

file_close(fh_w);

wait;

end process;

END;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值