使用VHDL和Xilinx的带按钮开关的计数器设计 [英] Counter with push button switch design using VHDL and Xilinx

查看:145
本文介绍了使用VHDL和Xilinx的带按钮开关的计数器设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是VHDL和XILINX ISE的新手.我使用的Xilinx ISE版本是13.2.

I'm very new to VHDL and XILINX ISE. I use the version 13.2 for Xilinx ISE.

我想用以下输入设计一个非常简单的计数器:

I want to design a very simple counter with the following inputs:

  • 方向

计数输入将分配给一个按钮,并且我希望计数器在按下按钮时根据方向输入向上或向下计数.在此之前,我已经编写了一个示例VHDL.它有一个时钟输入,并且正在根据时钟输入进行计数.现在,我希望它在按下按钮时进行计数,而不是同步进行计数.

The count input will be assigned to a button and I want the counter to count up or down according to direction input when the button is pressed. I have written a sample VHDL before this one. It had a clock input and It was counting according to the clock input. Now I want it to count when I press the button instead of counting synchronously.

这是我的VHDL代码(请告诉我我的代码是否存在逻辑缺陷或任何其他缺陷):

Here's my VHDL code (please tell me if my code have a logical or any other flaw):

entity counter is
    Port ( COUNT_EN : in  STD_LOGIC;
           DIRECTION : in  STD_LOGIC;
           COUNT_OUT : out  STD_LOGIC_VECTOR (3 downto 0));
end counter;

architecture Behavioral of counter is

signal count_int : std_logic_vector(3 downto 0) := "0000";
begin
process 
begin
    if COUNT_EN='1' then
        if DIRECTION='1' then   
            count_int <= count_int + 1;
        else
            count_int <= count_int - 1;
        end if;
    end if;
end process;
COUNT_OUT <= count_int;
end Behavioral;

我使用Spartan xc3s500e,并相应地放置了输入.以下是我的.ucf文件:

I use Spartan xc3s500e and I placed the inputs accordingly. Below is my .ucf file:

#Created by Constraints Editor (xc3s500e-fg320-5) - 2013/03/18
NET "COUNT_EN" LOC = K17;
NET "COUNT_OUT[0]" LOC = F12;
NET "COUNT_OUT[1]" LOC = E12;
NET "COUNT_OUT[2]" LOC = E11;
NET "COUNT_OUT[3]" LOC = F11;
NET "DIRECTION" LOC = L13;
#Created by Constraints Editor (xc3s500e-fg320-5) - 2013/03/18
NET "COUNT_EN" CLOCK_DEDICATED_ROUTE = FALSE;

由于出现错误,我需要更改最后一行:

I needed to change the last line because I was getting the error:

This will not allow the use of the fast path between the IO and the Clock...

此错误消失后,我对设备进行了编程.但是输出(LED)表现得很疯狂.他们有时静止不动几秒钟,有时只是快闪.我不知道我的错误在哪里.我将不胜感激,非常感谢一些初学者的教程(我发现的链接将我定向到xilinx的文档,对于初学者来说,它们似乎很复杂).

After having this error gone, I programmed the device. But the output (leds) acted crazy. They sometimes stood still for a few seconds, sometimes just flashed very fast. I could not figure out where my mistake is. I would appreciate any help, some beginner tutorials are greatly appreciated (the links i found directed me to xilinx's documentations and they seemed quite complicated for a beginner).

推荐答案

从您的描述中我了解到,您不是正在寻找

From your description I understand that you are not looking for an Asynchronous Counter.

您需要的是依靠按钮开关触发的计数器.下面的RTL应该可以工作:

What you need is counter that counts on trigger from PushButton Switch. The below RTL should work:

如果HDL编码有任何困难,请告诉我.

If any difficulty in HDL coding let me know.

这篇关于使用VHDL和Xilinx的带按钮开关的计数器设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