Advertisement
gunigma

Kolos_ze_zdjęcia

Jan 7th, 2019
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.59 KB | None | 0 0
  1. entity program is
  2.     Port(
  3.     DATA_A : in std_logic;
  4.     CLK_A : out std_logic;      -- zegar generowany w FPGA
  5.     CNV : out std_logic;
  6.     DATA_B : out std_logic_vector(7 downto 0);
  7.     CLK_B : out std_logic;
  8.     PAR_B : out std_logic;
  9.     CLK : in std_logic);        -- to ten wewnętrzny 10MHz
  10. end entity
  11.  
  12. Architecture Behavioral of program is
  13.     signal register : std_logic_vector(7 downto 0) <= '00000000';       -- sygnał który otrzymujemy z A/D a następnie dajemy na DATA_B
  14.     signal even : std_logic <= '0'  -- parzystość danych             
  15.  
  16.     generate_CLK_A : process(CLK)                           -- proces który na podstawie CLK generuje CLK_A dla A/D
  17.             variable counter : integer := 0;                -- pomocniczo
  18.         begin
  19.             if rising_edge(CLK) then                       
  20.                 counter := counter +1;
  21.                 if counter = 1 then                         -- wystawiamy '0' do CNV
  22.                     CNV <= '0';
  23.                 else
  24.                     CNV <= '1';
  25.                 end if
  26.                 if counter > 100 %% counter < 117 then      -- odczekało 10us - tyle trwało                                                            przetwarzanie w A/D, a następnie przez kolejne 8 taktów nadaje zegar:
  27.                     CLK_A <= NOT CLK_A;                     -- zmienia się co takt zegara CLK
  28.                 elsif counter = 1000 then
  29.                     counter := 0                            -- po 100us chcemy odbierać znowu
  30.                 end if;
  31.             end if
  32.     end generat_CLK_A;
  33.                
  34.     READ : process(CLK_A)                                   --odbieramy DATA_A z A/D
  35.             variable counter : integer:=0;
  36.             variable buf : std_logic_vector(7 downto 0);    -- pomocniczo, na dane 8 bitów
  37.             variable temp : std_logic;                     
  38.             variable temp_even : std_logic;                 -- pomocniczo przy liczeniu parzystości
  39.         begin
  40.             if falling_edge(CLK_A) then         -- zbocze opadające próbkuje dane
  41.                 temp := DATA_A;
  42.             end if
  43.             if rising_edge(CLK_A) then          -- zbocze rosnące robi rejestr przesówny
  44.                 buf(counter) := temp;           -- przypisujemu od bitu 0'wego
  45.                 counter := counter +1;
  46.                 if counter = 8 then             -- jak się wyśle wszystko to od nowa
  47.                     counter:= 0;       
  48.                     register <= buf;            -- przepisujemy do sygnału otrzymany bajt danych
  49.                     temp_even := NOT ( (buf(0) xor buf(1)) xor (buf(2) xor buf(3)) xor (buf(4)
  50.                                         xor buf(5)) xor (buf(6) xor buf(7)) ) -- xor daje 0 jeśli są takie same (czyli parzyście) i 1 gdy są różne (czyli nieparzyście)
  51.                     even <= temp_even;
  52.                 end if
  53.             end if
  54.     end process
  55.  
  56.     WRITE_B : process(CLK)    
  57.         variable counter : INTEGER:=0;
  58.         if rising_edge(CLK)
  59.             case counter is
  60.                 when 1 =>
  61.                     DATA_B <= register;
  62.                     PAR_B <= even;
  63.                 when 1001 =>
  64.                     CLK_B := '0';
  65.                 when 3501 =>
  66.                     CLK_B := '1';
  67.                 when 5001 =>
  68.                     DATA_B <= '11111111';
  69.                 when others => null
  70.             end case;
  71.             counter := counter + 1;
  72.         end if
  73.     end process
  74.  
  75. end architecture
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement