何かの役に立つかも知れないHDLコード達...
テストベンチ
クロック源とリセット信号
テストベンチ用のクロック源とリセット信号(負論理)
周波数は、適当にHDLを変更してください。
クロックとnリセット信号
クロック源、リセット信号、シリアル信号
テストベンチ用のクロック源とリセット信号(負論理)とシリアル信号
クロックと共にシリアル信号を出力できるテストベンチ。シリアル信号の内容は適宜HDLを変更してください。
クロックとnリセット信号とシリアル信号
RAM
SDRAM
textio
テキスト出力用のテストベンチ
CLKの立ち上がりに同期して入力されている値をテキスト出力する。
ポートとか出力したい値を修正して使ってください。
TEXTIO
HDLコード
微分回路(立ち上がり)
CLKと入力信号の変化の微分を取る回路
入力信号が変化した場合、CLKの立ち上がりのタイミングで1パルスを出力する回路
TRIGU
微分回路(立ち下がり)
CLKと入力信号の変化の微分を取る回路
入力信号が変化した場合、CLKの立ち下がりのタイミングで1パルスを出力する回路
TRIGD
AHBmaster
ARMの規格、AMBAのAHBmaster出力を行う回路
何かAHBslave回路をぶら下げたい場合等に使えます。
verilogで公開されていた回路を無理やりVHDLに書き換えたもの。
AHBMASTER_FIC
USER_RAM
ロジックを使用してRAMを構成する回路
FPGAに用意されているRAMでは不足するような場合に使用する。
USER_RAM
初期化
signal CNT : std_logic_vector(15 downto 0) := (others=>'0'); -- example
もしくは
DATA:=(others=>'0');
順序回路
以前の出力に関連し、現在の出力が変化するような回路のこと。
順序回路には、記録回路が必要不可欠
counter10のVHDL
VHDLのサンプルソース
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity counter10 is
Port ( CLK : in std_logic;
RESET : in std_logic;
Q : out std_logic_vector(3 downto 0));
end counter10;
architecture Behavioral of counter10 is
signal WORK : std_logic_vector(3 downto 0);
begin
process(CLK)
begin
if (CLK'event and CLK='1') then
if (RESET = '0') then
WORK <= "0000";
elsif (WORK = "1001") then
WORK <= "0000";
else
WORK <= WORK + '1';
end if;
end if;
end process;
Q <= WORK;
end Behavioral;
counter10のテストベンチ
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY counter10_tb IS
END counter10_tb;
ARCHITECTURE behavior OF counter10_tb IS
COMPONENT counter10
PORT(
CLK : IN std_logic;
RESET : IN std_logic;
Q : OUT std_logic_vector(3 downto 0)
);
END COMPONENT;
SIGNAL CLK : std_logic:='0';
SIGNAL RESET : std_logic:='0';
SIGNAL Q : std_logic_vector(3 downto 0);
BEGIN
uut : counter10 PORT MAP(
CLK => CLK,
RESET => RESET,
Q => Q
);
CLK <= not CLK after 20 ns;
RESET <= not RESET after 500 ns;
END;
CLKの分周
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity phalf is
port(
CLK: in std_logic;
DP : buffer std_logic:='0');
end phalf;
architecture Behavioral of phalf is
signal CNT: integer range 0 to 9999999:=0;
signal TMG: std_logic:='0';
begin
-- for count pulse
process(CLK)
begin
if (CLK'event and CLK = '1') then
if (CNT = 9999999) then
TMG <= '1';
CNT <= 0;
else
TMG <= '0';
CNT <= CNT + 1;
end if;
end if;
end process;
-- for ON/OFF LED
process(TMG)
begin
if (TMG'event and TMG = '1') then
DP <= not DP;
end if;
end process;
end Behavioral;
LEDを点灯させるだけのVHDL
-- LED_SW.vhd
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
library fusion;
entity LEDSW is
port ( INP : in std_logic;
OTP : out std_logic);
end LEDSW;
architecture DEF_ARCH of LEDSW is
begin
process (INP)
begin
if(INP = '1') then
OTP <= '1';
else
OTP <= '0';
end if;
end process;
end DEF_ARCH;
Portmapを利用したVHDL@Fusion
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
library proasic3;
entity sample is
port(RST: in std_logic;
OUTP: out std_logic;
OUTCLK:out std_logic);
end sample;
architecture DEF_ARCH of sample is
component newCore is
port(CLKOUT : out std_logic) ;
end component;
component pllCore is
port(POWERDOWN, CLKA : in std_logic; LOCK, GLA : out
std_logic; OADIVRST : in std_logic) ;
end component;
component PLLINT is
port(A : in std_logic; Y : out std_logic);
end component;
signal hoge: std_logic_vector(7 downto 0);
signal CLKOUT0 : std_logic;
signal CLK : std_logic;
signal CNT0: std_logic_vector(16 downto 0);
signal BIT4: std_logic_vector(3 downto 0);
begin
RCCLK0 : newCore port map(CLKOUT=>CLKOUT0);
PLL0 : pllcore port map(POWERDOWN=>'1', CLKA=>CLKOUT0, LOCK=>open, GLA=>CLK, OADIVRST=>'0') ;
process(CLK,RST,BIT4)
begin
OUTCLK <= BIT4(0);
if(RST = '1')then
OUTP <='0';
hoge <="00000000";
CNT0 <="00000000000000000";
BIT4 <="0000";
else
if(CLK'event and CLK = '1') then
BIT4 <= BIT4 + 1;
if(BIT4 = "1111")then
hoge <= hoge + 1;
end if;
case BIT4(3 downto 1) is
when "000" => OUTP <= hoge(0);
when "001" => OUTP <= hoge(1);
when "010" => OUTP <= hoge(2);
when "011" => OUTP <= hoge(3);
when "100" => OUTP <= hoge(4);
when "101" => OUTP <= hoge(5);
when "110" => OUTP <= hoge(6);
when "111" => OUTP <= hoge(7);
end case;
end if;
end if;
end process;
end DEF_ARCH;
シリアル2パラレル
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity SG is
port(
CLK : in std_logic;
INP : in std_logic;
SIG : out std_logic;
PLS : out std_logic);
end SG;
architecture Behavioral of SG is
signal cnt_clk : std_logic_vector(3 downto 0);
signal cnt_sg : std_logic_vector(7 downto 0);
signal cnt_dly : std_logic_vector(3 downto 0);
begin
-- for check ena/count pulse
process (CLK) begin
if (CLK'event and CLK = '1') then
if (INP = '0') then
cnt_clk <= "0000";
cnt_dly <= "0000";
cnt_sg <= "00000000";
else
cnt_dly <= cnt_dly + 1;
cnt_clk <= cnt_clk + cnt_dly(3);
if (cnt_dly(3) = '1') then cnt_dly <= "0000"; end if;
-- cnt_clk <= cnt_clk + 1;
end if;
if (cnt_clk(3) = '1') then
cnt_sg <= cnt_sg + '1';
cnt_clk <= "0000";
end if;
end if;
PLS <= cnt_clk(3);
end process;
process (cnt_clk) begin
case cnt_clk is
when "0000" => SIG <= cnt_sg(0);
when "0001" => SIG <= cnt_sg(1);
when "0010" => SIG <= cnt_sg(2);
when "0011" => SIG <= cnt_sg(3);
when "0100" => SIG <= cnt_sg(4);
when "0101" => SIG <= cnt_sg(5);
when "0110" => SIG <= cnt_sg(6);
when "0111" => SIG <= cnt_sg(7);
when others => SIG <= '0';
end case;
end process;
end Behavioral;
最終更新:2020年03月29日 23:57