集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 8340|回复: 10

菜鸟写的一个20进制可逆计数器,仿真得不到想要的结果,大家进来看看

[复制链接]
CHAN 发表于 2010-6-27 23:10:44 | 显示全部楼层 |阅读模式
写完后觉得正确了,但是真确结果不能仿真出来
检查VHDL语言找不到哪里出错了
大家帮我找找谢谢了

个人觉得是进位和退位时候出错的,但是不知道怎么改进
library ieee;
use ieee.std_logic_1164.all;
Use ieee.std_logic_unsigned.all;
entity counter20 is
port(clk,clr,up_down: in std_logic;
q0:buffer std_logic_vector(3 downto 0);--低4位
q1:buffer std_logic_vector(1 downto 0));-高2位
end entity;
architecture behave of counter20 is
begin
process(clk,clr)
begin
if(clr='0') then
  q1<="00";--high
  q0<="0000";--low
elsif (clk'event and clk = '1') then--clr=1时候上升沿到来就开始计数
  if (up_down='1') then--加法开始执行
  if q1="10" then
    q1<="00";高位等于2后就回到0(因为是20进制)
    if q0="1001" then
      q0<="0000";
      q1<=q1+1;低位等于9时候就回到0,并且高位加1
    else q0<=q0+1;否则低位加一
    end if;
  end if;
  elsif(up_down='0')then--减法开始执行
  if q1="00" then
    q1<="10";如果高位等于0就回到2
    if q0="0000" then
    q0<="1001";
    q1<=q1-1;如果低位等于0就回到9,并且高位减一
    else q0<=q0-1;否则低位减一
    end if;
  end if;
  end if;
end if;
end process;
end architecture;
ATA 发表于 2010-6-28 01:09:20 | 显示全部楼层
菜鸟学习中 希望得到大家指导
ngtim 发表于 2010-6-28 02:05:48 | 显示全部楼层
本人是学verilog的,对vhdl只了解一点,程序仅供参考,仓促之中,可能会有bug什么的,请谅解<br>
library ieee;<br>
use ieee.std_logic_1164.all;<br>
Use ieee.std_logic_unsigned.all;<br>
entity counter20 is<br>
port(clk,clr,up_down: in std_logic;<br>
q0:buffer std_logic_vector(3 downto 0);<br>
q1:buffer std_logic_vector(1 downto 0));<br>
end entity counter20;<br>
architecture behave of counter20 is<br>
begin<br>
process(clk,clr)<br>
begin<br>
if(clk'event and clk = '1') then&nbsp; &nbsp; &nbsp; &nbsp; <br>
&nbsp; &nbsp; &nbsp; &nbsp; if(clr='0') then<br>
&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; q1&lt;="00";<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; q0&lt;="0000";<br>
&nbsp; &nbsp; elsif(up_down='1') then<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; if(q1="10") then <br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; q1&lt;="00";<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;q0&lt;="0000";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; elsif(q0="1001") then<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;q0&lt;="0000";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;q1&lt;=q1+1;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; else q0&lt;=q0+1;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;end if;<br>
&nbsp; &nbsp; elsif(up_down='0')then<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if q1="00"then<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if q0="0000"then<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; q1&lt;="10";q0&lt;="0000";<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else q1&lt;="00";q0&lt;=q0-1; <br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end if;<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elsif q0="0000" then<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;q0&lt;="1001";<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;q1&lt;=q1-1;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;else q0&lt;=q0-1;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;end if;<br>
<br>
end if;<br>
end if;<br>
end process;<br>
end architecture;
ICE 发表于 2010-6-28 03:40:36 | 显示全部楼层
hao&nbsp; &nbsp;!!<br>
thanks!
ups 发表于 2010-6-28 05:36:35 | 显示全部楼层
VHDL不太懂啊 ,我学VERILOG的
CCIE 发表于 2010-6-28 07:02:23 | 显示全部楼层
我也是刚了解Verilog帮不上,<br>
顶顶。
FFT 发表于 2010-6-28 07:34:05 | 显示全部楼层
不论什么语言,看懂他的思路,考虑下就知道哪里有问题了.<br>
我也研究下
 楼主| CHAN 发表于 2010-6-28 07:55:05 | 显示全部楼层
帮忙顶
gzcjh230 发表于 2011-6-13 17:43:55 | 显示全部楼层
站在读者的角度来看楼上的VHDL编写,很乱,程序的可读性差,简单的事情复杂化了
妖刀 发表于 2011-8-3 11:35:40 | 显示全部楼层
顶一个  感觉自己学习的真的不怎么样。。。。。。。。。。
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|fpga论坛|fpga设计论坛 ( 京ICP备20003123号-1 )

GMT+8, 2025-6-24 04:26 , Processed in 0.071400 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表