-
Notifications
You must be signed in to change notification settings - Fork 0
/
fsm.vhdl
executable file
·86 lines (82 loc) · 1.88 KB
/
fsm.vhdl
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
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity clocked_fsm is
port(
clk,reset : in std_logic;
start: in std_logic; -- start waveform generation
full: in std_logic; --Counter is Full
send: in std_logic;
waveform_selector: in std_logic_vector(1 downto 0);
waveform_period: in std_logic_vector(1 downto 0);
waveform_datapoints: in std_logic_vector(1 downto 0);
P: out std_logic; --Counter Toggle
CC: out std_logic; -- Clear Counter
CS: out std_logic; --Clear state memory
EN: out std_logic; --Enable Memory
LP: out std_logic --Enable Data Latch
);
end clocked_fsm;
architecture clocked_fsm_arch of clocked_fsm is
type waveform_state_type is (s0, s1, s2, s3);
signal state_reg, state_next: waveform_state_type;
begin
--State Register Logic
process(clk, reset)
begin
-- Active Low FSM Reset
if (reset = '0')
then state_reg <=s0;
elsif (clk'event and clk ='1')
then state_reg <= state_next;
end if;
end process;
--Next State Logic
process(state_reg, start, send)
begin
case state_reg is
when s0 =>
if (start ='1') then state_next <= s1;
else state_next <= s0;
end if;
when s1 =>
if (start ='0') then state_next <= s1;
else state_next <= s2;
end if;
when s2 =>
if (start ='0') then state_next <= s2;
else
if(send = '1') then state_next <= s3;
else state_next <= s2;
end if;
end if;
when s3 =>
if (start ='0') then state_next <= s3;
else state_next <= s1;
end if;
end case;
end process;
--Moore Output Logic
process(state_reg)
begin
case state_reg is
when s0 =>
P <= '0';
CC <= '0';
CS <= '1';
EN <= '1';
LP <= '0';
when s1 =>
P <= '0';
CC <= '1';
CS <= '0';
EN <= '0';
LP <= '0';
when s2 =>
LP <= '1';
when s3 =>
LP <= '0';
EN <= '1';
P <= not clk;
end case;
end process;
end clocked_fsm_arch;