projet-fpga/MAE.vhd

95 lines
1.8 KiB
VHDL
Raw Permalink Normal View History

2022-03-21 12:29:40 +01:00
library ieee;
use ieee.std_logic_1164.all;
entity MAE is
port(
clk : in std_logic;
reset : in std_logic;
fin_tempo : in std_logic;
fin_1 : in std_logic;
fin_0 : in std_logic;
tr_bit : in std_logic;
load : out std_logic;
shift : out std_logic;
start_tempo : out std_logic;
go_1 : out std_logic;
go_0 : out std_logic
2022-05-09 08:41:51 +02:00
2022-03-21 12:29:40 +01:00
);
end MAE;
architecture behaviour of MAE is
2022-05-09 08:41:51 +02:00
type state is (Start, LecReg, Send0, Send1, Tempo);
2022-03-21 12:29:40 +01:00
signal cs, fs : state;
2022-05-09 08:41:51 +02:00
--signal cpt : integer range 0 to 51 := 0;
2022-03-21 12:29:40 +01:00
begin
process(clk, reset)
2022-05-09 08:41:51 +02:00
variable cpt : INTEGER RANGE 0 TO 101;
2022-03-21 12:29:40 +01:00
begin
if reset = '1' then
fs <= Start;
load <= '0';
shift <= '0';
start_tempo <= '0';
go_0 <= '0';
2022-05-09 08:41:51 +02:00
go_1 <= '0';
cpt := 0;
2022-03-21 12:29:40 +01:00
elsif rising_edge(clk) then
if cs = Start then
load <= '1';
2022-05-09 08:41:51 +02:00
fs <= LecReg;
2022-03-21 12:29:40 +01:00
2022-05-09 08:41:51 +02:00
elsif cs = LecReg then
load <= '0';
2022-03-21 12:29:40 +01:00
if tr_bit = '1' then
fs <= Send1;
else
fs <= Send0;
end if;
shift <= '1';
2022-05-09 08:41:51 +02:00
cpt := cpt + 1;
2022-03-21 12:29:40 +01:00
elsif cs = Send0 then
2022-05-09 08:41:51 +02:00
shift <= '0';
2022-03-21 12:29:40 +01:00
go_0 <= '1';
if fin_0 = '1' then
go_0 <= '0';
2022-05-09 08:41:51 +02:00
if cpt >= 101 then -- on doit normalement en compter 51, mais <20>a marche pas par contre 101 c'est nickel
2022-03-21 12:29:40 +01:00
fs <= Tempo;
else
2022-05-09 08:41:51 +02:00
fs <= LecReg;
2022-03-21 12:29:40 +01:00
end if;
end if;
elsif cs = Send1 then
2022-05-09 08:41:51 +02:00
shift <= '0';
2022-03-21 12:29:40 +01:00
go_1 <= '1';
if fin_1 = '1' then
go_1 <= '0';
2022-05-09 08:41:51 +02:00
if cpt >= 101 then
2022-03-21 12:29:40 +01:00
fs <= Tempo;
else
2022-05-09 08:41:51 +02:00
fs <= LecReg;
2022-03-21 12:29:40 +01:00
end if;
end if;
elsif cs = Tempo then
start_tempo <= '1';
2022-03-21 12:30:11 +01:00
if fin_tempo = '1' then
2022-03-21 12:29:40 +01:00
start_tempo <= '0';
2022-05-09 08:41:51 +02:00
cpt := 0;
fs <= Start;
2022-03-21 12:29:40 +01:00
end if;
end if;
cs <= fs;
end if;
end process;
2022-05-09 08:41:51 +02:00
end behaviour;