1.vhd


1
----------------------------------------------------------------------------------
2
-- Company: 
3
-- Engineer: 
4
-- 
5
-- Create Date:    11:55:48 06/09/2010 
6
-- Design Name: 
7
-- Module Name:    Tutorium - 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_ARITH.ALL;
23
use IEEE.STD_LOGIC_UNSIGNED.ALL;
24
25
---- Uncomment the following library declaration if instantiating
26
---- any Xilinx primitives in this code.
27
--library UNISIM;
28
--use UNISIM.VComponents.all;
29
30
entity Tutorium is
31
Port ( takt : in  STD_LOGIC;
32
           reset : in  STD_LOGIC;
33
           bcd_south  : in  STD_LOGIC;
34
           V : out  STD_LOGIC;
35
           R : out  STD_LOGIC;
36
        Ag : in  STD_LOGIC;
37
           Bg : in  STD_LOGIC;
38
        state: out std_logic_vector (2 downto 0); -- nur zum Beobachten des
39
                                    --Automaten zur Flankenerkennung
40
        state1: out std_logic_vector (2 downto 0); -- nur zum Beobachten des
41
                                    --Automaten zur Flankenerkennung                                    
42
           y: out std_logic_vector (1 downto 0);
43
          O1 : out std_logic;
44
          O2 : out std_logic;
45
          O3 : out std_logic;
46
          O4 : out std_logic;
47
          O5 : out std_logic;
48
          O6 : out std_logic;
49
          O7 : out std_logic);
50
end Tutorium;
51
52
architecture Behavioral of Tutorium is
53
54
--Deklaration der Automatenzustände und internen Signale
55
56
type ZUSTAENDE is (A,B,C,D,E,F);  --Deklaration der Automatenzustände
57
type ZUSTAENDE1 is (A1,B1,C1,D1,E1,F1);  --Deklaration der Automatenzustände
58
type ZUSTAENDE2 is (A2,B2,C2);  --Deklaration der Automatenzustände
59
60
signal ZUSTAND, FOLGEZUSTAND: ZUSTAENDE;
61
signal ZUSTAND1, FOLGEZUSTAND1: ZUSTAENDE1;
62
signal ZUSTAND2, FOLGEZUSTAND2: ZUSTAENDE2;
63
signal Af : std_logic;
64
signal Bf : std_logic;
65
signal ci : std_logic;
66
signal co : std_logic;
67
signal V_int : std_logic;
68
signal R_int : std_logic;
69
signal y_int: std_logic_vector (2 downto 0) := "000";
70
signal LED: std_logic_vector (6 downto 0);
71
72
begin
73
74
COUNTER: process (takt, reset)
75
  begin
76
    if reset = '1' then y_int <= "000";
77
    elsif takt = '1' and takt'event then
78
      if V_int = '1' then y_int <= y_int + 1;
79
      else                y_int <= y_int - 1;
80
81
      end if;
82
    end if;
83
  end process COUNTER;
84
  
85
ZUSTANDSAKTUALISIERUNG: process (takt,RESET)
86
begin
87
if RESET = '1' then ZUSTAND <= A;
88
elsif takt = '1' and takt'event then ZUSTAND <= FOLGEZUSTAND;
89
end if;
90
end process ZUSTANDSAKTUALISIERUNG;  
91
92
FOLGEZUSTANDSBERECHNUNG: process (Ag,Af,ci,co,ZUSTAND)
93
  begin
94
    case ZUSTAND is
95
    when A => if Ag = '1' THEN FOLGEZUSTAND <= B;
96
           else FOLGEZUSTAND <= A;
97
           end if ;
98
      Af <= '0';
99
      ci <= '0';
100
    when B => if co = '1' THEN FOLGEZUSTAND <= C;
101
           else FOLGEZUSTAND <= B;
102
           end if;
103
      Af <= '0';
104
      ci <= '1';
105
    when C =>  FOLGEZUSTAND <= D;
106
      Af <= '1';
107
      ci <= '1';
108
    when D => if Ag = '0' THEN FOLGEZUSTAND <= E;
109
      else FOLGEZUSTAND <= D;
110
      end if ;
111
      Af <= '0';
112
      ci <= '0';
113
    when E => if co = '1' THEN FOLGEZUSTAND <= F;
114
      else FOLGEZUSTAND <= E;
115
      end if ;
116
      Af <= '0';
117
      ci <= '1';
118
    when F =>  FOLGEZUSTAND <= A;
119
      Af <= '0';
120
      ci <= '1';
121
    end case;
122
  end process FOLGEZUSTANDSBERECHNUNG;
123
  
124
ZUSTANDSAUSGABE: process (ZUSTAND)
125
  begin
126
    CASE ZUSTAND is
127
      when A => state <= "000";
128
      when B => state <= "001";
129
      when C => state <= "010";
130
      when D => state <= "100";
131
      when E => state <= "101";
132
      when F => state <= "110";
133
    end case;
134
  end process ZUSTANDSAUSGABE;
135
  
