Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- entity program is
- Port(
- DATA_A : in std_logic;
- CLK_A : out std_logic; -- zegar generowany w FPGA
- CNV : out std_logic;
- DATA_B : out std_logic_vector(7 downto 0);
- CLK_B : out std_logic;
- PAR_B : out std_logic;
- CLK : in std_logic); -- to ten wewnętrzny 10MHz
- end entity
- Architecture Behavioral of program is
- signal register : std_logic_vector(7 downto 0) <= '00000000'; -- sygnał który otrzymujemy z A/D a następnie dajemy na DATA_B
- signal even : std_logic <= '0' -- parzystość danych
- generate_CLK_A : process(CLK) -- proces który na podstawie CLK generuje CLK_A dla A/D
- variable counter : integer := 0; -- pomocniczo
- begin
- if rising_edge(CLK) then
- counter := counter +1;
- if counter = 1 then -- wystawiamy '0' do CNV
- CNV <= '0';
- else
- CNV <= '1';
- end if
- 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:
- CLK_A <= NOT CLK_A; -- zmienia się co takt zegara CLK
- elsif counter = 1000 then
- counter := 0 -- po 100us chcemy odbierać znowu
- end if;
- end if
- end generat_CLK_A;
- READ : process(CLK_A) --odbieramy DATA_A z A/D
- variable counter : integer:=0;
- variable buf : std_logic_vector(7 downto 0); -- pomocniczo, na dane 8 bitów
- variable temp : std_logic;
- variable temp_even : std_logic; -- pomocniczo przy liczeniu parzystości
- begin
- if falling_edge(CLK_A) then -- zbocze opadające próbkuje dane
- temp := DATA_A;
- end if
- if rising_edge(CLK_A) then -- zbocze rosnące robi rejestr przesówny
- buf(counter) := temp; -- przypisujemu od bitu 0'wego
- counter := counter +1;
- if counter = 8 then -- jak się wyśle wszystko to od nowa
- counter:= 0;
- register <= buf; -- przepisujemy do sygnału otrzymany bajt danych
- temp_even := NOT ( (buf(0) xor buf(1)) xor (buf(2) xor buf(3)) xor (buf(4)
- 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)
- even <= temp_even;
- end if
- end if
- end process
- WRITE_B : process(CLK)
- variable counter : INTEGER:=0;
- if rising_edge(CLK)
- case counter is
- when 1 =>
- DATA_B <= register;
- PAR_B <= even;
- when 1001 =>
- CLK_B := '0';
- when 3501 =>
- CLK_B := '1';
- when 5001 =>
- DATA_B <= '11111111';
- when others => null
- end case;
- counter := counter + 1;
- end if
- end process
- end architecture
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement