首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

新手又来求助

新手又来求助

每次遇到问题都到这里来求助,真是个好地方,呵呵!

小弟最近学习VHDL的时候遇到一个问题。首先我把我预期的目的写出来:本来是来一个时钟就使输出移位一次,举个例子,来第一个clk输出00001,来第二个clk输出00010,来第三个clk输出00100,来第四个输出01000...........依此类推。

但是我写好程序并后,结果完全不同。我这个程序的基本思想是使用一个计数器,然后由计数器的计数值来决定输出的状态,这个本来可以用类似写译码器的列举方法来列举,但是由于这个输出太长了,是个矢量,一共19位,我觉得难写,就想另外想个办法(呵呵),我想,使上一个时钟的输出自身相加,即相当于使一个二进制数自身相加,不就相当于向高位移位一次吗?按照这个想法来写,结果仿真的后果是输出全部为零。下面是我的程序,请各位高手指导一下,为什么会出现这种结果?

entity timctrl is
port(clk:in std_logic;
        tmp:buffer std_logic_vector(19 downto 1));
end timctrl;
architecture bhv of timctrl is
signal count:std_logic_vector(4 downto 0);
begin
process(clk)
begin
if(clk'event and clk='1')then
 if(count="10011")then
   count<="00001";
 else count<=count+'1';
 end if;
end if;
end process;
process(count)
begin
case count is
when"00001"=>tmp<="0000000000000000001";
when others=>tmp<=tmp+tmp;
end case;
end process;
end bhv;

-- WARNING: Do NOT edit the input and output ports in this file in a text
-- editor if you plan to continue editing the block that represents it in
-- the Block Editor! File corruption is VERY likely to occur.

-- Copyright (C) 1991-2005 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 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.


-- Generated by Quartus II Version 5.1 (Build Build 176 10/26/2005)
-- Created on Sat Jan 06 00:37:33 2007

LIBRARY ieee;
USE ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

--  Entity Declaration

ENTITY ag IS
 -- {{ALTERA_IO_BEGIN}} DO NOT REMOVE THIS LINE!
 ORT
 (
  clk : IN STD_LOGIC;
  dout : OUT STD_LOGIC_VECTOR(18 downto 0)
 );
 -- {{ALTERA_IO_END}} DO NOT REMOVE THIS LINE!
 
END ag;


--  Architecture Body

ARCHITECTURE ag_architecture OF ag IS

 
BEGIN
process(clk)
variable count:integer range 0 to 19;
variable c:std_logic_vector(18 downto 0);
begin
 if(clk'event and clk='0')then
  case count is
   when 19=>count:=0;
     c:="0000000000000000001";
   when others=>c:=(others=>'0');
       c(count):='1';
      count:=count+1;
  end case;
  dout<=c;
 end if;
end process;
     
END ag_architecture;

这个你可以试一下,另外你可以试一下把tmp<=tmp+tmp;改成c:=c+c;tmp<=c;--c是变量,

每一天都是新的开始,每一天都有新的收获
谢谢了,呵呵。另外我想知道为什么我的程序会出现那种结果?

[此贴子已经被作者于2007-1-6 20:44:21编辑过]

你可以看一下信号量辅值的定义,我也说不好
每一天都是新的开始,每一天都有新的收获
返回列表