FPGA活用回路&サンプル記述集(2) ―― モータやLEDを駆動するパワー回路
tag: 半導体 電子回路 ディジタル・デザイン
技術解説 2009年3月 9日
リスト3-1にデューティ比指定優先PWMモジュール(PULSEGEN)のソース・コードを示します.
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity PULSEGEN is
port(RES_n : in std_logic;
CLK : in std_logic;
CYCLE : in std_logic_vector(10 downto 0);
OFFTIMING : in std_logic_vector(6 downto 0);
START : in std_logic;
CLRSTB : out std_logic;
PULSEOUT : out std_logic
);
end PULSEGEN;
architecture RTL_PULSEGEN of PULSEGEN is
signal SCLR1, SCLR2 : std_logic;
signal CCOUNT : std_logic_vector(10 downto 0);
signal SEQE : std_logic;
signal COUNTE : std_logic;
signal DCOUNT : std_logic_vector(6 downto 0);
signal ONT, OFFT : std_logic;
begin
-- 分周カウンタ本体
process(RES_n, CLK, SCLR1, CYCLE, CCOUNT)
begin
if RES_n = '0' then
CCOUNT <= "00000000000";
else
if CLK'event and CLK = '1' then
if SCLR1 = '1' then
CCOUNT <= "00000000000";
else
CCOUNT <= CCOUNT + "00000000001";
end if;
end if;
end if;
end process;
-- 分周比生成
process(CCOUNT, CYCLE)
begin
if CCOUNT = CYCLE then
SCLR1 <= '1';
else
SCLR1 <= '0';
end if;
end process;
-- 分周器出力
process(RES_n, CLK, SCLR1)
begin
if RES_n = '0' then
SEQE <= '0';
else
if CLK'event and CLK = '1' then
SEQE <= SCLR1;
end if;
end if;
end process;
-- デューティ・カウンタ更新制御
process(RES_n, CLK, SEQE, START)
begin
if RES_n = '0' then
COUNTE <= '0';
else
if CLK'event and CLK = '1' then
if SEQE = '1' then
COUNTE <= START;
end if;
end if;
end if;
end process;
-- デューティ・カウンタ
process(RES_n, COUNTE, CLK, SCLR2, SEQE, DCOUNT)
begin
if RES_n = '0' or COUNTE = '0' then
DCOUNT <= "0000000";
else
if CLK'event and CLK = '1' then
if SEQE = '1' then
if SCLR2 = '1' then
DCOUNT <= "0000000";
else
DCOUNT <= DCOUNT + "0000001"
end if;
end if;
end if;
end if;
end process;
-- デューティ・カウンタ上限検出
process(DCOUNT)
begin
if DCOUNT = "1100011" then
SCLR2 <= '1';
else
SCLR2 <= '0';
end if;
end process;
-- ONタイミング比較
process(DCOUNT)
begin
if DCOUNT >= "0000001" then
ONT <= '1';
else
ONT <= '0';
end if;
end process;
-- OFFタイミング比較
process(DCOUNT, OFFTIMING)
begin
if DCOUNT >= OFFTIMING then
OFFT <= '1';
else
OFFT <= '0';
end if;
end process;
-- パルス出力生成
process(RES_n, COUNTE, CLK, ONT, OFFT)
begin
if RES_n = '0' or COUNTE = '0' then
PULSEOUT <= '0';
else
if CLK'event and CLK = '1' then
PULSEOUT <= ONT and (not OFFT);
end if;
end if;
end process;
-- STARTビット・クリア・ストローブ生成
process(RES_n, COUNTE, CLK, SEQE, SCLR2)
begin
if RES_n = '0' or COUNTE = '0' then
CLRSTB <= '0';
else
if CLK'event and CLK = '1' then
if SEQE = '1' then
CLRSTB <= SCLR2;
end if;
end if;
end if;
end process;
end RTL_PULSEGEN;
リスト3-1 デューティ比をリニアに設定できるPWMモジュールPULSEGENのVHDL記述
あさい・たけし
(株)ネクスト・ディメンション
tag: FPGA