菜鸟写的一个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; 菜鸟学习中 希望得到大家指导 本人是学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 <br>
if(clr='0') then<br>
q1<="00";<br>
q0<="0000";<br>
elsif(up_down='1') then<br>
if(q1="10") then <br>
q1<="00";<br>
q0<="0000";<br>
elsif(q0="1001") then<br>
q0<="0000";<br>
q1<=q1+1;<br>
else q0<=q0+1;<br>
end if;<br>
elsif(up_down='0')then<br>
if q1="00"then<br>
if q0="0000"then<br>
q1<="10";q0<="0000";<br>
else q1<="00";q0<=q0-1; <br>
end if;<br>
elsif q0="0000" then<br>
q0<="1001";<br>
q1<=q1-1;<br>
else q0<=q0-1;<br>
end if;<br>
<br>
end if;<br>
end if;<br>
end process;<br>
end architecture; hao !!<br>
thanks! VHDL不太懂啊 ,我学VERILOG的 我也是刚了解Verilog帮不上,<br>
顶顶。 不论什么语言,看懂他的思路,考虑下就知道哪里有问题了.<br>
我也研究下 帮忙顶 站在读者的角度来看楼上的VHDL编写,很乱,程序的可读性差,简单的事情复杂化了 顶一个感觉自己学习的真的不怎么样。。。。。。。。。。
页:
[1]
2