1 | library ieee;
|
2 | use ieee.std_logic_1164.all;
|
3 | use ieee.numeric_std.all;
|
4 | entity sortierer is
|
5 | generic (
|
6 | CNT_OFL : positive := ERGÄNZE ; -- Sekundentakt overflow
|
7 | TIME_WEG_K : positive := ERGÄNZE im Praktikum; -- Kunststoff-Werkstück, langer Weg
|
8 | TIME_WEG_M : positive := ERGÄNZE im Praktikum; -- Metall-Werkstück, kurzer Weg
|
9 | FWD : std_logic := '0';
|
10 | BCK : std_logic := '1';
|
11 | RUN : std_logic := '1';
|
12 | STP : std_logic := '0';
|
13 | WEG_K : std_logic := '0';
|
14 | WEG_M : std_logic := '1'
|
15 | );
|
16 | port (
|
17 | reset_n : in std_logic; -- Key3
|
18 | clk : in std_logic; --50 MHz
|
19 | oe_in : in std_logic; -- Switch 9
|
20 | opt_sens : in std_logic; -- optischer Sensor
|
21 | ind_sens : in std_logic; -- induktiv Sensor
|
22 | oe_n_out : out std_logic;
|
23 | weiche_out : out std_logic; -- Weg A / Weg B -Umschaltung
|
24 | motor_pwr_out : out std_logic; -- ...
|
25 | motor_dir_out : out std_logic -- Motor Drehrichtung
|
26 | );
|
27 | end entity sortierer;
|
28 | architecture arch of sortierer is
|
29 | -- signals
|
30 | signal cnt : unsigned( ERGÄNZE );
|
31 | signal time_s : unsigned(4 downto 0);
|
32 | signal weiche : std_logic;
|
33 | signal motor_pwr : std_logic;
|
34 | signal motor_dir : std_logic;
|
35 | type main_state_t is (idle, ERGÄNZE );
|
36 | signal main_state, next_main_state : main_state_t;
|
37 |
|
38 |
|
39 | begin
|
40 | sort_control : process(clk, reset_n) is
|
41 | begin
|
42 | if (reset_n = '0') then
|
43 | ERGÄNZE
|
44 | elsif rising_edge(clk) then
|
45 | main_state <= next_main_state; -- z_reg
|
46 |
|
47 | -- fast counter, overflow = 1s
|
48 | if cnt = to_unsigned(CNT_OFL, cnt'length) or main_state = idle then
|
49 | cnt <= (others => '0');
|
50 | else
|
51 | cnt <= cnt + 1;
|
52 | end if;
|
53 | -- Sekunden timer
|
54 | if main_state = idle then -- reset timer
|
55 | time_s <= (others => '0');
|
56 | elsif cnt = CNT_OFL then
|
57 | time_s <= time_s + 1;
|
58 | end if;
|
59 |
|
60 | case main_state is
|
61 | when idle => -- warte auf opt_sens hi
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | ERGÄNZE
|
67 |
|
68 |
|
69 |
|
70 | when ……. =>
|
71 |
|
72 |
|
73 |
|
74 |
|
75 | ERGÄNZE
|
76 |
|
77 | when ……. =>
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 | ERGÄNZE
|
84 | when ……. =>
|
85 | ERGÄNZE
|
86 |
|
87 | when ……. =>
|
88 | ERGÄNZE
|
89 | when ……. =>
|
90 | ERGÄNZE
|
91 |
|
92 | end case;
|
93 | end if;
|
94 | oe_n_out <= not oe_in; -- voltage translator active
|
95 | weiche_out <= weiche;
|
96 | motor_pwr_out <= motor_pwr;
|
97 | motor_dir_out <= motor_dir;
|