136
ZUSTANDSAKTUALISIERUNG1: process (takt,RESET)
137
begin
138
if reset = '1' then ZUSTAND1 <= A1;
139
elsif takt = '1' and takt'event then ZUSTAND1 <= FOLGEZUSTAND1;
140
end if;
141
end process ZUSTANDSAKTUALISIERUNG1;  
142
143
FOLGEZUSTANDSBERECHNUNG1: process (Bg,Bf,ci,co,ZUSTAND1)
144
  begin
145
    case ZUSTAND1 is
146
    when A1 => if Bg = '1' THEN FOLGEZUSTAND1 <= B1;
147
      else FOLGEZUSTAND1 <= A1;
148
      end if ;
149
      Bf <= '0';
150
      ci <= '0';
151
    when B1 => if co = '1' THEN FOLGEZUSTAND1 <= C1;
152
      else FOLGEZUSTAND1 <= B1;
153
      end if;
154
      Bf <= '0';
155
      ci <= '1';
156
    when C1 =>  FOLGEZUSTAND1 <= D1;
157
      Bf <= '1';
158
      ci <= '1';
159
    when D1 => if Bg = '0' THEN FOLGEZUSTAND1 <= E1;
160
      else FOLGEZUSTAND1 <= D1;
161
      end if ;
162
      Bf <= '0';
163
      ci <= '0';
164
    when E1 => if co = '1' THEN FOLGEZUSTAND1 <= F1;
165
      else FOLGEZUSTAND1 <= E1;
166
      end if ;
167
      Bf <= '0';
168
      ci <= '1';
169
    when F1 =>  FOLGEZUSTAND1 <= A1;
170
      Bf <= '0';
171
      ci <= '1';
172
    end case;
173
  end process FOLGEZUSTANDSBERECHNUNG1;
174
175
176
ZUSTANDSAUSGABE1: process (ZUSTAND1)
177
  begin
178
    CASE ZUSTAND1 is
179
      when A1 => state1 <= "000";
180
      when B1 => state1 <= "001";
181
      when C1 => state1 <= "010";
182
      when D1 => state1 <= "100";
183
      when E1 => state1 <= "101";
184
      when F1 => state1 <= "110";
185
    end case;
186
  end process ZUSTANDSAUSGABE1;
187
  
188
ZUSTANDSAKTUALISIERUNG2: process (takt,RESET)
189
begin
190
if RESET = '1' then ZUSTAND2 <= A2;
191
elsif takt = '1' and takt'event then ZUSTAND2 <= FOLGEZUSTAND2;
192
end if;
193
end process ZUSTANDSAKTUALISIERUNG2;  
194
195
FOLGEZUSTANDSBERECHNUNG2 : process (Af,Bf,Bg,Ag,ZUSTAND2)
196
begin
197
  case ZUSTAND2 is 
198
    when A2 => if    Af = '1' and Bg = '0' then FOLGEZUSTAND2 <=B2;
199
            V <='1';
200
            R <='0';
201
                elsif Bf = '1' and Ag = '0' then FOLGEZUSTAND2 <=C2;
202
                 V <='0';
203
            R <='1';
204
               else                          FOLGEZUSTAND2 <=A2;
205
            end if;
206
    when B2 => FOLGEZUSTAND2 <=A2;
207
    when C2 => FOLGEZUSTAND2 <=A2;
208
  end case;
209
end process FOLGEZUSTANDSBERECHNUNG2;
210
211
ZUSTANDSAUSGABE2: process (ZUSTAND2)
212
begin
213
  CASE ZUSTAND2 is
214
    when A2 => y <= "00";
215
    when B2 => y <= "01";
216
    when C2 => y <= "10";
217
  end case;
218
end process ZUSTANDSAUSGABE2;
219
220
counter_y: process (reset,takt, V_int, y_int)
221
  begin
222
    if reset = '1' then y_int <= "000";
223
    elsif takt = '1' and takt'event then
224
      if V_int = '1' then y_int <= y_int + 1;
225
      else                y_int <= y_int - 1;
226
227
      end if;
228
    end if;
229
  end process counter_y;
230
231
process (bcd_south,y_int,LED)
232
begin
233
case y_int is 
234
235
  when "000" => LED <= "0000000";
236
  when "001" => LED <= "0000001";
237
  when "010" => if bcd_south = '0' then LED <= "0000010";
238
              else                    LED <= "0000011";
239
                end if;
240
  when "011" => if bcd_south = '0' then LED <= "0000100";
241
                else                    LED <= "0000111";
242
              end if;
243
  when "100" => if bcd_south = '0' then LED <= "0001000";
244
                else                    LED <= "0001111";
245
                end if;
246
  when "101" => if bcd_south = '0' then LED <= "0010000";
247
                else                    LED <= "0011111";
248
                end if;
249
  when "110" => if bcd_south = '0' then LED <= "0100000";
250
               else                    LED <= "0111111";
251
                end if;
252
  when others => if bcd_south = '0' then LED <= "1000000";
253
               else                    LED <= "1111111";
254
              end if;          
255
end case;
256
257
end process;
258
259
O1 <= LED(6);
260
O2 <= LED(5);
261
O3 <= LED(4);
262
O4 <= LED(3);
263
O5 <= LED(2);
264
O6 <= LED(1);
265
O7 <= LED(0);
266
267
end Behavioral;