VHDL ile ilk program denemem hakkinda?

Başlatan z, 06 Aralık 2018, 06:18:43

z

#15
Anladim.
Bana e^st de diyebilirsiniz.   www.cncdesigner.com

z

#16
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;
Bana e^st de diyebilirsiniz.   www.cncdesigner.com

muuzoo

#17
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.

gunluk.muuzoo.gen.tr - Kişisel karalamalarım...

z

Tesekkurler evet gordum ve biraz kurcaladim ama hic bir sey anlamadim.

Bir video arastirayim.
Bana e^st de diyebilirsiniz.   www.cncdesigner.com

z

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?

Bana e^st de diyebilirsiniz.   www.cncdesigner.com

muuzoo

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;

gunluk.muuzoo.gen.tr - Kişisel karalamalarım...

z

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.
Bana e^st de diyebilirsiniz.   www.cncdesigner.com

muuzoo

#22
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
        );
gunluk.muuzoo.gen.tr - Kişisel karalamalarım...