Advertisement
Himanshu2016

Lab 2 Group 11 VHDL Code

Oct 18th, 2023
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 20.44 KB | None | 0 0
  1. Counter5Periods.VHDL
  2. library ieee;
  3. use ieee.std_logic_1164.all;
  4. use ieee.std_logic_unsigned.all;
  5.  
  6. entity Counter5Periods is
  7.     port (
  8.         clock: in std_logic;
  9.         i_resetBar: in std_logic;
  10.         output: out std_logic
  11.     );
  12. end entity Counter5Periods;
  13.  
  14. architecture Behavioral of Counter5Periods is
  15.     signal counter: natural range 0 to 5 := 0; -- Counter initialized to 0
  16.  
  17. begin
  18.     process (clock, i_resetBar)
  19.     begin
  20.         if i_resetBar = '0' then
  21.             counter <= 0; -- Reset the counter to 0
  22.             output <= '1'; -- Set output to '0' on reset
  23.         elsif rising_edge(clock) then
  24.             if counter < 3 then
  25.                 counter <= counter + 1; -- Increment the counter
  26.                 output <= '1'; -- Set output to '1' during the first 5 clock periods
  27.             else
  28.                 output <= '0'; -- Set output to '0' after the first 5 clock periods
  29.             end if;
  30.         end if;
  31.     end process;
  32. end architecture Behavioral;
  33.  
  34. debouncer_2.VHDL
  35. LIBRARY ieee;
  36. USE ieee.std_logic_1164.ALL;
  37.  
  38. ENTITY debouncer_2 IS
  39.     PORT(
  40.         i_resetBar      : IN    STD_LOGIC;
  41.         i_clock         : IN    STD_LOGIC;
  42.         i_raw           : IN    STD_LOGIC;
  43.         o_clean         : OUT   STD_LOGIC);
  44. END debouncer_2;
  45.  
  46. ARCHITECTURE rtl OF debouncer_2 IS
  47.     SIGNAL con_vcc : STD_LOGIC;
  48.     SIGNAL int_notQ1Output, int_q1Output, int_notD1Input, int_d1Input :STD_LOGIC;
  49.     SIGNAL int_q2Output, int_notQ2Output, int_d2Input, int_debouncedRaw, int_feedback : STD_LOGIC;
  50.  
  51.     COMPONENT enARdFF_2
  52.         PORT(
  53.             i_resetBar  : IN    STD_LOGIC;
  54.             i_d     : IN    STD_LOGIC;
  55.             i_enable    : IN    STD_LOGIC;
  56.             i_clock     : IN    STD_LOGIC;
  57.             o_q, o_qBar : OUT   STD_LOGIC);
  58.     END COMPONENT;
  59. BEGIN
  60.     con_vcc <= '1';
  61. first: enARdFF_2
  62.     PORT MAP (i_resetBar => i_resetBar,
  63.               i_d => int_notD1Input,
  64.               i_enable => con_vcc,
  65.               i_clock => i_clock,
  66.               o_q => int_q1Output,
  67.               o_qBar => int_notQ1Output);
  68.  
  69. second: enARdFF_2
  70.     PORT MAP (i_resetBar => i_resetBar,
  71.               i_d => int_d2Input,
  72.               i_enable => con_vcc,
  73.               i_clock => i_clock,
  74.               o_q => int_q2Output,
  75.               o_qBar => int_notQ2Output);
  76.  
  77.     -- Internal concurrent signal assignment
  78.     int_notD1Input <= not(int_d1Input);
  79.     int_d1Input <= i_raw nand int_feedback;
  80.     int_feedback <= int_q2Output or int_debouncedRaw;
  81.     int_d2Input <= int_notQ1Output and int_notQ2Output and i_raw;
  82.     int_debouncedRaw <= int_q2Output nor int_notQ1Output;
  83.  
  84.     --  Output Concurrent Signal Assignment
  85.     o_clean <= int_debouncedRaw;
  86.  
  87. END rtl;
  88.  
  89.  
  90. dec_7seg.VHDL
  91. library ieee;
  92. use  ieee.std_logic_1164.all;
  93.  
  94. ENTITY dec_7seg IS
  95.     PORT(i_hexDigit : IN STD_LOGIC_VECTOR(3 downto 0);
  96.          o_segment: OUT STD_LOGIC_VECTOR(0 to 6));
  97. END dec_7seg;
  98.  
  99. ARCHITECTURE rtl OF dec_7seg IS
  100.     SIGNAL int_segment_data : STD_LOGIC_VECTOR(6 DOWNTO 0);
  101. BEGIN
  102.     PROCESS  (i_hexDigit)
  103.     BEGIN
  104.         CASE i_hexDigit IS
  105.                 WHEN "0000" =>
  106.                     int_segment_data <= "1111110";
  107.                 WHEN "0001" =>
  108.                     int_segment_data <= "0110000";
  109.                 WHEN "0010" =>
  110.                     int_segment_data <= "1101101";
  111.                 WHEN "0011" =>
  112.                     int_segment_data <= "1111001";
  113.                 WHEN "0100" =>
  114.                     int_segment_data <= "0110011";
  115.                 WHEN "0101" =>
  116.                     int_segment_data <= "1011011";
  117.                 WHEN "0110" =>
  118.                     int_segment_data <= "1011111";
  119.                 WHEN "0111" =>
  120.                     int_segment_data <= "1110000";
  121.                 WHEN "1000" =>
  122.                     int_segment_data <= "1111111";
  123.                 WHEN "1001" =>
  124.                     int_segment_data <= "1111011";
  125.                 WHEN "1010" =>
  126.                     int_segment_data <= "1110111";
  127.                 WHEN "1011" =>
  128.                     int_segment_data <= "0011111";
  129.                 WHEN "1100" =>
  130.                     int_segment_data <= "1001110";
  131.                 WHEN "1101" =>
  132.                     int_segment_data <= "0111101";
  133.                 WHEN "1110" =>
  134.                     int_segment_data <= "1001111";
  135.                 WHEN "1111" =>
  136.                     int_segment_data <= "1000111";
  137.             WHEN OTHERS =>
  138.                     int_segment_data <= "0111110";
  139.         END CASE;
  140.     END PROCESS;
  141.  
  142. -- LED driver is inverted
  143. o_segment <= NOT int_segment_data;
  144.  
  145. END rtl;
  146.  
  147.  
  148. enARdFF_2.VHDL
  149. LIBRARY ieee;
  150. USE ieee.std_logic_1164.ALL;
  151.  
  152. ENTITY enARdFF_2 IS
  153.     PORT(
  154.         i_resetBar  : IN    STD_LOGIC;
  155.         i_d     : IN    STD_LOGIC;
  156.         i_enable    : IN    STD_LOGIC;
  157.         i_clock     : IN    STD_LOGIC;
  158.         o_q, o_qBar : OUT   STD_LOGIC);
  159. END enARdFF_2;
  160.  
  161. ARCHITECTURE rtl OF enARdFF_2 IS
  162.     SIGNAL int_q : STD_LOGIC;
  163.  
  164. BEGIN
  165.  
  166. oneBitRegister:
  167. PROCESS(i_resetBar, i_clock)
  168. BEGIN
  169.     IF (i_resetBar = '0') THEN
  170.         int_q   <= '0';
  171.     ELSIF (i_clock'EVENT and i_clock = '1') THEN
  172.         IF (i_enable = '1') THEN
  173.             int_q   <=  i_d;
  174.         END IF;
  175.     END IF;
  176. END PROCESS oneBitRegister;
  177.  
  178.     --  Output Driver
  179.  
  180.     o_q     <=  int_q;
  181.     o_qBar      <=  not(int_q);
  182.  
  183. END rtl;
  184.  
  185.  
  186. enARdFF_2rev.VHDL
  187. LIBRARY ieee;
  188. USE ieee.std_logic_1164.ALL;
  189.  
  190. ENTITY enARdFF_2rev IS
  191.     PORT(
  192.         i_resetBar  : IN    STD_LOGIC;
  193.         i_d     : IN    STD_LOGIC;
  194.         i_enable    : IN    STD_LOGIC;
  195.         i_clock     : IN    STD_LOGIC;
  196.         o_q, o_qBar : OUT   STD_LOGIC);
  197. END enARdFF_2rev;
  198.  
  199. ARCHITECTURE rtl OF enARdFF_2rev IS
  200.     SIGNAL int_q : STD_LOGIC;
  201.  
  202. BEGIN
  203.  
  204. oneBitRegister:
  205. PROCESS(i_resetBar, i_clock)
  206. BEGIN
  207.     IF (i_resetBar = '0') THEN
  208.         int_q   <= '1';
  209.     ELSIF (i_clock'EVENT and i_clock = '1') THEN
  210.         IF (i_enable = '1') THEN
  211.             int_q   <=  i_d;
  212.         END IF;
  213.     END IF;
  214. END PROCESS oneBitRegister;
  215.  
  216.     --  Output Driver
  217.  
  218.     o_q     <=  int_q and i_enable;
  219.     o_qBar      <=  not(int_q) and i_enable;
  220.  
  221. END rtl;
  222.  
  223.  
  224. Encoder2x1sl.VHDL
  225. library ieee;
  226. use ieee.std_logic_1164.all;
  227.  
  228. entity Encoder2x1sl is
  229.     port (
  230.         I1, I0: in std_logic;
  231.         O: out std_logic_vector(1 downto 0)
  232.     );
  233. end;
  234.  
  235. architecture rtl of Encoder2x1sl is
  236. begin
  237.     process(I1, I0)
  238.     begin
  239.         if (I1 = '1') then
  240.             O <= "01";
  241.         elsif (I0 = '1') then
  242.             O <= "10";
  243.         else
  244.             O <= "00"; -- Optionally handle the case when neither input is active.
  245.         end if;
  246.     end process;
  247. end architecture rtl;
  248.  
  249.  
  250. Encoder2x1sr.VHDL
  251. library ieee;
  252. use ieee.std_logic_1164.all;
  253.  
  254. entity Encoder2x1sr is
  255.     port (
  256.         I1, I0: in std_logic;
  257.         O: out std_logic_vector(1 downto 0)
  258.     );
  259. end;
  260.  
  261. architecture rtl of Encoder2x1sr is
  262. begin
  263.     process(I1, I0)
  264.     begin
  265.         if (I1 = '1') then
  266.             O <= "01";
  267.         elsif (I0 = '1') then
  268.             O <= "11";
  269.         else
  270.             O <= "00"; -- Optionally handle the case when neither input is active.
  271.         end if;
  272.     end process;
  273. end architecture rtl;
  274.  
  275.  
  276. fourBitAdder.VHDL
  277. library ieee;
  278. use ieee.std_logic_1164.all;
  279.  
  280. entity fourBitAdder is
  281.     port (
  282.         i_X, i_Y: in std_logic_vector(3 downto 0);
  283.         i_Cin: in std_logic;
  284.         o_S: out std_logic_vector(3 downto 0);
  285.         o_Cout: out std_logic;
  286.         o_P, o_G: out std_logic;
  287.         o_V, o_Z: out std_logic
  288.     );
  289. end;
  290.  
  291. architecture Structural of fourBitAdder is
  292.     component oneBitFullAdder
  293.         port (
  294.             i_X, i_Y: in std_logic;
  295.             i_Cin: in std_logic;
  296.             o_S: out std_logic;
  297.             o_Cout: out std_logic;
  298.             o_P, o_G: out std_logic
  299.         );
  300.     end component;
  301.    
  302.     component LookaheadCarryUnit
  303.         port (
  304.             i_P, i_G: in std_logic_vector(3 downto 0);
  305.             i_Cin: in std_logic;
  306.             o_PG, o_GG: out std_logic;
  307.             o_C: out std_logic_vector(4 downto 0)
  308.         );
  309.     end component;
  310.    
  311.     signal signalFullAdderCarry: std_logic_vector(4 downto 0);
  312.     signal signalFullAdderG, signalFullAdderP: std_logic_vector(3 downto 0);
  313.     signal signalS: std_logic_vector(3 downto 0);
  314. begin
  315.     generateFullAdder:
  316.         for i in 3 downto 0 generate
  317.             fullAdderInst: oneBitFullAdder
  318.                 port map (
  319.                     i_X => i_X(i),
  320.                     i_Y => i_Y(i),
  321.                     i_Cin => signalFullAdderCarry(i),
  322.                     o_S => signalS(i),
  323.                     o_P => signalFullAdderP(i),
  324.                     o_G => signalFullAdderG(i)
  325.                 );
  326.         end generate;
  327.    
  328.     lookaheadCarryUnitInst: LookaheadCarryUnit
  329.         port map (
  330.             i_P => signalFullAdderP,
  331.             i_G => signalFullAdderG,
  332.             i_Cin => i_Cin,
  333.             o_C => signalFullAdderCarry,
  334.             o_PG => o_P,
  335.             o_GG => o_G
  336.         );
  337.    
  338.     o_S <= signalS;
  339.     o_Cout <= signalFullAdderCarry(4);
  340.     o_V <= signalFullAdderCarry(4) xor signalFullAdderCarry(3);
  341.     o_Z <= not (signalS(3) or signalS(2) or signalS(1) or signalS(0));
  342. end;
  343.  
  344.  
  345.  
  346. fourBitAdderSubtractor.VHDL
  347. library ieee;
  348. use ieee.std_logic_1164.all;
  349.  
  350. entity fourBitAdderSubtractor is
  351.     port (
  352.         i_X, i_Y: in std_logic_vector(3 downto 0);
  353.         i_SUB: in std_logic;
  354.         o_S: out std_logic_vector(3 downto 0);
  355.         o_Cout: out std_logic;
  356.         o_V, o_Z: out std_logic
  357.     );
  358. end;
  359.  
  360. architecture Structural of fourBitAdderSubtractor is
  361.     component fourBitAdder
  362.         port (
  363.             i_X, i_Y: in std_logic_vector(3 downto 0);
  364.             i_Cin: in std_logic;
  365.             o_S: out std_logic_vector(3 downto 0);
  366.             o_Cout: out std_logic;
  367.             o_P, o_G: out std_logic;--lookahead
  368.             o_V, o_Z: out std_logic--overflow flag(V); zero flag(Z)
  369.         );
  370.     end component;
  371.    
  372.     signal signalY: std_logic_vector(3 downto 0);
  373. begin
  374.     generateSignalY:
  375.         for i in 3 downto 0 generate
  376.             signalY(i) <= i_Y(i) xor i_SUB;
  377.         end generate;
  378.    
  379.     adder4Inst: fourBitAdder
  380.         port map (
  381.             i_X => i_X,
  382.             i_Y => signalY,
  383.             i_Cin => i_SUB,
  384.             o_S => o_S,
  385.             o_Cout => o_Cout,
  386.             o_V => o_V,
  387.             o_Z => o_Z
  388.         );
  389. end;
  390.  
  391.  
  392.  
  393. Gnd4bit.VHDL
  394. library ieee;
  395. use ieee.std_logic_1164.all;
  396.  
  397. entity Gnd4bit is
  398.     port(
  399.         OUTPUT: out std_logic_vector(3 downto 0)
  400.     );
  401. end;
  402.  
  403. architecture Rtl of Gnd4bit is
  404.     begin
  405.     OUTPUT <= "0000";
  406. end Rtl;
  407.  
  408.  
  409.  
  410.  
  411. LookaheadCarryUnit.VHDL
  412. library ieee;
  413. use ieee.std_logic_1164.all;
  414.  
  415. entity LookaheadCarryUnit is
  416.     port (
  417.         i_P, i_G: in std_logic_vector(3 downto 0);
  418.         i_Cin: in std_logic;
  419.         o_PG, o_GG: out std_logic;
  420.         o_C: out std_logic_vector(4 downto 0)
  421.     );
  422. end;
  423.  
  424. architecture Structural of LookaheadCarryUnit is
  425. begin
  426.     o_C(0) <= i_Cin;
  427.     o_C(1) <= i_G(0) or (i_P(0) and i_Cin);
  428.     o_C(2) <= i_G(1) or (i_P(1) and i_G(0)) or (i_P(1) and i_P(0) and i_Cin);
  429.     o_C(3) <= i_G(2) or (i_P(2) and i_G(1)) or (i_P(2) and i_P(1) and i_G(0)) or (i_P(2) and i_P(1) and i_P(0) and i_Cin);
  430.     o_C(4) <= i_G(3) or (i_P(3) and i_G(2)) or (i_P(3) and i_P(2) and i_G(1)) or (i_P(3) and i_P(2) and i_P(1) and i_G(0)) or (i_P(3) and i_P(2) and i_P(1) and i_P(0) and i_Cin);
  431.    
  432.     o_PG <= i_P(3) and i_P(2) and i_P(1) and i_P(0);
  433.     o_GG <= i_G(3) or (i_P(3) and i_G(2)) or (i_P(3) and i_P(2) and i_G(1)) or (i_P(3) and i_P(2) and i_P(1) and i_G(0));
  434. end;
  435.  
  436.  
  437.  
  438. LSBTaker.VHDL
  439. library ieee;
  440. use ieee.std_logic_1164.all;
  441.  
  442. entity LSBTaker is
  443.     port(
  444.         INPUT: in std_logic_vector(3 downto 0);
  445.           OUTPUT: out std_logic
  446.     );
  447. end;
  448.  
  449. architecture Rtl of LSBTaker is
  450.     begin
  451.     OUTPUT <= INPUT(0);
  452. end Rtl;
  453.  
  454.  
  455.  
  456. MUX4bit2x1.VHDL
  457. library ieee;
  458. use ieee.std_logic_1164.all;
  459.  
  460. entity MUX4bit2x1 is
  461.     port(
  462.         I1,I0: in std_logic_vector(3 downto 0);
  463.         OUTPUT: out std_logic_vector(3 downto 0);
  464.         C: in std_logic
  465.     );
  466. end;
  467.  
  468. architecture Rtl of MUX4bit2x1 is
  469.     begin
  470.     OUTPUT(3) <= (I1(3) AND C) OR (I0(3) AND not(C));
  471.      OUTPUT(2) <= (I1(2) AND C) OR (I0(2) AND not(C));
  472.      OUTPUT(1) <= (I1(1) AND C) OR (I0(1) AND not(C));
  473.      OUTPUT(0) <= (I1(0) AND C) OR (I0(0) AND not(C));
  474. end Rtl;
  475.  
  476.  
  477.  
  478. MUX4x1.VHDL
  479. library ieee;
  480. use ieee.std_logic_1164.all;
  481.  
  482. entity MUX4x1 is
  483.     port(
  484.         INPUT: in std_logic_vector(3 downto 0);
  485.         OUTPUT: out std_logic;
  486.         C: in std_logic_vector(1 downto 0)
  487.     );
  488. end;
  489.  
  490. architecture Rtl of MUX4x1 is
  491.     begin
  492.     OUTPUT <= (INPUT(3) AND C(1) AND C(0)) OR
  493.                     (INPUT(2) AND C(1) AND not(C(0))) OR
  494.                     (INPUT(1) AND not(C(1)) AND C(0)) OR
  495.                     (INPUT(0) AND not(C(1)) AND not(C(0)));
  496. end Rtl;
  497.  
  498.  
  499.  
  500. MUX8bit4x1.VHDL
  501. library ieee;
  502. use ieee.std_logic_1164.all;
  503.  
  504. entity MUX8bit4x1 is
  505.     port (
  506.         I3, I2, I1, I0: in std_logic_vector(7 downto 0);
  507.         O: out std_logic_vector(7 downto 0);
  508.         C: in std_logic_vector(1 downto 0)
  509.     );
  510. end;
  511.  
  512. ARCHITECTURE rtl OF MUX8bit4x1 IS
  513.     BEGIN
  514.        
  515.         O(0) <= (C(1)AND C(0) AND I3(0)) OR (not(C(1))AND C(0) AND  I2(0)) OR (C(1) AND not(C(0)) AND I1(0)) OR(not(C(1)) AND not(C(0)) AND I0(0));
  516.         O(1) <= (C(1)AND C(0) AND I3(1)) OR (not(C(1))AND C(0) AND  I2(1)) OR (C(1) AND not(C(0)) AND I1(1)) OR(not(C(1)) AND not(C(0)) AND I0(1));
  517.         O(2) <= (C(1)AND C(0) AND I3(2)) OR (not(C(1))AND C(0) AND  I2(2)) OR (C(1) AND not(C(0)) AND I1(2)) OR(not(C(1)) AND not(C(0)) AND I0(2));
  518.         O(3) <= (C(1)AND C(0) AND I3(3)) OR (not(C(1))AND C(0) AND  I2(3)) OR (C(1) AND not(C(0)) AND I1(3)) OR(not(C(1)) AND not(C(0)) AND I0(3));
  519.         O(4) <= (C(1)AND C(0) AND I3(4)) OR (not(C(1))AND C(0) AND  I2(4)) OR (C(1) AND not(C(0)) AND I1(4)) OR(not(C(1)) AND not(C(0)) AND I0(4));
  520.         O(5) <= (C(1)AND C(0) AND I3(5)) OR (not(C(1))AND C(0) AND  I2(5)) OR (C(1) AND not(C(0)) AND I1(5)) OR(not(C(1)) AND not(C(0)) AND I0(5));
  521.         O(6) <= (C(1)AND C(0) AND I3(6)) OR (not(C(1))AND C(0) AND  I2(6)) OR (C(1) AND not(C(0)) AND I1(6)) OR(not(C(1)) AND not(C(0)) AND I0(6));
  522.         O(7) <= (C(1)AND C(0) AND I3(7)) OR (not(C(1))AND C(0) AND  I2(7)) OR (C(1) AND not(C(0)) AND I1(7)) OR(not(C(1)) AND not(C(0)) AND I0(7));
  523.    
  524.     END rtl;
  525.  
  526.  
  527.  
  528. oneBitFullAdder.VHDL
  529. library ieee;
  530. use ieee.std_logic_1164.all;
  531.  
  532. entity oneBitFullAdder is
  533.     port (
  534.         i_X, i_Y: in std_logic;
  535.         i_Cin: in std_logic;
  536.         o_S: out std_logic;
  537.         o_Cout: out std_logic;
  538.         o_P, o_G: out std_logic
  539.     );
  540. end oneBitFullAdder;
  541.  
  542. architecture Structural of oneBitFullAdder is
  543. begin
  544.     o_S <= i_X xor i_Y xor i_Cin;
  545.     o_Cout <= (i_X and i_Y) or (i_Cin and i_X) or (i_Cin and i_Y);
  546.     o_P <= i_X or i_Y;
  547.     o_G <= i_X and i_Y;
  548. end;
  549.  
  550.  
  551. Register4.VHDL
  552. LIBRARY ieee;
  553. USE ieee.std_logic_1164.ALL;
  554.  
  555. ENTITY Register4 IS
  556.     PORT(
  557.         i_resetBar, i_load  : IN    STD_LOGIC;
  558.         i_clock         : IN    STD_LOGIC;
  559.         i_Value         : IN    STD_LOGIC_VECTOR(3 downto 0);
  560.         o_Value         : OUT   STD_LOGIC_VECTOR(3 downto 0));
  561. END Register4;
  562.  
  563. ARCHITECTURE rtl OF Register4 IS
  564.     SIGNAL int_Value, int_notValue : STD_LOGIC_VECTOR(3 downto 0);
  565.  
  566.     COMPONENT enARdFF_2
  567.         PORT(
  568.             i_resetBar  : IN    STD_LOGIC;
  569.             i_d     : IN    STD_LOGIC;
  570.             i_enable    : IN    STD_LOGIC;
  571.             i_clock     : IN    STD_LOGIC;
  572.             o_q, o_qBar : OUT   STD_LOGIC);
  573.     END COMPONENT;
  574.  
  575. BEGIN
  576.  
  577. msb: enARdFF_2
  578.     PORT MAP (i_resetBar => i_resetBar,
  579.               i_d => i_Value(3),
  580.               i_enable => i_load,
  581.               i_clock => i_clock,
  582.               o_q => int_Value(3),
  583.               o_qBar => int_notValue(3));
  584.  
  585. qsb: enARdFF_2
  586.     PORT MAP (i_resetBar => i_resetBar,
  587.               i_d => i_Value(2),
  588.               i_enable => i_load,
  589.               i_clock => i_clock,
  590.               o_q => int_Value(2),
  591.               o_qBar => int_notValue(2));
  592.  
  593. wsb: enARdFF_2
  594.     PORT MAP (i_resetBar => i_resetBar,
  595.               i_d => i_Value(1),
  596.               i_enable => i_load,
  597.               i_clock => i_clock,
  598.               o_q => int_Value(1),
  599.               o_qBar => int_notValue(1));
  600.                  
  601. esb: enARdFF_2
  602.     PORT MAP (i_resetBar => i_resetBar,
  603.               i_d => i_Value(0),
  604.               i_enable => i_load,
  605.               i_clock => i_clock,
  606.               o_q => int_Value(0),
  607.               o_qBar => int_notValue(0));
  608.      
  609.  
  610.     -- Output Driver
  611.     o_Value     <= int_Value;
  612.  
  613. END rtl;
  614.  
  615.  
  616.  
  617.  
  618. shiftleftR.VHDL
  619. library ieee;
  620. use ieee.std_logic_1164.all;
  621.  
  622. entity shiftleftR is
  623.     port (
  624.         I0: in std_logic;
  625.         O: out std_logic_vector(1 downto 0)
  626.     );
  627. end;
  628.  
  629. architecture rtl of shiftleftR is
  630. begin
  631.     process(I0)
  632.     begin
  633.         if (I0 = '1') then
  634.             O <= "10";
  635.           else
  636.             O <= "00"; -- Optionally handle the case when neither input is active.
  637.         end if;
  638.     end process;
  639. end architecture rtl;
  640.  
  641.  
  642.  
  643. ShiftRegister4.VHDL
  644. library ieee;
  645. use ieee.std_logic_1164.all;
  646.  
  647. entity ShiftRegister4 is
  648.     port (
  649.         CLK, RESETN: in std_logic;
  650.         MODE: in std_logic_vector(1 downto 0);
  651.         SERIAL_IN_LEFT, SERIAL_IN_RIGHT: in std_logic;
  652.         PARALLEL_IN: in std_logic_vector(3 downto 0);
  653.         PARALLEL_OUT: out std_logic_vector(3 downto 0)
  654.     );
  655.     -- MODE: 00 for latching, 01 for parallel loading, 10 for shifting left, 11 for shifting right
  656. end;
  657.  
  658. architecture Structural of ShiftRegister4 is
  659.     component enARdFF_2 is
  660.         port (
  661.             i_resetBar: in std_logic;
  662.             i_d: in std_logic;
  663.             i_enable: in std_logic;
  664.             i_clock: in std_logic;
  665.             o_q, o_qBar: out std_logic
  666.         );
  667.     end component;
  668.    
  669.     component MUX4x1 is
  670.         port(
  671.             INPUT: in std_logic_vector(3 downto 0);
  672.             OUTPUT: out std_logic;
  673.             C: in std_logic_vector(1 downto 0)
  674.         );
  675.     end component;
  676.    
  677.     signal signalDFFOutput: std_logic_vector(3 downto 0);
  678.     signal signalMUXOutput: std_logic_vector(3 downto 0);
  679.     signal signalMUXInputLeftShift: std_logic_vector(3 downto 0);
  680.     signal signalMUXInputRightShift: std_logic_vector(3 downto 0);
  681. begin
  682.     signalMUXInputLeftShift(0) <= SERIAL_IN_RIGHT;
  683.     signalMUXInputLeftShift(3 downto 1) <= signalDFFOutput(2 downto 0);
  684.     signalMUXInputRightShift(3) <= SERIAL_IN_LEFT;
  685.     signalMUXInputRightShift(2 downto 0) <= signalDFFOutput(3 downto 1);
  686.    
  687.     generateMUX: for i in 3 downto 0 generate
  688.         MUX4x1Inst: MUX4x1
  689.             port map (
  690.                 INPUT(3) => signalMUXInputRightShift(i),
  691.                 INPUT(2) => signalMUXInputLeftShift(i),
  692.                 INPUT(1) => PARALLEL_IN(i),
  693.                 INPUT(0) => signalDFFOutput(i),
  694.                 OUTPUT => signalMUXOutput(i),
  695.                 C => MODE
  696.             );
  697.     end generate;
  698.    
  699.     generateDFF: for i in 3 downto 0 generate
  700.         DFFInst: enARdFF_2
  701.             port map (
  702.                 i_resetBar => RESETN,
  703.                 i_d => signalMUXOutput(i),
  704.                 i_enable => '1',
  705.                 i_clock => CLK,
  706.                 o_q => signalDFFOutput(i)
  707.             );
  708.     end generate;
  709.    
  710.     PARALLEL_OUT <= signalDFFOutput;
  711. end;
  712.  
  713.  
  714.  
  715. ShiftRegister8.VHDL
  716. library ieee;
  717. use ieee.std_logic_1164.all;
  718.  
  719. entity ShiftRegister8 is
  720.     port (
  721.         CLK, RESETN: in std_logic;
  722.         MODE: in std_logic_vector(1 downto 0);
  723.         SERIAL_IN_LEFT, SERIAL_IN_RIGHT: in std_logic;
  724.         PARALLEL_IN: in std_logic_vector(7 downto 0);
  725.         PARALLEL_OUT: out std_logic_vector(7 downto 0)
  726.     );
  727.     -- MODE: 00 for latching, 01 for parallel loading, 10 for shifting left, 11 for shifting right
  728. end;
  729.  
  730. architecture Structural of ShiftRegister8 is
  731.     component enARdFF_2 is
  732.         port (
  733.             i_resetBar: in std_logic;
  734.             i_d: in std_logic;
  735.             i_enable: in std_logic;
  736.             i_clock: in std_logic;
  737.             o_q, o_qBar: out std_logic
  738.         );
  739.     end component;
  740.    
  741.     component MUX4x1 is
  742.         port(
  743.             INPUT: in std_logic_vector(3 downto 0);
  744.             OUTPUT: out std_logic;
  745.             C: in std_logic_vector(1 downto 0)
  746.         );
  747.     end component;
  748.    
  749.     signal signalDFFOutput: std_logic_vector(7 downto 0);
  750.     signal signalMUXOutput: std_logic_vector(7 downto 0);
  751.     signal signalMUXInputLeftShift: std_logic_vector(7 downto 0);
  752.     signal signalMUXInputRightShift: std_logic_vector(7 downto 0);
  753. begin
  754.     signalMUXInputLeftShift(0) <= SERIAL_IN_RIGHT;
  755.     signalMUXInputLeftShift(7 downto 1) <= signalDFFOutput(6 downto 0);
  756.     signalMUXInputRightShift(7) <= SERIAL_IN_LEFT;
  757.     signalMUXInputRightShift(6 downto 0) <= signalDFFOutput(7 downto 1);
  758.    
  759.     generateMUX: for i in 7 downto 0 generate
  760.         MUX4x1Inst: MUX4x1
  761.             port map (
  762.                 INPUT(3) => signalMUXInputRightShift(i),
  763.                 INPUT(2) => signalMUXInputLeftShift(i),
  764.                 INPUT(1) => PARALLEL_IN(i),
  765.                 INPUT(0) => signalDFFOutput(i),
  766.                 OUTPUT => signalMUXOutput(i),
  767.                 C => MODE
  768.             );
  769.     end generate;
  770.    
  771.     generateDFF: for i in 7 downto 0 generate
  772.         DFFInst: enARdFF_2
  773.             port map (
  774.                 i_resetBar => RESETN,
  775.                 i_d => signalMUXOutput(i),
  776.                 i_enable => '1',
  777.                 i_clock => CLK,
  778.                 o_q => signalDFFOutput(i)
  779.             );
  780.     end generate;
  781.    
  782.     PARALLEL_OUT <= signalDFFOutput;
  783. end;
  784.  
  785.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement