Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------------------------------------------------------------
- -- Company:
- -- Engineer:
- --
- -- Create Date: 17:20:24 04/28/2017
- --Zadatak 3:
- --Napisati VHDL model 4-bitnog registra sa serijskim upisom i paralelnim čitanjem koji će pored ulanzog porta za podatke
- --imati i sledeće ulazne portove:
- -- clock enable (ce) signal za selekciju rastućih ivica clk ulaza na koje registar treba da reaguje
- -- ulazni port dozvole upisa novog sadržaja u registar - we (write enable)
- -- ulazni port dozvole čitanja trenutnog sadržaja iz registra - read ili re (read enable).
- -- Kada je re port jednak 0 na Q izlazu registra treba da stoji vrednost "0000",
- -- a ako je re port jednak 1 na Q izlazu registra treba da stoji tekuća vrednost koja se nalazi smeštena u registru.
- -- ulazni portove za inicijalizaciju sadržaja registra - clear i preset
- --Za razvijeni VHDL model napisai odgovarajući testbenč pomoću kojega će biti moguće izvršiti funkcionalnu verifikaciju modela.
- ----------------------------------------------------------------------------------
- library IEEE;
- use IEEE.STD_LOGIC_1164.ALL;
- entity REGISTER_4BIT_SIPO is
- PORT(
- CLK : in std_logic;
- D : in std_logic;
- CE: in std_logic;
- WE: in std_logic;
- RE: in std_logic;
- CLEAR: in std_logic;
- PRESET: in std_logic;
- Q: out std_logic_vector(3 downto 0)
- );
- end REGISTER_4BIT_SIPO;
- architecture Behavioral of REGISTER_4BIT_SIPO is
- signal REG_FILE_s : std_logic_vector(3 downto 0);
- begin
- SIPO_REG : process(CLK, PRESET, CLEAR)
- begin
- -- preset ima veci priroritet ovaj put - nije receno - biram prozvoljno
- if (PRESET = '1') then
- REG_FILE_s <= (others => '1');
- else
- if(CLEAR = '1') then
- REG_FILE_s <= (others => '0');
- else
- -- unutar CLK if-dela, ne treba nikakav else za signale, nece praviti LATCHEVE!
- -- PRAVICE FLIP-FLOPOVE OD TOGA PA NEMA INCOMPLETE ASSIGNMENTA!
- if(CLK'event and CLK = '1') then
- if(CE = '1') then
- if(WE = '1') then
- -- When used in arrays, downto corresponds to little endian.
- -- This means that the least significant bit is stored at the lowest position.
- -- So in L downto R, L corresponds to the Most Significant Bit (MSB) and R to
- -- the Least Significant Bit (LSB). to corresponds to big endian. So in L to R, L is the LSB and R the MSB.
- -- STD_LOGIC_VECTOR(15 donwto 0) ===> 15 je indeks MSB-a
- REG_FILE_s <= REG_FILE_s(2 downto 0) & D; -- Q = 1101 , Q(3 downto 1) = 110
- -- Q(2 downto 0) = 101
- -- D cu da kacim na LSB!
- -- znaci Q pomeram u levo 1 mesto
- -- i imam 101 i D lepim sa desne strane
- -- Dakle Q(2 downto 0) & D
- -- 101 & D
- -- REG_FILE_s <= D & Q(3 downto 1); -- ovako bi bilo da sam ULAZ gurao na MSB
- -- U OVOM SLUCAJU LSB OTPADA SVAKI PUT
- end if;
- end if;
- end if;
- end if;
- end if;
- end process;
- Q <= REG_FILE_s when RE = '1' else X"0";
- end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement