完整程式如下:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity my_div is
generic(divisor:integer:=4000000); -- 因為要產生1Hz的Cclock, 所以定義除數為4000000
port(
clk_in: in std_logic;
clk_out: out std_logic
);
end my_div;
architecture arch of my_div is
signal cnt2 : std_logic;
begin
process(clk_in)
variable cnt1 : integer range 0 to divisor:=1;
variable divisor2 : integer range 0 to divisor;
begin
divisor2:=divisor/2;
if(clk_in'event and clk_in='1') then -- cnt1為計數器,累加至4000000時歸0
if cnt1 = divisor then
cnt1 := 1;
else
cnt1 := cnt1 + 1;
end if;
end if;
if(clk_in'event and clk_in='1') then
if((cnt1 = divisor2) or (cnt1 = divisor)) then -- cn1 為2000000或4000000時,輸出做反向
cnt2<= not cnt2;
end if;
end if;
clk_out <= cnt2;
end process;
end arch;
結果如下:
想請教一下0.5hz該如何改呢?
回覆刪除又或是想2秒亮2秒暗?是用工作週期寫嗎?