VHDL四位计数器编写(手把手)

quartus新建工程和仿真操作参考这篇博文,只需修改工程名和VHD文件即可
CNT4.vhd文件

LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_arith.all;  
use ieee.std_logic_unsigned.all; 

ENTITY CNT4 IS
	PORT(CLK,RST_n:IN STD_LOGIC;
		P:OUT STD_LOGIC_VECTOR (3 downto 0));
END ENTITY CNT4;

ARCHITECTURE ART OF CNT4 IS

SIGNAL tmp :STD_LOGIC_VECTOR (3 downto 0);

	BEGIN
	PROCESS (CLK) IS
		BEGIN
		IF(RST_n='1') THEN
			IF (CLK='1' AND CLK'EVENT) THEN
				--tmp<=unsigned(tmp)+'1';
				tmp<=tmp+1;
			END IF;
		ELSE
			tmp<=(others =>'0');
		END IF;
	P<=tmp;	
	END PROCESS;
END ARCHITECTURE ART;

testbench文件,CNT.vht

-- Copyright (C) 1991-2013 Altera Corporation
-- Your use of Altera Corporation's design tools, logic functions 
-- and other software and tools, and its AMPP partner logic 
-- functions, and any output files from any of the foregoing 
-- (including device programming or simulation files), and any 
-- associated documentation or information are expressly subject 
-- to the terms and conditions of the Altera Program License 
-- Subscription Agreement, Altera MegaCore Function License 
-- Agreement, or other applicable license agreement, including, 
-- without limitation, that your use is for the sole purpose of 
-- programming logic devices manufactured by Altera and sold by 
-- Altera or its authorized distributors.  Please refer to the 
-- applicable agreement for further details.

-- ***************************************************************************
-- This file contains a Vhdl test bench template that is freely editable to   
-- suit user's needs .Comments are provided in each section to help the user  
-- fill out necessary details.                                                
-- ***************************************************************************
-- Generated on "05/10/2021 20:16:49"
                                                            
-- Vhdl Test Bench template for design  :  CNT4
-- 
-- Simulation tool : ModelSim-Altera (VHDL)
-- 

LIBRARY ieee;                                               
USE ieee.std_logic_1164.all;                                

ENTITY CNT4_vhd_tst IS
END CNT4_vhd_tst;
ARCHITECTURE CNT4_arch OF CNT4_vhd_tst IS
-- constants
constant ClockPeriod :time :=20 ns;                                                   
-- signals                                                   
SIGNAL CLK : STD_LOGIC;
SIGNAL P : STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL RST_n : STD_LOGIC;
COMPONENT CNT4
	PORT (
	CLK : IN STD_LOGIC;
	P : OUT STD_LOGIC_VECTOR(3 DOWNTO 0);
	RST_n : IN STD_LOGIC
	);
END COMPONENT;
BEGIN
	i1 : CNT4
	PORT MAP (
-- list connections between master ports and signals
	CLK => CLK,
	P => P,
	RST_n => RST_n
	);
init : PROCESS                                               
-- variable declarations                                     
BEGIN                                                        
        -- code that executes only once                      
WAIT;                                                       
END PROCESS init;                                           
always : PROCESS                                              
-- optional sensitivity list                                  
-- (        )                                                 
-- variable declarations
BEGIN                                                         
        -- code executes for every event on sensitivity list
	RST_n<='0';
	wait for ClockPeriod;
	RST_n<='1';		
WAIT;                                                        
END PROCESS always;
GENERATE_CLOCK:PROCESS
BEGIN
	CLK<='0';
	wait for ClockPeriod/2;
	CLK<='1';
	wait for ClockPeriod/2;	
END PROCESS;                                          
END CNT4_arch;

仿真结果
在这里插入图片描述

  • 3
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值