-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCounts_Quarter.vhd
executable file
·142 lines (129 loc) · 2.83 KB
/
Counts_Quarter.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
Library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
Entity Counts_Quarter is
Port(
CLK,Rstb : in std_logic;
i1ms,i1s : in std_logic;
iStart,iFinish : in std_logic;
sOverC,fOverC : in std_logic;
O_LED : out std_logic_vector(4 downto 0);
oRe : out std_logic
);
End Counts_Quarter;
Architecture Behavioral of Counts_Quarter is
type State_Type is (S1,S2,S3,S4);
signal state : State_Type;
signal wO : std_logic_vector(3 downto 0);
signal wS,wF,wRe : std_logic := '0';
signal wOver : std_logic;
signal wSO,wSOv : std_logic := '0';
Begin
O_LED <= wOver & wO;
oRe <= wRe;
u_Count1 : Process(CLK,Rstb,wRe)
Begin
if(Rstb='0' or wRe='1') then
wS <= '0';
wF <= '0';
elsif(rising_edge(CLK)) then
if(iStart='1') then
wS <= '1';
wF <= '0';
elsif(iFinish='1') then
wF <= '1';
wS <= '0';
else
wS <= wS;
wF <= wF;
end if;
end if;
end Process;
u_Count2 : Process(CLK,Rstb)
Begin
if(Rstb='0') then
wO <= (others => '0');
state <= S1;
elsif(rising_edge(CLK)) then
case state is
when S1 => if(i1s='1' and wS='1') then
wO(0) <= not wO(0);
wRe <= '0';
elsif(i1ms='1' and wF='1') then
wO(0) <= '1';
wRe <= '1';
state <= S2;
else
wO(0) <= wO(0);
wRe <= '0';
end if;
when S2 => if(i1s='1' and wS='1') then
wO(1) <= not wO(1);
wRe <= '0';
elsif(i1ms='1' and wF='1') then
wO(1) <= '1';
wRe <= '1';
state <= S3;
else
wO(1) <= wO(1);
wRe <= '0';
end if;
when S3 => if(i1s='1' and wS='1') then
wO(2) <= not wO(2);
wRe <= '0';
elsif(i1ms='1' and wF='1') then
wO(2) <= '1';
wRe <= '1';
state <= S4;
else
wO(2) <= wO(2);
wRe <= '0';
end if;
when S4 => if(i1s='1' and wS='1') then
wO(3) <= not wO(3);
wRe <= '0';
elsif(i1ms='1' and wF='1') then
wO(3) <= '1';
wRe <= '0';
else
wO(3) <= wO(3);
wRe <= '0';
end if;
when others => state <= S1;
end case;
end if;
end Process;
u_CountO1 : Process(CLK,Rstb)
Begin
if(Rstb='0') then
wSO <= '0';
wSOv <= '0';
elsif(rising_edge(CLK)) then
if(sOverC='1') then
wSO <= '1';
wSOv <= '0';
elsif(fOverC='1') then
wSOv <= '1';
wSO <= '0';
else
wSO <= wSO;
wSOv <= wSOv;
end if;
end if;
end Process;
u_CountO2 : Process(CLK,Rstb)
Begin
if(Rstb='0') then
wOver <= '0';
elsif(rising_edge(CLK)) then
if(i1s='1' and wSO='1') then
wOver <= not wOver;
elsif(i1ms='1' and wSOv='1') then
wOver <= '1';
else
wOver <= wOver;
end if;
end if;
end Process;
End Behavioral;