00001 LIBRARY IEEE;
00002 USE IEEE.STD_LOGIC_1164.ALL;
00003 USE ieee.numeric_std.ALL;
00004
00005 --USE IEEE.STD_LOGIC_ARITH.ALL;
00006 --USE IEEE.STD_LOGIC_UNSIGNED.ALL;
00007 --USE IEEE.STD_LOGIC_SIGNED.ALL;
00008
00009
00010 ENTITY compteur IS
00011 GENERIC ( Nb_bascules : natural := 1
00012 );
00013 PORT ( AB : IN (1 DOWNTO 0);
00014 cpt : OUT (7 DOWNTO 0);
00015 clk : IN ;
00016 INV : IN
00017 );
00018 END compteur;
00019
00020 ARCHITECTURE Behavioral OF compteur IS
00021 TYPE tableau IS ARRAY (Nb_bascules downto 0) OF (1 DOWNTO 0);
00022 SIGNAL A_B : tableau;
00023
00024 SIGNAL tmp : (7 DOWNTO 0);
00025 BEGIN
00026
00027 -- double latch des codeurs
00028 copie : PROCESS
00029 BEGIN
00030 WAIT UNTIL rising_edge(clk) ;
00031
00032 A_B(0)<= AB(1) & (AB(0) XOR INV);
00033
00034 FOR i IN 1 TO Nb_bascules LOOP
00035 A_B(i) <= A_B(i-1);
00036 END LOOP;
00037
00038 END PROCESS copie;
00039
00040
00041
00042 -- decodage de la quadrature et comptage
00043 comptage: PROCESS
00044 BEGIN
00045 WAIT UNTIL falling_edge(clk) ;
00046
00047
00048 IF (A_B(Nb_bascules-1) = "00" and A_B(Nb_bascules) = "01") OR (A_B(Nb_bascules-1) = "01" AND A_B(Nb_bascules) = "11") OR (A_B(Nb_bascules-1) = "11" AND A_B(Nb_bascules) = "10") OR (A_B(Nb_bascules-1) = "10" AND A_B(Nb_bascules) = "00") THEN
00049 tmp <= tmp - 1;
00050
00051 ELSIF (A_B(Nb_bascules) = "00" and A_B(Nb_bascules-1) = "01") OR (A_B(Nb_bascules) = "01" AND A_B(Nb_bascules-1) = "11") OR (A_B(Nb_bascules) = "11" AND A_B(Nb_bascules-1) = "10") OR (A_B(Nb_bascules) = "10" AND A_B(Nb_bascules-1) = "00") THEN
00052 tmp <= tmp + 1;
00053
00054 END IF;
00055 END PROCESS comptage;
00056
00057 cpt <= tmp;
00058
00059 END Behavioral;