-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfsm.vhd
146 lines (124 loc) · 3.27 KB
/
fsm.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
--Maquina de estados del timer
--Tiene una fase inicial cuando se le introducen los numeros
--Una fase de decrementar los segundos
--Una de decrementar los minutos
--Y dos para realizar el sonido
entity FSM_timer is
port(
start : in std_logic;
clk : in std_logic;
--Entrada minutos y segundo
min : in std_logic_vector (3 downto 0);
sec : in std_logic_vector (5 downto 0);
--Se activa cada segundo que pasa
secPassed : in std_logic;
--Salidas
act_timer : out std_logic;
act_sonido : out std_logic;
min_out : out std_logic_vector (3 downto 0);
sec_out : out std_logic_vector (5 downto 0)
);
end FSM_timer;
architecture behavior of FSM_timer is
signal Qn, Qp : std_logic_vector(3 downto 0) := "0000";
signal minAux : std_logic_vector (3 downto 0) := "0000";
signal secAux : std_logic_vector (5 downto 0) := "000000";
signal minAuxB : std_logic_vector (3 downto 0) := "0000";
signal secAuxB : std_logic_vector (5 downto 0) := "000000";
--signal restador : std_logic_vector (5 downto 0) := "000000";
begin
process (Qp, min, sec, start, secPassed, secAuxB, minAuxB)
begin
case Qp is
--Estado inicial
when "0000" =>
secAux <= sec;
minAux <= min;
act_timer <= '1';
act_sonido <= '0';
if (start = '0') then
Qn <= "0001";
else
Qn <= Qp;
end if;
--Estado de conteo hacia abajo (segundos)
when "0001" =>
act_timer <= '0';
act_sonido <= '0';
--Si pasa un segundo, restarle uno a los segundos
if (secPassed = '1') then
secAux <= secAuxB - '1';
else
secAux <= secAuxB;
minAux <= minAuxB;
end if;
--Si los segundos estan en cero, ir al siguiente estado
if (secAuxB = "000000") then
Qn <= "0010";
else
Qn <= Qp;
end if;
--Resta minuto
when "0010" =>
act_timer <= '0';
act_sonido <= '0';
--Si los minutos y los segundos estan en cero significa que se acabo el tiempo
--y se va al siguiente estado
if (minAuxB = "0000") then
if (secAuxB = "000000") then
Qn <= "0011";
end if;
else
Qn <= Qp;
end if;
--Pero si no, solamente se le resta uno a los minutos
--y se ponen los segundos en 59
if (secPassed = '1') then
minAux <= minAuxB - '1';
secAux <= "111011";
Qn <= "0001";
else
secAux <= secAuxB;
minAux <= minAuxB;
end if;
--Sonar por dos segundos
when "0011" =>
act_timer <= '0';
act_sonido <= '1'; --Activar el sonido
--Si pasa un segundo, pasar al siguiente estado (seguir sonando)
if (secPassed = '1') then
Qn <= "0100";
else
Qn <= "0011";
end if;
when "0100" =>
act_timer <= '0';
act_sonido <= '1'; --Activar sonido
--Al pasar otro segundo, regresar al estado inicial
if (secPassed = '1') then
Qn <= "0000";
else
Qn <= "0100";
end if;
--Default
when others =>
Qn <= "0000";
act_timer <= '1';
act_sonido <= '0';
end case;
end process;
process(clk, Qn, minAux , secAux)
begin
if (rising_edge(CLK)) then
Qp <= Qn;
minAuxB <= minAux;
secAuxB <= secAux;
min_out <= minAux;
sec_out <= secAux;
else
end if;
end process;
end behavior;