CodeurIncrémental

De troyesGEII
Aller à : navigation, rechercher


library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;

entity codeur is
port
(
  clk 	:  in std_logic;
  ina 		:  in std_logic;
  inb		:	in std_logic;
  int		:	in std_logic;
  tourne	:	out std_logic;
  sangle	:	out integer range 0 to 799
);
end codeur;


architecture codeursync of codeur is
signal a,b,t,aa,ab : std_logic;
signal	 angle_c : integer range 0 to 799;
begin

change: process(clk)
variable	 angle : integer range 0 to 799;
variable	 startok : std_logic :='0';
begin

	if (clk'event and clk='1') then
		aa <= a; 	ab <= b;
		a <= ina;	b <= inb;	t <= int;
		
		tourne <= '1';
		
		if ((t='1')and(a='0')and(b='0')and((not(angle=0))or(startok='0'))) then
			angle := 0;
			startok := '1';
	   elsif (startok='1') then
			if ((ab='0')and(b='1')) then
				if (a='1') then
					angle := angle + 1;
				else
					angle := angle - 1;
				end if;
			elsif ((ab='1')and(b='0')) then
				if (a='1') then
					angle := angle - 1;
				else
					angle := angle + 1;
				end if;
			elsif ((aa='0')and(a='1')) then
				if (b='0') then
					angle := angle + 1;
				else
					angle := angle - 1;
				end if;
			elsif ((aa='1')and(a='0')) then
				if (b='1') then
					angle := angle + 1;
				else
					angle := angle - 1;
				end if;
			end if;
		else
			angle := angle;
			tourne <= '0';
		end if;
		if (angle=800) then angle:=0; end if;
		if (angle=1023) then angle:=799; end if;
		angle_c<=angle;
end if;
end process change;

sangle <= angle_c;

end codeursync;