source: trunk/firmware_v4/SES/src/mode_lvp.c

Last change on this file was 42, checked in by f.jahn, 5 days ago
File size: 7.4 KB
RevLine 
[42]1
2// Wie LVP||OVP Modul
3// Jedoch hier nur LVP
4
5
6
7#include "stdio.h"
8#include "mode_lvp.h"
9#include "button.h"
10#include "relais.h"
11#include "main.h"
12#include "leds.h"
13#include "buzzer.h"
14#include "chip_temperature.h"
15
16
17typedef enum LVP_State_enum
18{
19 LVP_OFF,
20 LVP_ON,
21 LVP_MANUAL_ON,
22 LVP_ERROR
23} LVP_state_t;
24
25
26static LVP_state_t smState;
27
28
29static void LVP_SM_Off(void)
30{
31 int faultInput;
32
33
34 if (HAL_GPIO_ReadPin(GPIO_INPUT_FAULT_GPIO_Port, GPIO_INPUT_FAULT_Pin) == GPIO_PIN_RESET)
35 {
36 faultInput = 1;
37 }
38 else
39 {
40 faultInput = 0;
41 }
42
43
44
45
46
47 //Prüfe auf Wechsel des Modus AUTO / SM ON
48 if (BUTTON_GetMode() == BUTTON_AUTO)
49 {
50 if (faultInput == 0)
51 {
52 RELAIS_SetPuls();
53 BUZZER_Beep(BUZZER_ON_TIME_CONFIRM);
54 LEDS_GN_Blink_Start(LED_GN_ON_TIME_ON_MODE, LED_GN_OFF_TIME);
55#ifdef DEBUG
56 printf("LVP_SM_Off: NEW_STATE: LVP_ON\n");
57#endif
58 smState = LVP_ON;
59
60 }
61 else
62 {
63 //Wechsel nicht möglich. Fehler Eingang aktiv
64 BUZZER_Beep(BUZZER_ON_TIME_REJECT);
65 BUTTON_SetModeOff();
66 //LEDS_RT_Blink_Start(LED_RT_ON_TIME_WARN_FAULT_INPUT, LED_GN_OFF_TIME); //Fehler Anzeigen
67 LEDS_RT_BlinkCode_Start(BLINK_CODE_ERROR_FAULT_INPUT, LED_RT_ON_TIME_WARN_FAULT_INPUT, LED_RT_OFF_TIME, LED_RT_OFF_TIME *5); //Fehler Anzeigen
68#ifdef DEBUG
69 printf("LVP_SM_Off: NEW_STATE: LVP_ERROR_FAULT_INPUT\n");
70#endif
71 smState =LVP_ERROR;
72 }
73 }
74
75
76 //Prüfe auf Wechsel in MANUAL ON Mode
77 //Keine Fehlerüberprüfungen. In diesem Modus werdem alle Alarme ignoriert.
78 if (BUTTON_GetMode() == BUTTON_MANUAL_ON)
79 {
80
81 RELAIS_SetPuls();
82 BUZZER_Alarm_Start(BUZZER_ON_TIME_ALARM_MANUAL_MODE, BUZZER_OFF_TIME);
83 LEDS_GN_On();
84 LEDS_RT_BlinkCode_Start(BLINK_CODE_WARN_MANUAL, LED_RT_ON_TIME_WARN_MANUAL_MODE, LED_RT_OFF_TIME, LED_RT_OFF_TIME * 5); //Fehler Anzeigen
85#ifdef DEBUG
86 printf("NEW_STATE: LVP_MANUAL_ON\n");
87#endif
88 smState = LVP_MANUAL_ON;
89 }
90
91
92
93}
94
95static void LVP_SM_On(void)
96{
97 int faultInput = 0;
98 static int lvpInput = 0;
99 static int lvpTimeCounter = 0;
100 static int oldtime;
101
102 if (HAL_GPIO_ReadPin(GPIO_INPUT_FAULT_GPIO_Port, GPIO_INPUT_FAULT_Pin) == GPIO_PIN_RESET)
103 {
104 faultInput = 1;
105 }
106 else
107 {
108 faultInput = 0;
109 }
110
111 if ((HAL_GPIO_ReadPin(GPIO_INPUT_LVP_GPIO_Port, GPIO_INPUT_LVP_Pin) == GPIO_PIN_SET) || (HAL_GPIO_ReadPin(GPIO_INPUT_OVP_GPIO_Port, GPIO_INPUT_OVP_Pin) == GPIO_PIN_SET))
112 {
113 if (HAL_GetTick() != oldtime)
114 {
115 if (lvpTimeCounter < 5000) lvpTimeCounter++;
116 if (lvpTimeCounter >= 5000)
117 {
118 lvpInput = 1;
119 lvpTimeCounter=0;
120 }
121 oldtime = HAL_GetTick();
122 }
123 }
124
125 if (HAL_GPIO_ReadPin(GPIO_INPUT_LVP_GPIO_Port, GPIO_INPUT_LVP_Pin) == GPIO_PIN_RESET)
126 {
127// if (HAL_GetTick() != oldtime)
128// {
129// lvpAndOvpInputTimeCounter++;
130// if (lvpAndOvpInputTimeCounter > 30000)
131// {
132 lvpInput = 0;
133 lvpTimeCounter=0;
134// }
135// oldtime = HAL_GetTick();
136// }
137 }
138
139
140
141
142 //Prüfe auf Fehlermode
143 if (faultInput == 1)
144 {
145 RELAIS_ResetPuls();
146 BUZZER_Beep(BUZZER_ON_TIME_REJECT); //Warnung
147 LEDS_GN_Off();
148 LEDS_RT_BlinkCode_Start(BLINK_CODE_ERROR_FAULT_INPUT, LED_RT_ON_TIME_WARN_FAULT_INPUT, LED_RT_OFF_TIME, LED_RT_OFF_TIME *5); //Fehler Anzeigen
149 BUTTON_SetModeOff(); //Damit nicht von alleine wieder eingeschaltet wird
150#ifdef DEBUG
151 printf("FAULT INPUT EVENT DETECTED!\n");
152 printf("NEW_STATE: LVP_ERROR\n");
153#endif
154 smState = LVP_ERROR;
155 }
156
157 if (CHIP_TEMPERATURE_GetTemp() > 80)
158 {
159 RELAIS_ResetPuls();
160 BUZZER_Beep(BUZZER_ON_TIME_REJECT); //Warnung
161 LEDS_GN_Off();
162 LEDS_RT_BlinkCode_Start(BLINK_CODE_ERROR_TEMP, LED_RT_ON_TIME_WARN_TEMP, LED_GN_OFF_TIME, LED_GN_OFF_TIME *5); //Fehler Anzeigen
163 BUTTON_SetModeOff(); //Damit nicht von alleine wieder eingeschaltet wird
164#ifdef DEBUG
165 printf("NEW_STATE: MAINSWITCH_ERROR, Temp too high\n");
166#endif
167 smState = LVP_ERROR;
168 }
169
170
171 //LVP oder OVP hat stattgefunden, und Relais ist ein, dann aus
172 if ((lvpInput == 1) && (RELAIS_GetState() == 1))
173 {
174 RELAIS_ResetPuls();
175 BUZZER_Beep(BUZZER_ON_TIME_REJECT); //Warnung
176 LEDS_GN_Off();
177 LEDS_RT_BlinkCode_Start(BLINK_CODE_ERROR_OVP_LVP, LED_RT_ON_TIME_WARN_OVP_AND_LVP_INPUT, LED_RT_OFF_TIME, LED_RT_OFF_TIME *5); //Fehler Anzeigen
178#ifdef DEBUG
179 printf("LVP OFF!\n");
180 printf("NEW_STATE: LVP_Auto On, Relais off\n");
181#endif
182 }
183
184 //KEIN LVP und keine OVP Abschaltung, Relais ist aber noch aus, dann einschalten
185 if ((lvpInput == 0) && (RELAIS_GetState() == 0))
186 {
187 RELAIS_SetPuls();
188 BUZZER_Beep(BUZZER_ON_TIME_CONFIRM); //Warnung
189 LEDS_GN_Off();
190 LEDS_GN_Blink_Start(LED_GN_ON_TIME_ON_MODE, LED_GN_OFF_TIME);
191#ifdef DEBUG
192 printf("LVP ON!\n");
193 printf("NEW_STATE: LVP_OVP_Auto On, Relais on\n");
194#endif
195 }
196
197 // Prüfe Wechsel in off mode
198 if (BUTTON_GetMode() == BUTTON_OFF)
199 {
200 //Ausschalten muss immer möglich sein
201 RELAIS_ResetPuls();
202 BUZZER_Beep(BUZZER_ON_TIME_CONFIRM); //Bestätigung
203 LEDS_GN_Off();
204 LEDS_RT_Off();
205#ifdef DEBUG
206 printf("NEW_STATE: LVP_OFF\n");
207#endif
208 smState = LVP_OFF;
209 //Damit beim drücken auf on erstmal eingeschaltet wird
210 lvpTimeCounter=0;
211 lvpInput = 0;
212 }
213
214
215}
216
217static void LVP_SM_ManualOn(void)
218{
219 // Prüfe Wechsel in off mode
220 if (BUTTON_GetMode() == BUTTON_OFF)
221 {
222 //Ausschalten muss immer möglich sein
223 RELAIS_ResetPuls();
224 BUZZER_Alarm_Stop();
225 LEDS_GN_Off();
226 LEDS_RT_Off();
227#ifdef DEBUG
228 printf("NEW_STATE: LVP_OFF\n");
229#endif
230 smState = LVP_OFF;
231 }
232
233}
234
235static void LVP_SM_Error(void)
236{
237 int faultInput;
238 int lvpAndOvpInput;
239
240 if (HAL_GPIO_ReadPin(GPIO_INPUT_FAULT_GPIO_Port, GPIO_INPUT_FAULT_Pin) == GPIO_PIN_RESET)
241 {
242 faultInput = 1;
243 }
244 else
245 {
246 faultInput = 0;
247 }
248
249
250
251 //Prüfe auf Wechsel des Modus AUTO / SM ON
252 if (BUTTON_GetMode() == BUTTON_AUTO)
253 {
254 if (faultInput == 0)
255 {
256 RELAIS_SetPuls();
257 BUZZER_Beep(BUZZER_ON_TIME_CONFIRM);
258 LEDS_GN_Blink_Start(LED_GN_ON_TIME_ON_MODE, LED_GN_OFF_TIME);
259 LEDS_RT_Off(); //Fehler löschen
260#ifdef DEBUG
261 printf("NEW_STATE: LVP_ON\n");
262#endif
263 smState = LVP_ON;
264 }
265 else
266 {
267 //Wechsel nicht möglich. Fehler Eingang weiterhin aktiv
268 BUZZER_Beep(BUZZER_ON_TIME_REJECT);
269 BUTTON_SetModeOff();
270 }
271 }
272
273 //Prüfe auf Wechsel in MANUAL ON Mode
274 //Keine Fehlerüberprüfungen. In diesem Modus werdem alle Alarme ignoriert.
275 if (BUTTON_GetMode() == BUTTON_MANUAL_ON)
276 {
277
278 RELAIS_SetPuls();
279 BUZZER_Alarm_Start(BUZZER_ON_TIME_ALARM_MANUAL_MODE, BUZZER_OFF_TIME);
280 LEDS_GN_On();
281 LEDS_RT_Off();
282 LEDS_RT_BlinkCode_Start(BLINK_CODE_WARN_MANUAL, LED_RT_ON_TIME_WARN_MANUAL_MODE, LED_RT_OFF_TIME, LED_RT_OFF_TIME *5); //Fehler Anzeigen
283#ifdef DEBUG
284 printf("NEW_STATE: LVP_MANUAL_ON\n");
285#endif
286 smState = LVP_MANUAL_ON;
287 }
288}
289
290
291
292void MODE_LVP_Exec(void)
293{
294 switch (smState)
295 {
296 case LVP_OFF:
297 LVP_SM_Off();
298 break;
299
300 case LVP_ON:
301 LVP_SM_On();
302 break;
303
304 case LVP_MANUAL_ON:
305 LVP_SM_ManualOn();
306 break;
307
308 case LVP_ERROR:
309 LVP_SM_Error();
310 break;
311
312 default:
313 break;
314 }
315}
316
317
Note: See TracBrowser for help on using the repository browser.