CHAN 发表于 2010-6-27 23:10:44

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

写完后觉得正确了,但是真确结果不能仿真出来
检查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] 2
查看完整版本: 菜鸟写的一个20进制可逆计数器,仿真得不到想要的结果,大家进来看看