1 | --
|
---|
2 | -- VHDL Architecture FACT_FAD_lib.led_controller.bahavior
|
---|
3 | --
|
---|
4 | -- Created:
|
---|
5 | -- by - dneise.UNKNOWN (E5B-LABOR6)
|
---|
6 | -- at - 11:04:17 04.01.2011
|
---|
7 | --
|
---|
8 | -- using Mentor Graphics HDL Designer(TM) 2009.2 (Build 10)
|
---|
9 | --
|
---|
10 | LIBRARY ieee;
|
---|
11 | USE ieee.std_logic_1164.all;
|
---|
12 | USE ieee.std_logic_arith.all;
|
---|
13 | use ieee.STD_LOGIC_UNSIGNED.all;
|
---|
14 |
|
---|
15 | library FACT_FAD_lib;
|
---|
16 |
|
---|
17 |
|
---|
18 | use FACT_FAD_lib.fad_definitions.all;
|
---|
19 |
|
---|
20 |
|
---|
21 | ENTITY led_controller IS
|
---|
22 | GENERIC(
|
---|
23 | HEARTBEAT_PWM_DIVIDER : integer := 500;
|
---|
24 | WAITING_DIVIDER : integer := 500000000
|
---|
25 | );
|
---|
26 | PORT(
|
---|
27 | CLK : IN std_logic;
|
---|
28 |
|
---|
29 | -- LED outs -- inverted logic
|
---|
30 | green : OUT std_logic;
|
---|
31 | amber : OUT std_logic;
|
---|
32 | red : OUT std_logic;
|
---|
33 | additional_flasher_out : OUT std_logic;
|
---|
34 |
|
---|
35 |
|
---|
36 | -- status INs
|
---|
37 | trigger : IN std_logic; -- when trigger is received green should toggle
|
---|
38 |
|
---|
39 | w5300_reset : in std_logic;
|
---|
40 | trigger_veto : in std_logic;
|
---|
41 |
|
---|
42 | refclk_too_high : in std_logic;
|
---|
43 | refclk_too_low : in std_logic;
|
---|
44 |
|
---|
45 | socks_waiting : IN std_logic;
|
---|
46 | socks_connected: IN std_logic
|
---|
47 |
|
---|
48 |
|
---|
49 | --heartbeat_en : IN std_logic
|
---|
50 | );
|
---|
51 | END ENTITY led_controller;
|
---|
52 |
|
---|
53 | --
|
---|
54 | ARCHITECTURE bahavior OF led_controller IS
|
---|
55 |
|
---|
56 | type states is ( INIT, WAITING, CONNECTED);
|
---|
57 | signal state,next_state : states := INIT;
|
---|
58 |
|
---|
59 | -- noninverted logic
|
---|
60 | signal green_loc : std_logic := '1'; -- on in order to show power
|
---|
61 | signal amber_loc : std_logic := '0'; --default off
|
---|
62 | signal red_loc : std_logic := '0'; --default off
|
---|
63 | signal flasher : std_logic;
|
---|
64 |
|
---|
65 | signal heartbeat_counter: integer range 0 to HEARTBEAT_PWM_DIVIDER - 1 := 0;
|
---|
66 | constant ontime_update : integer := 100;
|
---|
67 | signal ontime_update_counter : integer range 0 to ontime_update - 1 := 0;
|
---|
68 | signal on_time: integer range 0 to HEARTBEAT_PWM_DIVIDER - 1 := 0;
|
---|
69 | constant ontime_divider : integer range 0 to HEARTBEAT_PWM_DIVIDER - 1 := 1;
|
---|
70 | signal delta_ontime : integer range 0 to HEARTBEAT_PWM_DIVIDER - 1 := 1;
|
---|
71 | signal DIR : std_logic := '0';
|
---|
72 |
|
---|
73 | BEGIN
|
---|
74 | -- since leds have inverted logic, the outs are inverted at this point.
|
---|
75 | green <= not green_loc;
|
---|
76 |
|
---|
77 | --amber <= not amber_loc;
|
---|
78 | amber <= w5300_reset;
|
---|
79 |
|
---|
80 | --red <= not red_loc;
|
---|
81 | red <= not trigger_veto;
|
---|
82 |
|
---|
83 | additional_flasher_out <= flasher;
|
---|
84 |
|
---|
85 | -- MAIN FSM: go to next state if rising edge
|
---|
86 | FSM_Registers: process(CLK)
|
---|
87 | begin
|
---|
88 | if Rising_edge(CLK) then
|
---|
89 | state <= next_state;
|
---|
90 | end if;
|
---|
91 | end process;
|
---|
92 |
|
---|
93 | -- MAIN FSM
|
---|
94 | FSM_logic: process(state, socks_connected, socks_waiting)
|
---|
95 | begin
|
---|
96 | next_state <= state;
|
---|
97 | case state is
|
---|
98 |
|
---|
99 |
|
---|
100 | when INIT =>
|
---|
101 | green_loc <= '0';
|
---|
102 | if (socks_waiting = '1') then
|
---|
103 | next_state <= WAITING;
|
---|
104 | else
|
---|
105 | next_state <= INIT;
|
---|
106 | end if;
|
---|
107 |
|
---|
108 | when WAITING =>
|
---|
109 | green_loc <= flasher;
|
---|
110 | if (socks_connected = '1') then
|
---|
111 | next_state <= CONNECTED;
|
---|
112 | else
|
---|
113 | next_state <= WAITING;
|
---|
114 | end if;
|
---|
115 |
|
---|
116 | when CONNECTED =>
|
---|
117 | green_loc <= '1';
|
---|
118 | if (socks_connected = '0') then
|
---|
119 | next_state <= INIT;
|
---|
120 | else
|
---|
121 | next_state <= CONNECTED;
|
---|
122 | end if;
|
---|
123 | end case;
|
---|
124 | end process FSM_logic;
|
---|
125 |
|
---|
126 |
|
---|
127 | -- if trigger is received red_loc toggles
|
---|
128 | trigger_proc : process (trigger)
|
---|
129 | begin
|
---|
130 | if Rising_edge(trigger) then
|
---|
131 | red_loc <= not red_loc;
|
---|
132 | end if;
|
---|
133 | end process trigger_proc;
|
---|
134 |
|
---|
135 | -- heartbeat process:
|
---|
136 | -- as long as nothing else is to be done for the red led
|
---|
137 | -- it will show a ~2Hz heartbeat
|
---|
138 | -- can be switched off with heartbeat_en high
|
---|
139 | heartbeat : process (CLK)
|
---|
140 |
|
---|
141 |
|
---|
142 |
|
---|
143 |
|
---|
144 | begin
|
---|
145 | if rising_edge(CLK) then
|
---|
146 | if (heartbeat_counter < HEARTBEAT_PWM_DIVIDER - 1) then
|
---|
147 | heartbeat_counter <= heartbeat_counter + 1;
|
---|
148 | else
|
---|
149 | heartbeat_counter <= 0;
|
---|
150 | end if;
|
---|
151 |
|
---|
152 | -- calculate the change in on_time
|
---|
153 | -- if the change is too small... then change at least by 1.
|
---|
154 | if ( on_time / (2*ontime_divider) = 0) then
|
---|
155 | delta_ontime <= 1;
|
---|
156 | else
|
---|
157 | delta_ontime <= on_time / (2*ontime_divider);
|
---|
158 | end if;
|
---|
159 | if (heartbeat_counter = 0) then
|
---|
160 | if (ontime_update_counter < ontime_update - 1) then
|
---|
161 | ontime_update_counter <= ontime_update_counter + 1;
|
---|
162 | else
|
---|
163 | ontime_update_counter <= 0;
|
---|
164 |
|
---|
165 | -- set new on_time
|
---|
166 | if (DIR = '0') then -- increase on_time
|
---|
167 | if (on_time + delta_ontime < HEARTBEAT_PWM_DIVIDER - 1) then
|
---|
168 | on_time <= on_time + delta_ontime;
|
---|
169 | else
|
---|
170 | on_time <= HEARTBEAT_PWM_DIVIDER - 1;
|
---|
171 | DIR <= '1';
|
---|
172 | end if;
|
---|
173 | else -- DIR is '1' -- count down
|
---|
174 | if (on_time - delta_ontime > 0) then
|
---|
175 | on_time <= on_time - delta_ontime;
|
---|
176 | else
|
---|
177 | on_time <= 0;
|
---|
178 | DIR <= '0';
|
---|
179 | end if;
|
---|
180 | end if;
|
---|
181 |
|
---|
182 | end if;
|
---|
183 | end if;
|
---|
184 |
|
---|
185 |
|
---|
186 |
|
---|
187 | if (heartbeat_counter = 0) then
|
---|
188 | amber_loc <= '1';
|
---|
189 | end if;
|
---|
190 | if (heartbeat_counter = on_time) then
|
---|
191 | amber_loc <= '0';
|
---|
192 | end if;
|
---|
193 | end if;
|
---|
194 | end process heartbeat;
|
---|
195 |
|
---|
196 |
|
---|
197 | -- sock_waiting_flasher process:
|
---|
198 | sock_waiting_flasher : process (CLK)
|
---|
199 | variable Y: integer range 0 to WAITING_DIVIDER - 1;
|
---|
200 | begin
|
---|
201 | if rising_edge(CLK) then
|
---|
202 | if (Y < WAITING_DIVIDER - 1) then
|
---|
203 | Y := Y + 1;
|
---|
204 | else
|
---|
205 | Y := 0;
|
---|
206 | end if;
|
---|
207 | if (Y = 0) then
|
---|
208 | flasher <= '1';
|
---|
209 | end if;
|
---|
210 | if (Y = WAITING_DIVIDER / 2) then
|
---|
211 | flasher <= '0';
|
---|
212 | end if;
|
---|
213 | end if;
|
---|
214 | end process sock_waiting_flasher;
|
---|
215 |
|
---|
216 |
|
---|
217 | END ARCHITECTURE bahavior;
|
---|
218 |
|
---|