library ieee; use ieee.std_logic_1164.all; entity compare_block is port(CLK :in std_logic; RSTN : in std_logic; r1 :in std_logic ; ---input from the ir sensors from all sides r2 :in std_logic ; r3 :in std_logic ; r4 :in std_logic ; C1 : out std_logic_vector(2 downto 0); --giving out the count value from the vehicle counter C2 : out std_logic_vector(2 downto 0); C3 : out std_logic_vector(2 downto 0); C4 : out std_logic_vector(2 downto 0); in1 : out std_logic_vector(2 downto 0); --giving out the count value from the vehicle counter in2 : out std_logic_vector(2 downto 0); in3 : out std_logic_vector(2 downto 0); in4 : out std_logic_vector(2 downto 0)); end entity compare_block ; architecture functionality of compare_block is component BC_bit is port(I :in std_logic_vector(4 downto 0); O: out std_logic_vector(2 downto 0)); end component; component vehicle_counter2 is port(CLK :in std_logic; RSTN : in std_logic; I1 :in std_logic ; outp : out std_logic_vector(2 downto 0)); end component; signal S1,S2,S3,S4,L : std_logic_vector(2 downto 0); type ARr is array (0 to 3) of std_logic_vector(2 downto 0); type AR is array (0 to 3) of integer range 0 to 4; signal ind : AR:=(0,0,0,0); signal S : ARr ; --begin --process(r1,r2,r3,r4) begin U0 : vehicle_counter2 port map(CLK,RSTN,r1,S1); --S1 stores the R1 counted value U1 : vehicle_counter2 port map(CLK,RSTN,r2,S2); U2 : vehicle_counter2 port map(CLK,RSTN,r3,S3); U3 : vehicle_counter2 port map(CLK,RSTN,r4,S4); --A : BC_bit port map (S(0),C1); --B : BC_bit port map (S(1),C2); --C : BC_bit port map (S(2),C3); --D : BC_bit port map (S(3),C4); --in1 <= to_unsigned(ind(0), 3); --in2 <= to_unsigned(ind(1), 3); --in3 <= to_unsigned(ind(2), 3); --in4 <= to_unsigned(ind(3), 3); --C1<=S(0); --C2<=S(1); --C3<=S(2); --C4<=S(3); process(S1,S2,S3,S4) begin --if (S1 < S2 ) then --L <= S2; --index(3) <=2; --elsif(S1 = S2) then L <= S1; index(3) <= 1; --elsif (S1>S2) then L <= S1; index(3) <= 1; --end if; --if (L < S3) then --L <= S3;index(3) <= 3; --elsif(L = S3) then L <= L ; index(3) <= index(3); --elsif (L>S3) then L <= L ; index(3) <= index(3); --end if; --if (L < S4) then --L <= S4;index(3) <= 4; --elsif(L = S4) then L <= L ; index(3) <= index(3); --elsif (L > S4) then L <= L ; index(3) <= index(3); --end if; if(S1S3 and S4S3 and S4>S3) then C1 <= S1;C2<= S2; C3<=S4; C4<=S3; in1 <="001";in2<="010";in3<="100";in4<="011"; elsif( S1=S2 and S1>S3 and S4=S3) then C1 <= S1;C2<= S2; C3<=S3; C4<=S4; in1 <="001";in2<="010";in3<="011";in4<="100"; elsif( S1=S2 and S1S1 and S1=S2 and S1S3) then C1 <= S4;C2<= S3; C3<=S1; C4<=S2; in1 <="100";in2<="011";in3<="001";in4<="010"; elsif(S4>S1 and S1=S2 and S1S1 and S1=S2 and S1>S3) then C1 <= S4;C2<= S1; C3<=S2; C4<=S3; in1 <="100";in2<="001";in3<="010";in4<="011"; elsif(S4S2 and S2>S4 ) then C1 <= S1;C2<= S3; C3<=S2; C4<=S4; in1 <="001";in2<="011";in3<="010";in4<="100"; elsif(S4S2 and S2S2 and S2=S4 ) then C1 <= S1;C2<= S3; C3<=S2; C4<=S4; in1 <="001";in2<="011";in3<="010";in4<="100"; elsif( S1=S3 and S1S1 and S1=S3 and S1S1 and S1=S3 and S1S4) then C1 <= S2;C2<= S4; C3<=S1; C4<=S3; in1 <="010";in2<="100";in3<="001";in4<="011"; elsif(S4S1 and S1=S3 and S1>S2) then C1 <= S4;C2<= S1; C3<=S3; C4<=S2; in1 <="100";in2<="001";in3<="011";in4<="010"; elsif(S2S3 and S3S3 and S3>S2) then C1 <= S1;C2<= S4; C3<=S3; C4<=S2; in1 <="001";in2<="100";in3<="011";in4<="010"; elsif( S1=S4 and S1>S3 and S3=S2) then C1 <= S1;C2<= S4; C3<=S2; C4<=S3; in1 <="001";in2<="100";in3<="010";in4<="011"; elsif( S1=S4 and S1S1 and S1=S4 and S1S1 and S1=S4 and S1>S3) then C1 <= S2;C2<= S1; C3<=S4; C4<=S3; in1 <="010";in2<="001";in3<="100";in4<="011"; elsif(S4S1 and S1S1 and S1>S4) then C1 <= S2;C2<= S3; C3<=S1; C4<=S4; in1 <="010";in2<="011";in3<="001";in4<="100"; elsif( S3=S2 and S2>S1 and S1=S4) then C1 <= S2;C2<= S3; C3<=S1; C4<=S4; in1 <="010";in2<="011";in3<="001";in4<="100"; elsif( S3=S2 and S2S2 and S3=S2 and S2S4) then C1 <= S1;C2<= S4; C3<=S2; C4<=S3; in1 <="001";in2<="100";in3<="010";in4<="011"; elsif(S4>S2 and S3=S2 and S2S2 and S3=S2 and S2>S1) then C1 <= S4;C2<= S2; C3<=S3; C4<=S1; in1 <="100";in2<="010";in3<="011";in4<="001"; elsif(S1S3 and S1S3 and S1>S3) then C1 <= S2;C2<= S4; C3<=S1; C4<=S3; in1 <="010";in2<="100";in3<="001";in4<="011"; elsif( S4=S2 and S2>S3 and S1=S3) then C1 <= S2;C2<= S4; C3<=S1; C4<=S3; in1 <="010";in2<="100";in3<="001";in4<="011"; elsif( S4=S2 and S2S2 and S4=S2 and S2S3) then C1 <= S1;C2<= S3; C3<=S2; C4<=S4; in1 <="001";in2<="011";in3<="010";in4<="100"; elsif(S1>S2 and S4=S2 and S2S2 and S4=S2 and S2>S3) then C1 <= S1;C2<= S2; C3<=S4; C4<=S3; in1 <="001";in2<="010";in3<="100";in4<="011"; elsif(S1S2 and S1S2 and S1>S2) then C1 <= S3;C2<= S4; C3<=S1; C4<=S2; in1 <="011";in2<="100";in3<="001";in4<="010"; elsif(S3=S4 and S3>S2 and S1=S2) then C1 <= S3;C2<= S4; C3<=S1; C4<=S2; in1 <="011";in2<="100";in3<="001";in4<="010"; elsif(S3=S4 and S3S3 and S3=S4 and S3S2) then C1 <= S1;C2<= S2; C3<=S3; C4<=S4; in1 <="001";in2<="010";in3<="011";in4<="100"; elsif(S1>S3 and S3=S4 and S3S3 and S3=S4 and S3>S2) then C1 <= S1;C2<= S3; C3<=S4; C4<=S2; in1 <="001";in2<="011";in3<="100";in4<="010"; elsif(S4S1 and S1=S2 and S1=S3) then C1 <= S4;C2<= S1; C3<=S2; C4<=S3; in1 <="100";in2<="001";in3<="010";in4<="011"; elsif(S4=S1 and S1=S2 and S1S3) then C1 <= S1;C2<= S2; C3<=S4; C4<=S3; in1 <="001";in2<="010";in3<="100";in4<="011"; elsif(S4=S1 and S1>S2 and S1=S3) then C1 <= S1;C2<= S3; C3<=S4; C4<=S2; in1 <="001";in2<="011";in3<="100";in4<="010"; elsif(S4=S1 and S1S1 and S4=S2 and S2=S3) then C1 <= S2;C2<= S3; C3<=S4; C4<=S1; in1 <="010";in2<="011";in3<="100";in4<="001"; elsif(S4=S1 and S1=S2 and S1=S3) then C1 <= S1;C2<= S2; C3<=S3; C4<=S4; in1 <="001";in2<="010";in3<="011";in4<="100"; --in1 <= std_logic_vector(to_unsigned(ind(0), 3)); --C1<=S(0); --C2<=S(1); --C3<=S(2); --C4<=S(3); --1,2 --1,3 --1,4 --2,3 --2,4 --3,4 --1,2,3 --1,2,4 --1,3,4 --2,3,4 --1,2,3,4 end if; end process; end functionality;