http://www.vhdl.club/2016/01/27/69/ sitesindeki ornegin uzerinde oynayarak asagidaki kodu hazirladim.
Hatalarimi ve daha iyi yazilmis halini konusabilirmiyiz?
Amac: 10 bitlik pwm portumuz var. Bu porta datayi yerlestirip Load girisini 1 yaparsak porttaki data pwm uretmek uzere fpga icine aliniyor.
Rst ile pwm donanimi resetlenebiliyor.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity pwm is
Port(
in_clk : in std_logic; ; Pwm Clock
in_rst : in std_logic; ; Pwm Reset
in_ld : in std_logic; ; Pwm Data Load
in_d0 : in std_logic ; Pwm Data0
in_d1 : in std_logic ; Pwm Data1
in_d2 : in std_logic ; Pwm Data2
in_d3 : in std_logic ; Pwm Data3
in_d4 : in std_logic ; Pwm Data4
in_d5 : in std_logic ; Pwm Data5
in_d6 : in std_logic ; Pwm Data6
in_d7 : in std_logic ; Pwm Data7
in_d8 : in std_logic ; Pwm Data8
in_d9 : in std_logic ; Pwm Data9
out_data : out std_logic ; Pwm Output
);
end pwm;
architecture Tanimlamar of pwm is
signal pwm_shadow_reg : integer range 0 to 1023 ;
signal pwm_reg : integer range 0 to 1023 ;
signal pwm_cnt : integer range 0 to 1023
signal pwm_clk : std_logic;
begin
pwm_clk <= in_clk
; PWM Data Portunu PWM Registerine okuma islemi
process(pwm_clk, in_ld)
begin
if rising_edge(pwm_clk) then
if in_ld = '1' then
pwm_reg <= 512*in_d9 + 256*in_d8 + 128*in_d7 + 64*in_d6 +32*in_d5 + 16*in_d4 + 8*in_d3 + 4*in_d2 + 2*in_d1 + in_d0;
endif
endif
end process;
; Resetleme ve sayma islemi
process(pwm_clk, in_rst)
begin
if in_rst = '1' then
pwm_cnt <= 0;
pwm_reg <= 0;
pwm_shadow_reg <= 0;
elsif rising_edge(pwm_clk) then
if pwm_cnt = 1023 then
pwm_cnt <= 0;
pwm_shadow_reg <= pwm_reg;
else
pwm_cnt <= pwm_cnt + 1;
end if;
end if;
end process;
; PWM sinyali uretme islemi
process(pwm_clk)
begin
if rising_edge(pwm_clk) then
if pwm_cnt < pwm_shadow_reg then
out_data <= '1';
else
out_data <= '0';
end if;
end if;
end procesS;
end Tanimlamar;
Power on asamasinda tum registerlerin otomatik sifiranmasi nasil olur?
Asagidaki satir yerine (dogrumu yazdim bilmiyorum) daha guzel bir kod nasil yazilir?
pwm_reg <= 512*in_d9 + 256*in_d8 + 128*in_d7 + 64*in_d6 +32*in_d5 + 16*in_d4 + 8*in_d3 + 4*in_d2 + 2*in_d1 + in_d0;
Giris ve cikis pinerinin hangi pinler olacagini kod icinde tanimlayabilirmiyim?
Tanımladığını Registere ilk değer olarak 0 atayarak yapabilirsiniz.
singnal Bir_register : std_logic_vector(0 to 3) := "0000"
Pin tanımlamalarını ayrıca bir Constrains dosyasında yapıyorsunuz. proje içine oluşturuyorsunuz ki bu hem hangi pin olduğunu ve hangi loji seviye ile çalıştığını tanımlıyor (LVCMOS33 vb.)
set_property IOSTANDARD LVCMOS33 [get_ports Qdeğil]
set_property PACKAGE_PIN E19 [get_ports Qdeğil]
signal pwm_shadow_reg : integer range 0 to 1023 : '000000000'
Peki yukaridaki yazim ile asagidaki yazim ayni anlama mi geliyor?
signal pwm_shadow_reg : std_logic_vector(0 to 9) : '000000000'
Birnde integer bir tanımlama yapıp ilk değeri 0 veryorsunuz, diğerinde ise bit türünden tanımlama yapıp ilk değeri 0 versiyorsunuz.
yaplan işe aynı anlamda.
Peki yukaridaki programda hata yok diyelim.
Simdi FPGA icine ayni pwm blogundan 8 tane yerlestirmek isteyeyim. FPGA in 10 bitlik pwm deger yukleme girisi 8 kanal icin de ortak kullaniliyor olsun. 8 Pwm regden hangisine yukleme yapacagim 3 girisli adres hatti uzerinden girilen deger ile belirlenecek olsun.
Verdigim kodu 8 kanal icin tek tek yazmak yerine bu programi fonksiyon olarak yazip 8 kanali bu fonskiyonla iliskilendirebilirmiyiz?
Mumkunse program olarak burda verebilirmisiniz?
Gelistirme ortamini kurdum ve calisti.
Yukaridaki programda pek cok hata verdi. Aciklamalarin onune -- isareti koymak gerekiyor.
se IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity pwm is
Port(
in_clk : in std_logic ; -- Clock
in_rst : in std_logic ; -- Reset
in_ld : in std_logic ; -- Load
in_data : in std_logic_vector(9 downto 0);
out_data : out std_logic
);
end pwm;
architecture Tanimlamalar of pwm is
signal pwm_shadow_reg : std_logic_vector(9 downto 0);
signal pwm_reg : std_logic_vector(9 downto 0);
signal pwm_cnt : std_logic_vector(9 downto 0);
signal pwm_clk : std_logic;
begin
pwm_clk <= in_clk ;
-- PWM Data Portunu PWM Registerine okuma islemi
process(pwm_clk, in_ld)
begin
if rising_edge(pwm_clk) then
if in_ld = '1' then
pwm_reg <= in_data;
end if;
end if;
end process;
-- Resetleme ve sayma islemi
process(pwm_clk, in_rst)
begin
if in_rst = '1' then
pwm_cnt <= (others=>'0');
pwm_reg <= (others=>'0');
pwm_shadow_reg <= (others=>'0');
elsif rising_edge(pwm_clk) then
if pwm_cnt = 1023 then
pwm_cnt <= (others=>'0');
pwm_shadow_reg <= pwm_reg;
else
pwm_cnt <= pwm_cnt + 1;
end if;
end if;
end process;
-- PWM sinyali uretme islemi
process(pwm_clk)
begin
if rising_edge(pwm_clk) then
if pwm_cnt < pwm_shadow_reg then
out_data <= '1';
else
out_data <= '0';
end if;
end if;
end process;
end Tanimlamalar;
Bu programdaki ERROR:HDLCompiler:1401 - "/home/ise/MyProject/PWM.vhd" Line 35: Signal pwm_reg[9] in unit pwm is connected to following multiple drivers:
Hatasini yok edemiyorum.
pwm_reg tanimladim ve bunun bir register olmasini dusundum. Fakat yaptigim tanim dogrumu emin degilim.
Error gayet güzel açıklamış;
pwm_reg[9] e farklı yerlerde atama yapmışsınız, bilgisayar programı gibi sırayla değil hepsi aynı anda olduğu için farklı yerlerde atama yapılamaz kısa devre olur ;D tek procss içinde atama yapabilirsiniz.
Alıntı yapılan: z - 06 Aralık 2018, 11:31:34Gelistirme ortamini kurdum ve calisti.
Yukaridaki programda pek cok hata verdi. Aciklamalarin onune -- isareti koymak gerekiyor.
se IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity pwm is
Port(
in_clk : in std_logic ; -- Clock
in_rst : in std_logic ; -- Reset
in_ld : in std_logic ; -- Load
in_data : in std_logic_vector(9 downto 0);
out_data : out std_logic
);
end pwm;
architecture Tanimlamalar of pwm is
signal pwm_shadow_reg : std_logic_vector(9 downto 0);
signal pwm_reg : std_logic_vector(9 downto 0);
signal pwm_cnt : std_logic_vector(9 downto 0);
signal pwm_clk : std_logic;
begin
pwm_clk <= in_clk ;
-- PWM Data Portunu PWM Registerine okuma islemi
process(pwm_clk, in_ld)
begin
if rising_edge(pwm_clk) then
if in_ld = '1' then
pwm_reg <= in_data;
end if;
end if;
end process;
-- Resetleme ve sayma islemi
process(pwm_clk, in_rst)
begin
if in_rst = '1' then
pwm_cnt <= (others=>'0');
pwm_reg <= (others=>'0');
pwm_shadow_reg <= (others=>'0');
elsif rising_edge(pwm_clk) then
if pwm_cnt = 1023 then
pwm_cnt <= (others=>'0');
pwm_shadow_reg <= pwm_reg;
else
pwm_cnt <= pwm_cnt + 1;
end if;
end if;
end process;
-- PWM sinyali uretme islemi
process(pwm_clk)
begin
if rising_edge(pwm_clk) then
if pwm_cnt < pwm_shadow_reg then
out_data <= '1';
else
out_data <= '0';
end if;
end if;
end process;
end Tanimlamalar;
Bu programdaki ERROR:HDLCompiler:1401 - "/home/ise/MyProject/PWM.vhd" Line 35: Signal pwm_reg[9] in unit pwm is connected to following multiple drivers:
Hatasini yok edemiyorum.
pwm_reg tanimladim ve bunun bir register olmasini dusundum. Fakat yaptigim tanim dogrumu emin degilim.
Hocam problemin nedeni aynı sinyale iki farklı noktadan değer ataması yapmanız. Kaba bir benzetme yaparsam "signal" yapıları bir yazılım dilindeki global değişkenlere benzetilebilir. Fakat bir farkla bir sinyale sadece tek bir yerden değer atanabilir. Fakat istenilen yerden o değere erişilebilir.
Sizin örneğinizde pem_reg sinyaline ilk process de atama yapmışsınız in_data ile. Fakat ikinci process'in reset kısmında değerini sıfırlamaya çalışmışsınız. pwm_reg içeriğini sıfırlamak için değer atadığınız process içerisindeki rst kısmında yapın bu işlemi.
10 bitlik pwm_reg registerine sadece cipin 10 pininden gelen datayi yukluyorum. Baska bir atama yokki.
Bu satir da asagida.
pwm_reg <= in_data;
Reset ile sifirlamaya calistigim yerde bu registeri olusturan Flip floplarin reset pinine sinyal yollanmiyor mu?
Ama evet orada registere 0 yukledim. Dogru.
Peki bahsettigim sekilde resetleme islemi nasil yapilir?
Yada program nasil isler hale getirilir?
Alıntı yapılan: z - 06 Aralık 2018, 13:26:3110 bitlik pwm_reg registerine sadece cipin 10 pininden gelen datayi yukluyorum. Baska bir atama yokki.
Bu satir da asagida.
pwm_reg <= in_data;
Hocam aşağıdaki kodun rst kımına bakarsanız orada değeri sıfırlamışsınız,
pwm_reg <= (others => '0')-- Resetleme ve sayma islemi
process(pwm_clk, in_rst)
begin
if in_rst = '1' then
pwm_cnt <= (others=>'0');
pwm_reg <= (others=>'0');
pwm_shadow_reg <= (others=>'0');
elsif rising_edge(pwm_clk) then
if pwm_cnt = 1023 then
pwm_cnt <= (others=>'0');
pwm_shadow_reg <= pwm_reg;
else
pwm_cnt <= pwm_cnt + 1;
end if;
end if;
end process;
Evet evet anladim.
Peki bir registeri sifirlamanin iki yolu var.
- Deger yukleyerek
- Reset pinini sinyal uygulayarak.
2. secenekle Resetleme yapamazmiyim? Nasil yaparim?
@z hocam ilk process kısmına da bir rst işlemi ekleyip o regin içeriğinin sıfırlanmasını sağlayabilirsiniz. Örneğin:
process(pwm_clk, in_rst, in_ld)
begin
if in_rst = '1' then
pwm_reg <= (others=>'0');
elsif rising_edge(pwm_clk) then
if in_ld = '1' then
pwm_reg <= in_data;
end if;
end if;
end process;
Alıntı yapılan: z - 06 Aralık 2018, 13:35:45Evet evet anladim.
Peki bir registeri sifirlamanin iki yolu var.
- Deger yukleyerek
- Reset pinini sinyal uygulayarak.
2. secenekle Resetleme yapamazmiyim? Nasil yaparim?
Aslında hocam hepsi aynı kapıya çıkıyor. Kodun rst kısmı sizin istediğiniz başlangıç değerlerini oluşturuyor. Bu durumda yaptığınz şey aslında o sinyale değer yüklemek. Reset konumunda ilgili sinyale istediğiniz değeri (türüne uygun olarak) atayabilirsiniz. Her zaman 1 ya da 0 olmak zorunda değil. Örneğin başlangıç konumunda (resetlendiğinde) değeri 512 olsun derseniz onu atarsınız. Her resetlendiğinde register içeriği 512 değerini alır.
Demek istedigim
10 bitlik pwm_reg registeri 10 adet FF dan olusuyor.
Bu FF'larin D girisine Clk esliginde 0 yuklersem registere sifir yazmis olurum.
Fakat bu FFlarin R girisine sinyal verirsem de registerime sifir yuklemis olurum.
pwm_reg.R=1 gibi bir numara cekemiyormuyuz?
Sematik cizimde bu resetleme sinyali ile registeri sifirlama isini kolayca asabilirdik.
Herhalde VHDL de de benzer bir cozum vardir.
Neyse onerdiginiz degisikligi yapip devam edeyim.
Alıntı yapılan: z - 06 Aralık 2018, 13:46:01Demek istedigim
10 bitlik pwm_reg registeri 10 adet FF dan olusuyor.
Bu FF'larin D girisine Clk esliginde 0 yuklersem registere sifir yazmis olurum.
Fakat bu FFlarin R girisine sinyal verirsem de registerime sifir yuklemis olurum.
pwm_reg.R=1 gibi bir numara cekemiyormuyuz?
Sematik cizimde bu resetleme sinyali ile registeri sifirlama isini kolayca asabilirdik.
Herhalde VHDL de de benzer bir cozum vardir.
Neyse onerdiginiz degisikligi yapip devam edeyim.
Hocam zaten önerdiğim yöntem dediğiniz şey ile aynı. Size örnek verdiğim kod parçası asenkron reset olarak geçer. Yani clock girişnden bağımsız olarak etki eder. O yüzden pwm_reg <= (others => '0') yaptığımda (kodun rst kımında yapıyorum bu atamayı) rst girişlerine uygulamış oluyorum. Eğer değerlerini 1 olarak ayarlarsam da set girişlerine bağlanmış oluyor. D girişlerine değer atamıyorum doğrudan rst ya da set kısmına erişmiş oluyorum.
Anladim.
Kodlar hatasiz derlendi.
Simdi kodlari verecegim test giris verilerine gore test etmek istiyorum.
CPLD ile calisirken bir dosyaya test vektorleri olusturuyor ve bu girdilere karsilik devrenin degisik noktalarindaki sinyalleri sanal lojik analyzer cihazinda gorebiliyorduk.
xilinx in bu toolunda bu isi nasil yapacagim?
Paralel 10 bit veri yuklenen ve PWM sinyali ureten kodumun en son hali asagida.
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity pwm is
Port(
in_data : in std_logic_vector (9 downto 0);
in_clk : in std_logic ; -- Clock
in_rst : in std_logic ; -- Reset
in_ld : in std_logic ; -- Load
out_data : out std_logic
);
end pwm;
architecture Tanimlamalar of pwm is
signal pwm_shadow_reg : std_logic_vector(9 downto 0);
signal pwm_reg : std_logic_vector (9 downto 0);
signal pwm_cnt : std_logic_vector(9 downto 0);
signal pwm_clk : std_logic;
begin
pwm_clk <= in_clk ;
process(pwm_clk, in_rst, in_ld)-- PWM Data Portunu PWM Registerine aktarma, resetleme vs islemleri
begin
if in_rst = '1' then
pwm_cnt <= (others=>'0');
pwm_reg <= (others=>'0');
pwm_shadow_reg <= (others=>'0');
else
if rising_edge(pwm_clk) then
pwm_cnt <= pwm_cnt + 1;
if pwm_cnt < pwm_shadow_reg then
out_data <= '1';
else
out_data <= '0';
end if;
if in_ld = '1' then
pwm_reg <= in_data;
end if;
if pwm_cnt = 1023 then
pwm_shadow_reg <= pwm_reg;
end if;
end if;
end if;
end process;
end Tanimlamalar;
Alıntı yapılan: z - 06 Aralık 2018, 15:08:04Kodlar hatasiz derlendi.
Simdi kodlari verecegim test giris verilerine gore test etmek istiyorum.
CPLD ile calisirken bir dosyaya test vektorleri olusturuyor ve bu girdilere karsilik devrenin degisik noktalarindaki sinyalleri sanal lojik analyzer cihazinda gorebiliyorduk.
xilinx in bu toolunda bu isi nasil yapacagim?
Paralel 10 bit veri yuklenen ve PWM sinyali ureten kodumun en son hali asagida.
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity pwm is
Port(
in_data : in std_logic_vector (9 downto 0);
in_clk : in std_logic ; -- Clock
in_rst : in std_logic ; -- Reset
in_ld : in std_logic ; -- Load
out_data : out std_logic
);
end pwm;
architecture Tanimlamalar of pwm is
signal pwm_shadow_reg : std_logic_vector(9 downto 0);
signal pwm_reg : std_logic_vector (9 downto 0);
signal pwm_cnt : std_logic_vector(9 downto 0);
signal pwm_clk : std_logic;
begin
pwm_clk <= in_clk ;
process(pwm_clk, in_rst, in_ld)-- PWM Data Portunu PWM Registerine aktarma, resetleme vs islemleri
begin
if in_rst = '1' then
pwm_cnt <= (others=>'0');
pwm_reg <= (others=>'0');
pwm_shadow_reg <= (others=>'0');
else
if rising_edge(pwm_clk) then
pwm_cnt <= pwm_cnt + 1;
if pwm_cnt < pwm_shadow_reg then
out_data <= '1';
else
out_data <= '0';
end if;
if in_ld = '1' then
pwm_reg <= in_data;
end if;
if pwm_cnt = 1023 then
pwm_shadow_reg <= pwm_reg;
end if;
end if;
end if;
end process;
end Tanimlamalar;
Hocam Xilinx ISE de proje dosyalarını gösteren pencerinin hemen üstünde Implementation ve Simulataion şeklinde iki seçenek var. Simulation seçimini yaparsanız kodlarınızı Xilinx iSim ile test edebilirsiniz.
Simulation seçince vhdl dosyanınız seçin ardından altındaki pencerede "
Simulate Behavioral Model" kısmını seçin simülasyon programı açılır Buradam elle giriş vererek benzetim yapabilirsiniz. Ya da bu işi kendiliğinden yapmasını isterseniz VHDL TestBench dosyası hazırlayıp otomatik olarak yaptırabilirsiniz.
Tesekkurler evet gordum ve biraz kurcaladim ama hic bir sey anlamadim.
Bir video arastirayim.
10 Bit PWM simulasyonu icin en azindan 1024 clock palsi gerekecegi icin
simulasyonun kolay ve anlasilir olmasi acisindan pwm uretimini 10 bit degil de 4 bit yapacagim.
Bunun icin kodu keske en basinda parametrik yapsaydim tek parametre ile pwm cozunurlugunu degistirebilseydim. Neyse duzeltmek icin gec degil.
Test dosyasi ici doldurulmak uzere olustu.
Bu asamayi anlatacak olan varmi?
for n= 0 to 32
if n=1 then in_data=8;
if (n=2) or (n=4) then in_ld=1 else rst=0
if n=3 then in_rst=1 else rst=0;
if n>4 then in_clk=(n and 1)
next n
benzeri bir yazim yapabilecekmiyim?
Bu test kodu yazim isini anlatmak isteyen var mi?
Hocam şu an için vaktim yok detaylar için ama ekte bir testbench kodu gönderiyorum. Sanırım biraz fikir verir. SPI haberleşmesi için yaptığım bir kod idi.
library IEEE;
use IEEE.STD_LOGIC_1164.all;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
use IEEE.NUMERIC_STD.all;
-- Uncomment the following library declaration if instantiating
-- any Xilinx leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity spiTestBench is
-- Port ( );
end spiTestBench;
architecture Behavioral of spiTestBench is
component spiCore is
port (
clk : in std_logic;
rst : in std_logic;
ena : in std_logic;
sw : in std_logic_vector(15 downto 8);
led : out std_logic_vector(7 downto 0);
busy : out std_logic;
miso : in std_logic;
mosi : out std_logic;
sclk : out std_logic;
cs : out std_logic);
end component spiCore;
signal clk : std_logic := '0';
signal rst : std_logic := '0';
signal ena : std_logic := '0';
signal addr : std_logic_vector(7 downto 0) := X"00";
signal led : std_logic_vector(7 downto 0) := X"00";
signal busy : std_logic := '0';
signal miso : std_logic := '0';
signal mosi : std_logic := '0';
signal sclk : std_logic := '0';
signal cs : std_logic := '0';
signal command : std_logic_vector(15 downto 0) := X"0000";
signal answer : std_logic_vector(23 downto 0) := X"0000AD";
constant CLK_PERIOD : time := 10 ns;
begin
U1 : spiCore
port map (
clk => clk,
rst => rst,
ena => ena,
sw => addr,
led => led,
busy => busy,
miso => miso,
mosi => mosi,
sclk => sclk,
cs => cs);
CLKGEN : process
begin -- process CLKGEN
clk <= '0';
wait for CLK_PERIOD/2;
clk <= '1';
wait for CLK_PERIOD/2;
end process CLKGEN;
RUN : process
begin -- process RUN
rst <= '0';
ena <= '0';
addr <= X"01";
wait for CLK_PERIOD*10;
rst <= '1';
ena <= '0';
wait for CLK_PERIOD*10;
ena <= '1';
wait until busy = '1';
ena <= '0';
wait;
end process RUN;
SPISLV : process (sclk, rst, cs) is
begin -- process SPISLV
if rst = '0' then -- asynchronous reset (active low)
answer <= X"0000AD";
elsif sclk'event and sclk = '1' then -- rising clock edge
if (cs = '0') then
miso <= answer(23);
answer <= answer(22 downto 0) & '0';
end if;
end if;
end process SPISLV;
end Behavioral;
Fazlasi ile isime yaradi. Tesekkurler. Simulasyonu yaptim.
Test kodlarimi barindiran dosyam asagida.
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--USE ieee.numeric_std.ALL;
ENTITY test IS
END test;
ARCHITECTURE behavior OF test IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT pwm
PORT(
in_data : IN std_logic_vector(3 downto 0);
in_clk : IN std_logic;
in_rst : IN std_logic;
in_ld : IN std_logic;
out_data : OUT std_logic
);
END COMPONENT;
--Inputs
signal in_data : std_logic_vector(3 downto 0) := (others => '0');
signal in_clk : std_logic := '0';
signal in_rst : std_logic := '0';
signal in_ld : std_logic := '0';
--Outputs
signal out_data : std_logic;
-- Clock period definitions
constant in_clk_period : time := 10 ns;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: pwm PORT MAP (
in_data => in_data,
in_clk => in_clk,
in_rst => in_rst,
in_ld => in_ld,
out_data => out_data
);
-- Clock process definitions
in_clk_process :process
begin
in_clk <= '0';
wait for in_clk_period/2;
in_clk <= '1';
wait for in_clk_period/2;
end process;
-- Stimulus process
stim_proc: process
begin
-- hold reset state for 100 ns.
wait for 100 ns;
wait for in_clk_period*10;
-- insert stimulus here
in_data<= X"3";
wait for in_clk_period*2;
in_ld<='1';
wait for in_clk_period*2;
in_ld<='0';
in_rst<='1';
wait for in_clk_period*2;
in_rst<='0';
wait for in_clk_period*2;
in_data<=X"8";
wait for in_clk_period*2;
in_ld<='1';
wait for in_clk_period*20;
in_ld<='0';
in_data<=X"4";
wait for in_clk_period*2;
in_ld<='1';
wait for in_clk_period*20;
end process;
END;
Sabah VHDL nedir nasil yazilir hic fikrim yokken 12 saat icinde picprojenin degerli uyeleri ve www.vhdl.club sitesi yazarlari sayesinde kod yazabilir hale geldim.
Simdiki amacim;
PWM blogu datayi paralel porttan aliyordu. FPGA ile ARM islemciyi paralel data bus uzerinden baglamak isime gelmiyor. PWM verilerini SPI uzerinden gonderecegim.
Bu durumda FPGA icine SPI unitesi eklemek gerekecek.
Fakat daha once su soruya cevap bulmam gerekiyor.
Su ana kadar yazdigim kodlar 10 bitlik bir PWM donanimina aitti.
Simdi 3 tane daha PWM blogu ekleyecegim. Fakat daha onceki pwm kodlamasini fonksiyona/module donusturmek istiyorum.
4 pwm blogunu olustururken bu fonksiyondan yararlanacagim.
Bu isi nasil yaparim?
Aksi halde kodlari pespese copy paste ile yapistirarak editlemem gerekecek bu kodu uzatacak goz korkutucu olmaya baslayacak.
Alıntı yapılan: z - 06 Aralık 2018, 17:28:36Fazlasi ile isime yaradi. Tesekkurler. Simulasyonu yaptim.
Test kodlarimi barindiran dosyam asagida.
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--USE ieee.numeric_std.ALL;
ENTITY test IS
END test;
ARCHITECTURE behavior OF test IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT pwm
PORT(
in_data : IN std_logic_vector(3 downto 0);
in_clk : IN std_logic;
in_rst : IN std_logic;
in_ld : IN std_logic;
out_data : OUT std_logic
);
END COMPONENT;
--Inputs
signal in_data : std_logic_vector(3 downto 0) := (others => '0');
signal in_clk : std_logic := '0';
signal in_rst : std_logic := '0';
signal in_ld : std_logic := '0';
--Outputs
signal out_data : std_logic;
-- Clock period definitions
constant in_clk_period : time := 10 ns;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: pwm PORT MAP (
in_data => in_data,
in_clk => in_clk,
in_rst => in_rst,
in_ld => in_ld,
out_data => out_data
);
-- Clock process definitions
in_clk_process :process
begin
in_clk <= '0';
wait for in_clk_period/2;
in_clk <= '1';
wait for in_clk_period/2;
end process;
-- Stimulus process
stim_proc: process
begin
-- hold reset state for 100 ns.
wait for 100 ns;
wait for in_clk_period*10;
-- insert stimulus here
in_data<= X"3";
wait for in_clk_period*2;
in_ld<='1';
wait for in_clk_period*2;
in_ld<='0';
in_rst<='1';
wait for in_clk_period*2;
in_rst<='0';
wait for in_clk_period*2;
in_data<=X"8";
wait for in_clk_period*2;
in_ld<='1';
wait for in_clk_period*20;
in_ld<='0';
in_data<=X"4";
wait for in_clk_period*2;
in_ld<='1';
wait for in_clk_period*20;
end process;
END;
Sabah VHDL nedir nasil yazilir hic fikrim yokken 12 saat icinde picprojenin degerli uyeleri ve www.vhdl.club sitesi yazarlari sayesinde kod yazabilir hale geldim.
Simdiki amacim;
PWM blogu datayi paralel porttan aliyordu. FPGA ile ARM islemciyi paralel data bus uzerinden baglamak isime gelmiyor. PWM verilerini SPI uzerinden gonderecegim.
Bu durumda FPGA icine SPI unitesi eklemek gerekecek.
Fakat daha once su soruya cevap bulmam gerekiyor.
Su ana kadar yazdigim kodlar 10 bitlik bir PWM donanimina aitti.
Simdi 3 tane daha PWM blogu ekleyecegim. Fakat daha onceki pwm kodlamasini fonksiyona/module donusturmek istiyorum.
4 pwm blogunu olustururken bu fonksiyondan yararlanacagim.
Bu isi nasil yaparim?
Aksi halde kodlari pespese copy paste ile yapistirarak editlemem gerekecek bu kodu uzatacak goz korkutucu olmaya baslayacak.
Hocam anahtar kelime COMPONENT. Size verdiğim örnek testbench kodunda ben mesela spiCore tasarımını component olarak ekledim. ardından aşağıda giriş ve çıkışlarını bağladım. Siz de bir pwm tasarımını component olarak bir kere ekler aşağıda istediğiniz kadar kullanabilirsiniz. Örneğin :
MODULE0: pwm PORT MAP (
in_data => in_data_0,
in_clk => in_clk,
in_rst => in_rst,
in_ld => in_ld,
out_data => out_data_0
);
MODULE1: pwm PORT MAP (
in_data => in_data_1,
in_clk => in_clk,
in_rst => in_rst,
in_ld => in_ld,
out_data => out_data_1
);