source: firmware/FAD/FACT_FAD_20MHz_VAR_PS/FACT_FAD_lib/hdl/led_controller_bahavior.vhd@ 10075

Last change on this file since 10075 was 10075, checked in by neise, 13 years ago
LED controller debugged
File size: 4.5 KB
Line 
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--
10LIBRARY ieee;
11USE ieee.std_logic_1164.all;
12USE ieee.std_logic_arith.all;
13use ieee.STD_LOGIC_UNSIGNED.all;
14
15library FACT_FAD_lib;
16
17
18use FACT_FAD_lib.fad_definitions.all;
19
20
21ENTITY led_controller IS
22GENERIC(
23 HEARTBEAT_PWM_DIVIDER : integer := 500; -- 1kHz @ 50 MHz
24 MAX_DELAY : integer := 100;
25 WAITING_DIVIDER : integer := 500000000 -- 1Hz @ 50 MHz
26);
27PORT(
28 CLK : IN std_logic;
29
30 -- LED outs -- inverted logic
31 green : OUT std_logic;
32 amber : OUT std_logic;
33 red : OUT std_logic;
34
35
36 -- status INs
37 trigger : IN std_logic; -- when trigger is received green should toggle
38
39 socks_waiting : IN std_logic;
40 socks_connected: IN std_logic
41
42 --heartbeat_en : IN std_logic
43 );
44END ENTITY led_controller;
45
46--
47ARCHITECTURE bahavior OF led_controller IS
48
49 type states is ( INIT, WAITING, CONNECTED);
50 signal state,next_state : states := INIT;
51
52 -- noninverted logic
53 signal green_loc : std_logic := '1'; -- on in order to show power
54 signal amber_loc : std_logic := '0'; --default off
55 signal red_loc : std_logic := '0'; --default off
56 signal flasher : std_logic;
57
58BEGIN
59 -- since leds have inverted logic, the outs are inverted at this point.
60 green <= not green_loc;
61 amber <= not amber_loc;
62 red <= not red_loc;
63
64 -- MAIN FSM: go to next state if rising edge
65 FSM_Registers: process(CLK)
66 begin
67 if Rising_edge(CLK) then
68 state <= next_state;
69 end if;
70 end process;
71
72 -- MAIN FSM
73 FSM_logic: process(state, socks_connected, socks_waiting)
74 begin
75 next_state <= state;
76 case state is
77
78
79 when INIT =>
80 amber_loc <= '0';
81 if (socks_waiting = '1') then
82 next_state <= WAITING;
83 else
84 next_state <= INIT;
85 end if;
86
87 when WAITING =>
88 amber_loc <= flasher;
89 if (socks_connected = '1') then
90 next_state <= CONNECTED;
91 else
92 next_state <= WAITING;
93 end if;
94
95 when CONNECTED =>
96 amber_loc <= '1';
97 if (socks_connected = '0') then
98 next_state <= INIT;
99 else
100 next_state <= CONNECTED;
101 end if;
102 end case;
103 end process FSM_logic;
104
105
106 -- if trigger is received green_loc toggles
107 trigger_proc : process (trigger)
108 begin
109 if Rising_edge(trigger) then
110 green_loc <= not green_loc;
111 end if;
112 end process trigger_proc;
113
114 -- heartbeat process:
115 -- as long as nothing else is to be done for the red led
116 -- it will show a ~2Hz heartbeat
117 -- can be switched off with heartbeat_en high
118 heartbeat : process (CLK)
119 variable Z: integer range 0 to HEARTBEAT_PWM_DIVIDER - 1 := 0;
120 variable ON_TIME: integer range 0 to HEARTBEAT_PWM_DIVIDER - 1 := 0;
121 variable DELAY: integer range 0 to MAX_DELAY - 1 := 0;
122 variable DIR : std_logic := '1';
123
124 begin
125 if rising_edge(CLK) then
126 if (Z < HEARTBEAT_PWM_DIVIDER - 1) then
127 Z := Z + 1;
128 else
129 Z := 0;
130 if (DELAY < MAX_DELAY - 1) then
131 DELAY := DELAY + 1;
132 else
133 DELAY := 0;
134 end if;
135 end if;
136
137
138 if (Z = 0) then
139 if (DIR = '0') then -- count up
140 if (ON_TIME < HEARTBEAT_PWM_DIVIDER - 11) then
141 ON_TIME := ON_TIME + 10;
142 else
143 DIR := '1';
144 end if;
145 else -- DIR is '1' -- count down
146 if (ON_TIME > 10) then
147 ON_TIME := ON_TIME - 10;
148 else
149 DIR := '0';
150 end if;
151 end if;
152 end if;
153
154 if (Z = 0) then
155 red_loc <= '1';
156 end if;
157 if (Z = ON_TIME) then
158 red_loc <= '0';
159 end if;
160 end if;
161 end process heartbeat;
162
163
164 -- sock_waiting_flasher process:
165 sock_waiting_flasher : process (CLK)
166 variable Y: integer range 0 to WAITING_DIVIDER - 1;
167 begin
168 if rising_edge(CLK) then
169 if (Y < WAITING_DIVIDER - 1) then
170 Y := Y + 1;
171 else
172 Y := 0;
173 end if;
174 if (Y = 0) then
175 flasher <= '1';
176 end if;
177 if (Y = WAITING_DIVIDER / 2) then
178 flasher <= '0';
179 end if;
180 end if;
181 end process sock_waiting_flasher;
182
183
184END ARCHITECTURE bahavior;
185
Note: See TracBrowser for help on using the repository browser.