[問題] VHDL計數器的問題
最近在做一個設定上數的計數器
用的軟體是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