作者ppp122333333 (Dove)
看板Electronics
标题[问题] VHDL计数器的问题
时间Fri Jul 25 14:04:58 2008
最近在做一个设定上数的计数器
用的软体是QUARTUS来跑
按钮有清除 CLR 跟致能开关 EN
以及选择所要设定的输出个位数十位数的位置 SEL
和所要设定的个位数十位数的数字+1按钮 SW
这是我写的程式码
--------set1----------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity set1 is
port(sel1 :in std_logic;
en1,clr:in std_logic;
sw1:in std_logic;
light1,light2:out std_logic;
mone1:out std_logic_vector(3 downto 0);
mten1:out std_logic_vector(3 downto 0));
end set1;
architecture a of set1 is
signal a,b:std_logic_vector(3 downto 0);
begin
process(sw1)
begin
if (en1='0' and clr='0')then
if sel1='0' then
light1<='1';
light2<='0';
if sw1'event and sw1='1' then
a<=a+1;
end if;
case a is
when "0000"=>
mone1<="0000";
when "0001"=>
mone1<="0001";
when "0010"=>
mone1<="0010";
when "0011"=>
mone1<="0011";
when "0100"=>
mone1<="0100";
when "0101"=>
mone1<="0101";
when "0110"=>
mone1<="0110";
when "0111"=>
mone1<="0111";
when "1000"=>
mone1<="1000";
when "1001"=>
mone1<="1001";
when others=>
mone1<="0000";
end case;
else
light2<='1';
light1<='0';
if sw1'event and sw1='1' then
b<=b+1;
end if;
mten1<=b;
end if;
else
mten1<="0000"; mone1<="0000";
light2<='0';
light1<='0';
end if;
end process;
end a;
-------------------------------
我是用两个方法来撰写
其中设定第一个个位数字的时候用的是当SW为正缘触发 传到A
让他+1 之後再到CASE去执行所要的输出
第二个设定十位数的时候
则是用正缘触发後
直接输出
不论在第一个方法或是第二个方法下
输出都会有0的暂态 就是 01020300000000 且後面都是0的输出
无法将所要设定的数字固定输出
另外在第二个方法下
输出的数值都会比所按压的次数少一 这是我感到相当不解疑惑的事
不知道板上的大大们能不能帮我看一下到底是哪个地方出现错误 或是方法观念出了问题
能否替我指点迷津 谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.160.177.55