1
0
Fork 0
mirror of https://github.com/RobotechLille/cdf2018-principal synced 2024-05-20 05:39:37 +02:00
cdf2018-principal/fpga/hedm.vhd

80 lines
2.7 KiB
VHDL
Raw Normal View History

2018-02-07 17:57:01 +01:00
-- Process signals from HEDM-550X encoder
-- and output the value read
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;
entity hedm is
Port (
clk : in STD_LOGIC; -- Horloge, la fréquence n'importe pas
chA : in STD_LOGIC; -- Canal A
chB : in STD_LOGIC; -- Canal B
2018-02-27 10:41:33 +01:00
reset : in STD_LOGIC; -- Hard reset
zero : in STD_LOGIC; -- Force la valeur à zéro sans réinitialiser le fonctionnement
counts : out integer
2018-02-07 17:57:01 +01:00
);
end hedm;
architecture Behavioral of hedm is
2018-05-06 01:14:09 +02:00
signal counter : integer := 0;
signal oldCounter : integer := 0;
signal An, Bn : STD_LOGIC := '0'; -- Nouvelles valeurs de A et B stockées pour que les entrées soient lues une seule fois en début de cycle
2018-02-24 16:56:57 +01:00
signal Ap, Bp : STD_LOGIC := '0'; -- Précédentes valeurs de A et B pour détecter les front montant
2018-02-07 17:57:01 +01:00
begin
2018-02-24 16:56:57 +01:00
processInput : process(clk, reset)
2018-02-07 17:57:01 +01:00
begin
2018-02-24 16:56:57 +01:00
if reset = '1' then
2018-05-06 01:14:09 +02:00
counter <= 0;
An <= '0';
Bn <= '0';
2018-02-24 16:56:57 +01:00
Ap <= '0';
Bp <= '0';
elsif rising_edge(clk) then
2018-02-07 17:57:01 +01:00
2018-05-06 01:14:09 +02:00
Ap <= An;
Bp <= Bn;
An <= chA;
Bn <= chB;
2018-02-27 10:41:33 +01:00
-- On pourrait optimiser la logique avec un tableau de Karnaugh ou autres méthodes
-- de simplification d'algèbre de Boole, mais le synthétiseur pour FPGA fera un
-- tout aussi bon travail, on garde donc le code suivant pour la lisibilité
2018-02-07 17:57:01 +01:00
2018-05-06 01:14:09 +02:00
if (Ap = '0' and An = '1') then -- Front montant A
if (Bn = '0') then
counter <= oldCounter + 1;
2018-02-07 17:57:01 +01:00
else
2018-05-06 01:14:09 +02:00
counter <= oldCounter - 1;
2018-02-07 17:57:01 +01:00
end if;
2018-05-06 01:14:09 +02:00
elsif (Ap = '1' and An = '0') then -- Front descendant A
if (Bn = '1') then
counter <= oldCounter + 1;
2018-02-07 17:57:01 +01:00
else
2018-05-06 01:14:09 +02:00
counter <= oldCounter - 1;
2018-02-07 17:57:01 +01:00
end if;
2018-05-06 01:14:09 +02:00
elsif (Bp = '0' and Bn = '1') then -- Front montant B
if (An = '1') then
counter <= oldCounter + 1;
2018-02-07 17:57:01 +01:00
else
2018-05-06 01:14:09 +02:00
counter <= oldCounter - 1;
2018-02-07 17:57:01 +01:00
end if;
2018-05-06 01:14:09 +02:00
elsif (Bp = '1' and Bn = '0') then -- Front descendant B
if (An = '0') then
counter <= oldCounter + 1;
2018-02-07 17:57:01 +01:00
else
2018-05-06 01:14:09 +02:00
counter <= oldCounter - 1;
2018-02-07 17:57:01 +01:00
end if;
2018-05-06 01:14:09 +02:00
else
counter <= oldCounter;
2018-02-07 17:57:01 +01:00
end if;
end if;
end process;
2018-05-06 01:14:09 +02:00
oldCounter <= 0 when zero = '1' else counter;
counts <= counter;
2018-02-07 17:57:01 +01:00
end Behavioral;