Digitaluhr.vhd


1
----------------------------------------------------------------------------------
2
-- Company: 
3
-- Engineer: 
4
-- 
5
-- Create Date:    18:05:30 12/12/2014 
6
-- Design Name: 
7
-- Module Name:    Digitaluhr - Behavioral 
8
-- Project Name: 
9
-- Target Devices: 
10
-- Tool versions: 
11
-- Description: 
12
--
13
-- Dependencies: 
14
--
15
-- Revision: 
16
-- Revision 0.01 - File Created
17
-- Additional Comments: 
18
--
19
----------------------------------------------------------------------------------
20
library IEEE;
21
use IEEE.STD_LOGIC_1164.ALL;
22
use IEEE.STD_LOGIC_unsigned.ALL;
23
24
-- Uncomment the following library declaration if using
25
-- arithmetic functions with Signed or Unsigned values
26
use IEEE.NUMERIC_STD.ALL;
27
28
-- Uncomment the following library declaration if instantiating
29
-- any Xilinx primitives in this code.
30
--library UNISIM;
31
--use UNISIM.VComponents.all;
32
33
entity Digitaluhr is
34
    Port ( clk : in  STD_LOGIC;
35
           reset : in  STD_LOGIC;
36
        stunde : in STD_LOGIC;
37
        mode : in STD_LOGIC_VECTOR (1 downto 0);
38
           o_std_z : out  STD_LOGIC_VECTOR (3 downto 0);
39
           o_std_e : out  STD_LOGIC_VECTOR (3 downto 0);
40
           o_min_z : out  STD_LOGIC_VECTOR (3 downto 0);
41
           o_min_e : out  STD_LOGIC_VECTOR (3 downto 0);
42
           o_sec_z : out  STD_LOGIC_VECTOR (3 downto 0);
43
           o_sec_e : out  STD_LOGIC_VECTOR (3 downto 0);
44
       i_std_z : in  STD_LOGIC_VECTOR (3 downto 0);
45
           i_std_e : in  STD_LOGIC_VECTOR (3 downto 0);
46
           i_min_z : in  STD_LOGIC_VECTOR (3 downto 0);
47
           i_min_e : in  STD_LOGIC_VECTOR (3 downto 0);
48
           i_sec_z : in  STD_LOGIC_VECTOR (3 downto 0);
49
           i_sec_e : in  STD_LOGIC_VECTOR (3 downto 0));
50
end Digitaluhr;
51
52
architecture Behavioral of Digitaluhr is
53
54
     signal s_std_z :  STD_LOGIC_VECTOR (3 downto 0) := "0000";
55
     signal s_std_e :  STD_LOGIC_VECTOR (3 downto 0) := "0000";
56
     signal s_min_z :  STD_LOGIC_VECTOR (3 downto 0) := "0000";
57
     signal s_min_e :  STD_LOGIC_VECTOR (3 downto 0) := "0000";
58
     signal s_sec_z :  STD_LOGIC_VECTOR (3 downto 0) := "0000";
59
     signal s_sec_e :  STD_LOGIC_VECTOR (3 downto 0) := "0000";
60
61
begin
62
--
63
--test: process(i_sec_e,i_sec_z,i_min_e,i_min_z,i_std_e,i_std_z)
64
--begin
65
66
--    s_sec_e <= i_sec_e;
67
--    s_sec_z <= i_sec_z;
68
--    s_min_e <= i_min_e;
69
--    s_min_z <= i_min_z;
70
--    s_std_e <= i_std_e;
71
--    s_std_z <= i_std_z;
72
--    
73
--end process test;
74
75
modul: process(clk,reset)
76
  begin
77
  if ( reset = '1') then
78
    s_std_z <= "0000";
79
    s_std_e <= "0000";
80
    s_min_z <= "0000";
81
    s_min_e <= "0000";
82
    s_sec_z <= "0000";
83
    s_sec_e <= "0000";
84
  end if;
85
86
87
  if(clk'event and clk ='1' and mode = "00") then
88
    s_sec_e <= STD_LOGIC_VECTOR(unsigned(s_sec_e)+1);
89
    if(s_sec_e = "1001") then
90
      s_sec_e <= "0000";
91
      s_sec_z <= STD_LOGIC_VECTOR(unsigned(s_sec_z)+1);
92
          if(s_sec_z = "0101" ) then
93
            s_sec_z <= "0000";
94
            s_min_e <= STD_LOGIC_VECTOR(unsigned(s_min_e)+1);
95
              if(s_min_e = "1001") then
96
                s_min_e <= "0000";
97
                s_min_z <= STD_LOGIC_VECTOR(unsigned(s_min_z)+1);
98
                  if(s_min_z = "0101") then
99
                    s_min_z <= "0000";
100
                    s_std_e <= STD_LOGIC_VECTOR(unsigned(s_std_e)+1);
101
                      if(s_std_e = "1001" ) then
102
                        s_std_e <= "0000";
103
                        s_std_z <= STD_LOGIC_VECTOR(unsigned(s_std_z)+1);
104
                      end if;
105
                      if(stunde = '0') then
106
                        if(s_std_z = "0001" and s_std_e = "0010") then
107
                          s_std_e <= "0000";
108
                          s_std_z <= "0000";
109
                        end if;
110
                      end if;
111
                      if(stunde = '1') then
112
                        if(s_std_z = "0010" and s_std_e = "0100") then
113
                              s_std_e <= "0000";
114
                              s_std_z <= "0000";
115
                        end if;
116
                      end if;
117
                      
118
                  end if;
119
              end if;
120
          end if;
121
      end if;
122
    end if;
123
124
--  if(clk'event and clk ='1' and mode = "00") then
125
--    s_sec_e <= STD_LOGIC_VECTOR(unsigned(s_sec_e)+1);
126
--    if(s_sec_e = "1001") then
127
--      s_sec_e <= "0000";
128
--      s_sec_z <= STD_LOGIC_VECTOR(unsigned(s_sec_z)+1);
129
--    end if;
130
--    if(s_sec_z = "0101" and s_sec_e = "1001" ) then
131
--      s_sec_e <= "0000";
132
--      s_sec_z <= "0000";
133
--      s_min_e <= STD_LOGIC_VECTOR(unsigned(s_min_e)+1);
134
--    end if;
135
--    if(s_min_e = "1001" and s_sec_z = "0101" and s_sec_e = "1001") then
136
--      s_sec_e <= "0000";
137
--      s_sec_z <= "0000";
138
--      s_min_e <= "0000";
139
--      s_min_z <= STD_LOGIC_VECTOR(unsigned(s_min_z)+1);
140
--    end if;
141
--    if(s_min_z = "0101" and s_min_e = "1001" and s_sec_z = "0101" and s_sec_e = "1001") then
142
--      s_sec_e <= "0000";
143
--      s_sec_z <= "0000";
144
--      s_min_e <= "0000";
145
--      s_min_z <= "0000";
146
--      s_std_e <= STD_LOGIC_VECTOR(unsigned(s_std_e)+1);
147
--    end if;
148
--    if(s_std_e = "1001" and s_min_z = "0101" and s_min_e = "1001" and s_sec_z = "0101" and s_sec_e = "1001") then
149
--      s_sec_e <= "0000";
150
--      s_sec_z <= "0000";
151
--      s_min_e <= "0000";
152
--      s_min_z <= "0000";
153
--      s_std_e <= "0000";
154
--      s_std_z <= STD_LOGIC_VECTOR(unsigned(s_std_z)+1);
155
--    end if;
156
--    if(stunde = '0') then
157
--      if(s_std_z = "0001" and s_std_e = "0010" and s_min_z = "0101" and s_min_e = "1001" and s_sec_z = "0101" and s_sec_e = "1001") then
158
--        s_sec_e <= "0000";
159
--        s_sec_z <= "0000";
160
--        s_min_e <= "0000";
161
--        s_min_z <= "0000";
162
--        s_std_e <= "0000";
163
--        s_std_z <= "0000";
164
--      end if;
165
--    end if;
166
--    if(stunde = '1') then
167
--      if(s_std_z = "0010" and s_std_e = "0100" and s_min_z = "0101" and s_min_e = "1001" and s_sec_z = "0101" and s_sec_e = "1001") then
168
--        s_sec_e <= "0000";
169
--        s_sec_z <= "0000";
170
--        s_min_e <= "0000";
171
--        s_min_z <= "0000";
172
--        s_std_e <= "0000";
173
--        s_std_z <= "0000";
174
--      end if;
175
--    
176
--    end if;
177
--  end if;
178
179
--  if(clk'event and clk ='1' and mode = "01") then
180
--
181
--    s_sec_e <= STD_LOGIC_VECTOR(unsigned(s_sec_e)+1);
182
--    if(s_sec_e = "1001") then
183
--      s_sec_e <= "0000";
184
--      s_sec_z <= STD_LOGIC_VECTOR(unsigned(s_sec_z)+1);
185
--    end if;
186
--    if(s_sec_z = "0101" and s_sec_e = "1001" ) then
187
--      s_sec_e <= "0000";
188
--      s_sec_z <= "0000";
189
--      s_min_e <= STD_LOGIC_VECTOR(unsigned(s_min_e)+1);
190
--    end if;
191
--    if(s_min_e = "1001" and s_sec_z = "0101" and s_sec_e = "1001") then
192
--      s_sec_e <= "0000";
193
--      s_sec_z <= "0000";
194
--      s_min_e <= "0000";
195
--      s_min_z <= STD_LOGIC_VECTOR(unsigned(s_min_z)+1);
196
--    end if;
197
--    if(s_min_z = "0101" and s_min_e = "1001" and s_sec_z = "0101" and s_sec_e = "1001") then
198
--      s_sec_e <= "0000";
199
--      s_sec_z <= "0000";
200
--      s_min_e <= "0000";
201
--      s_min_z <= "0000";
202
--      s_std_e <= STD_LOGIC_VECTOR(unsigned(s_std_e)+1);
203
--    end if;
204
--    if(s_std_e = "1001" and s_min_z = "0101" and s_min_e = "1001" and s_sec_z = "0101" and s_sec_e = "1001") then
205
--      s_sec_e <= "0000";
206
--      s_sec_z <= "0000";
207
--      s_min_e <= "0000";
208
--      s_min_z <= "0000";
209
--      s_std_e <= "0000";
210
--      s_std_z <= STD_LOGIC_VECTOR(unsigned(s_std_z)+1);
211
--    end if;
212
--
213
--  end if;
214
215
  if(clk'event and clk ='1' and mode = "01") then
216
    s_sec_e <= STD_LOGIC_VECTOR(unsigned(s_sec_e)+1);
217
    if(s_sec_e = "1001") then
218
      s_sec_e <= "0000";
219
      s_sec_z <= STD_LOGIC_VECTOR(unsigned(s_sec_z)+1);
220
          if(s_sec_z = "0101" ) then
221
            s_sec_z <= "0000";
222
            s_min_e <= STD_LOGIC_VECTOR(unsigned(s_min_e)+1);
223
              if(s_min_e = "1001") then
224
                s_min_e <= "0000";
225
                s_min_z <= STD_LOGIC_VECTOR(unsigned(s_min_z)+1);
226
                  if(s_min_z = "0101") then
227
                    s_min_z <= "0000";
228
                    s_std_e <= STD_LOGIC_VECTOR(unsigned(s_std_e)+1);
229
                      if(s_std_e = "1001" ) then
230
                        s_std_e <= "0000";
231
                        s_std_z <= STD_LOGIC_VECTOR(unsigned(s_std_z)+1);
232
                      end if;
233
                  end if;
234
              end if;
235
          end if;
236
      end if;
237
    end if;
238
239
  if(clk'event and clk ='1' and mode = "10") then
240
    if( s_std_z > "0000" or s_std_e > "0000" or s_min_z > "0000" or s_min_e > "0000" or s_sec_z > "0000" or s_sec_e > "0000") then
241
      s_sec_e <= STD_LOGIC_VECTOR(unsigned(s_sec_e)-1);
242
    end if;
243
    
244
    if(s_std_z > "0000") then
245
      if(s_sec_e ="0000" and s_sec_z = "0000" and s_min_e = "0000" and s_min_z = "0000" and s_std_e = "0000") then
246
        s_sec_e <= "1001";
247
        s_sec_z <= "0101";
248
        s_min_e <= "1001";
249
        s_min_z <= "0101";
250
        s_std_e <= "1001";
251
        s_std_z <= STD_LOGIC_VECTOR(unsigned(s_std_z)-1);
252
      end if;
253
    end if;
254
    
255
    if(s_std_e > "0000") then
256
        if(s_sec_e ="0000" and s_sec_z = "0000" and s_min_e = "0000" and s_min_z = "0000") then
257
          s_sec_e <= "1001";
258
          s_sec_z <= "0101";
259
          s_min_e <= "1001";
260
          s_min_z <= "0101";
261
          s_std_e <= STD_LOGIC_VECTOR(unsigned(s_std_e)-1);
262
        end if;
263
    end if;
264
    
265
    if(s_min_z > "0000") then
266
      if(s_sec_e ="0000" and s_sec_z = "0000" and s_min_e = "0000") then
267
        s_sec_e <= "1001";
268
        s_sec_z <= "0101";
269
        s_min_e <= "1001";
270
        s_min_z <= STD_LOGIC_VECTOR(unsigned(s_min_z)-1);
271
      end if;
272
    end if;
273
    
274
    if(s_min_e >"0000") then
275
      if(s_sec_e ="0000" and s_sec_z = "0000") then
276
        s_sec_e <= "1001";
277
        s_sec_z <= "0101";
278
        s_min_e <= STD_LOGIC_VECTOR(unsigned(s_min_e)-1);
279
      end if;
280
    end if;
281
    
282
    if(s_sec_z >"0000") then
283
      if(s_sec_e ="0000") then
284
        s_sec_e <= "1001";
285
        s_sec_z <= STD_LOGIC_VECTOR(unsigned(s_sec_z)-1);
286
      end if;
287
    end if;
288
289
290
291
    
292
  end if;
293
294
end process modul;
295
296
o_sec_e <= s_sec_e;
297
o_sec_z <= s_sec_z;
298
o_min_e <= s_min_e;
299
o_min_z <= s_min_z;
300
o_std_e <= s_std_e;
301
o_std_z <= s_std_z;
302
303
end Behavioral;