source: trunk/firmware_v4/SES/src/mode_lvp_ovp.c@ 42

Last change on this file since 42 was 42, checked in by f.jahn, 5 days ago
File size: 8.7 KB
Line 
1
2// Dieser Modus ist ein Hauptschaltermodus mit Secondary Protection
3// Secondary Protection löst aus, wenn OVP und LVP wegfällt.
4// OVP und LVP fällt wegbei:
5// - Sehr tiefe Entladung
6// - Sehr hohe Spannung
7// - Übertemperatur
8// - je nach Liproeinstellung möglicherweise auch wenn sowohl Untertemperaturschutz für Ladung und für Last erreicht ist
9// - je nach Liproeinstellung möglicherweise auch wenn sowohl Überttemperaturschutz für Ladung und für Last erreicht ist
10// - Die letzten beiden Positionen können vielleicht ungewollt sein.
11
12// OVP UND LVP Signal gleichzeitig:
13// Es wurde eine Verzögerung von ca. 30 Sekunden implementiert. So kann noch problemlos ein Testjumper auf die Lipro gesteckt werden und die
14// einzelnennen Funktionen zu prüfen. Außerdem ist es eventuell für die Prametrierung hilfreich, wenn nicht sofort ausgeht
15// Auch wäre es hilfreich um zum Beispiel die Ursache über Modbus abfragen heruas zu bekommen
16
17//
18// Fault Input:
19// Hier ohne Verzögerung um schnell auf kurzschluss reagieren zu können
20// Ansonsten wie Modus 0
21
22
23
24#include "stdio.h"
25#include "mode_lvp_ovp.h"
26#include "button.h"
27#include "relais.h"
28#include "main.h"
29#include "leds.h"
30#include "buzzer.h"
31#include "chip_temperature.h"
32
33
34typedef enum LVP_OVP_State_enum
35{
36 LVP_OVP_OFF,
37 LVP_OVP_ON,
38 LVP_OVP_MANUAL_ON,
39 LVP_OVP_ERROR
40} LVP_OVP_state_t;
41
42
43static LVP_OVP_state_t smState;
44
45
46static void LVP_OVP_SM_Off(void)
47{
48 int faultInput;
49
50
51 if (HAL_GPIO_ReadPin(GPIO_INPUT_FAULT_GPIO_Port, GPIO_INPUT_FAULT_Pin) == GPIO_PIN_RESET)
52 {
53 faultInput = 1;
54 }
55 else
56 {
57 faultInput = 0;
58 }
59
60
61
62
63 //Prüfe auf Wechsel des Modus AUTO / SM ON
64 if (BUTTON_GetMode() == BUTTON_AUTO)
65 {
66 if (faultInput == 0)
67 {
68 RELAIS_SetPuls();
69 BUZZER_Beep(BUZZER_ON_TIME_CONFIRM);
70 LEDS_GN_Blink_Start(LED_GN_ON_TIME_ON_MODE, LED_GN_OFF_TIME);
71#ifdef DEBUG
72 printf("LVP_OVP_SM_Off: NEW_STATE: LVP_OVP_ON\n");
73#endif
74 smState = LVP_OVP_ON;
75
76 }
77 else
78 {
79 //Wechsel nicht möglich. Fehler Eingang aktiv
80 BUZZER_Beep(BUZZER_ON_TIME_REJECT);
81 BUTTON_SetModeOff();
82 //LEDS_RT_Blink_Start(LED_RT_ON_TIME_WARN_FAULT_INPUT, LED_GN_OFF_TIME); //Fehler Anzeigen
83 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
84#ifdef DEBUG
85 printf("LVP_OVP_SM_Off: NEW_STATE: LVP_OVP_ERROR_FAULT_INPUT\n");
86#endif
87 smState =LVP_OVP_ERROR;
88 }
89 }
90
91
92 //Prüfe auf Wechsel in MANUAL ON Mode
93 //Keine Fehlerüberprüfungen. In diesem Modus werdem alle Alarme ignoriert.
94 if (BUTTON_GetMode() == BUTTON_MANUAL_ON)
95 {
96
97 RELAIS_SetPuls();
98 BUZZER_Alarm_Start(BUZZER_ON_TIME_ALARM_MANUAL_MODE, BUZZER_OFF_TIME);
99 LEDS_GN_On();
100 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
101#ifdef DEBUG
102 printf("NEW_STATE: LVP_OVP_MANUAL_ON\n");
103#endif
104 smState = LVP_OVP_MANUAL_ON;
105 }
106}
107
108static void LVP_OVP_SM_On(void)
109{
110 int faultInput = 0;
111 static int lvpOROvpInput = 0;
112 static int lvpAndOvpInputTimeCounter = 0;
113 static int oldtime;
114
115 if (HAL_GPIO_ReadPin(GPIO_INPUT_FAULT_GPIO_Port, GPIO_INPUT_FAULT_Pin) == GPIO_PIN_RESET)
116 {
117 faultInput = 1;
118 }
119 else
120 {
121 faultInput = 0;
122 }
123
124 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))
125 {
126 if (HAL_GetTick() != oldtime)
127 {
128 if (lvpAndOvpInputTimeCounter < 5000)lvpAndOvpInputTimeCounter++;
129 if (lvpAndOvpInputTimeCounter >= 5000)
130 {
131 lvpOROvpInput = 1;
132 lvpAndOvpInputTimeCounter=0;
133 }
134 oldtime = HAL_GetTick();
135 }
136 }
137
138 if ((HAL_GPIO_ReadPin(GPIO_INPUT_LVP_GPIO_Port, GPIO_INPUT_LVP_Pin) == GPIO_PIN_RESET) && (HAL_GPIO_ReadPin(GPIO_INPUT_OVP_GPIO_Port, GPIO_INPUT_OVP_Pin) == GPIO_PIN_RESET))
139 {
140// if (HAL_GetTick() != oldtime)
141// {
142// lvpAndOvpInputTimeCounter++;
143// if (lvpAndOvpInputTimeCounter > 30000)
144// {
145 lvpOROvpInput = 0;
146 lvpAndOvpInputTimeCounter=0;
147// }
148// oldtime = HAL_GetTick();
149// }
150 }
151
152
153
154
155 //Prüfe auf Fehlermode
156 if (faultInput == 1)
157 {
158 RELAIS_ResetPuls();
159 BUZZER_Beep(BUZZER_ON_TIME_REJECT); //Warnung
160 LEDS_GN_Off();
161 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
162 BUTTON_SetModeOff(); //Damit nicht von alleine wieder eingeschaltet wird
163#ifdef DEBUG
164 printf("FAULT INPUT EVENT DETECTED!\n");
165 printf("NEW_STATE: LVP_OVP_ERROR\n");
166#endif
167 smState = LVP_OVP_ERROR;
168 }
169
170 if (CHIP_TEMPERATURE_GetTemp() > 80)
171 {
172 RELAIS_ResetPuls();
173 BUZZER_Beep(BUZZER_ON_TIME_REJECT); //Warnung
174 LEDS_GN_Off();
175 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
176 BUTTON_SetModeOff(); //Damit nicht von alleine wieder eingeschaltet wird
177#ifdef DEBUG
178 printf("NEW_STATE: MAINSWITCH_ERROR, Temp too high\n");
179#endif
180 smState = LVP_OVP_ERROR;
181 }
182
183
184 //LVP oder OVP hat stattgefunden, und Relais ist ein, dann aus
185 if ((lvpOROvpInput == 1) && (RELAIS_GetState() == 1))
186 {
187 RELAIS_ResetPuls();
188 BUZZER_Beep(BUZZER_ON_TIME_REJECT); //Warnung
189 LEDS_GN_Off();
190 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
191#ifdef DEBUG
192 printf("LVP OR OVP OFF!\n");
193 printf("NEW_STATE: LVP_OVP_Auto On, Relais off\n");
194#endif
195 }
196
197 //KEIN LVP und keine OVP Abschaltung, Relais ist aber noch aus, dann einschalten
198 if ((lvpOROvpInput == 0) && (RELAIS_GetState() == 0))
199 {
200 RELAIS_SetPuls();
201 BUZZER_Beep(BUZZER_ON_TIME_CONFIRM); //Warnung
202 LEDS_GN_Off();
203 LEDS_GN_Blink_Start(LED_GN_ON_TIME_ON_MODE, LED_GN_OFF_TIME);
204#ifdef DEBUG
205 printf("LVP AND OVP ON!\n");
206 printf("NEW_STATE: LVP_OVP_Auto On, Relais on\n");
207#endif
208 }
209
210 // Prüfe Wechsel in off mode
211 if (BUTTON_GetMode() == BUTTON_OFF)
212 {
213 //Ausschalten muss immer möglich sein
214 RELAIS_ResetPuls();
215 BUZZER_Beep(BUZZER_ON_TIME_CONFIRM); //Bestätigung
216 LEDS_GN_Off();
217 LEDS_RT_Off();
218#ifdef DEBUG
219 printf("NEW_STATE: LVP_OVP_OFF\n");
220#endif
221 smState = LVP_OVP_OFF;
222 //Damit beim drücken auf on erstmal eingeschaltet wird
223 lvpAndOvpInputTimeCounter=0;
224 lvpOROvpInput = 0;
225 }
226
227
228}
229
230static void LVP_OVP_SM_ManualOn(void)
231{
232 // Prüfe Wechsel in off mode
233 if (BUTTON_GetMode() == BUTTON_OFF)
234 {
235 //Ausschalten muss immer möglich sein
236 RELAIS_ResetPuls();
237 BUZZER_Alarm_Stop();
238 LEDS_GN_Off();
239 LEDS_RT_Off();
240#ifdef DEBUG
241 printf("NEW_STATE: LVP_OVP_OFF\n");
242#endif
243 smState = LVP_OVP_OFF;
244 }
245
246}
247
248static void LVP_OVP_SM_Error(void)
249{
250 int faultInput;
251 int lvpAndOvpInput;
252
253 if (HAL_GPIO_ReadPin(GPIO_INPUT_FAULT_GPIO_Port, GPIO_INPUT_FAULT_Pin) == GPIO_PIN_RESET)
254 {
255 faultInput = 1;
256 }
257 else
258 {
259 faultInput = 0;
260 }
261
262
263
264 //Prüfe auf Wechsel des Modus AUTO / SM ON
265 if (BUTTON_GetMode() == BUTTON_AUTO)
266 {
267 if (faultInput == 0)
268 {
269 RELAIS_SetPuls();
270 BUZZER_Beep(BUZZER_ON_TIME_CONFIRM);
271 LEDS_GN_Blink_Start(LED_GN_ON_TIME_ON_MODE, LED_GN_OFF_TIME);
272 LEDS_RT_Off(); //Fehler löschen
273#ifdef DEBUG
274 printf("NEW_STATE: LVP_OVP_ON\n");
275#endif
276 smState = LVP_OVP_ON;
277 }
278 else
279 {
280 //Wechsel nicht möglich. Fehler Eingang weiterhin aktiv
281 BUZZER_Beep(BUZZER_ON_TIME_REJECT);
282 BUTTON_SetModeOff();
283 }
284 }
285
286 //Prüfe auf Wechsel in MANUAL ON Mode
287 //Keine Fehlerüberprüfungen. In diesem Modus werdem alle Alarme ignoriert.
288 if (BUTTON_GetMode() == BUTTON_MANUAL_ON)
289 {
290
291 RELAIS_SetPuls();
292 BUZZER_Alarm_Start(BUZZER_ON_TIME_ALARM_MANUAL_MODE, BUZZER_OFF_TIME);
293 LEDS_GN_On();
294 LEDS_RT_Off();
295 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
296#ifdef DEBUG
297 printf("NEW_STATE: LVP_OVP_MANUAL_ON\n");
298#endif
299 smState = LVP_OVP_MANUAL_ON;
300 }
301}
302
303
304
305void MODE_LVP_OVP_Exec(void)
306{
307 switch (smState)
308 {
309 case LVP_OVP_OFF:
310 LVP_OVP_SM_Off();
311 break;
312
313 case LVP_OVP_ON:
314 LVP_OVP_SM_On();
315 break;
316
317 case LVP_OVP_MANUAL_ON:
318 LVP_OVP_SM_ManualOn();
319 break;
320
321 case LVP_OVP_ERROR:
322 LVP_OVP_SM_Error();
323 break;
324
325 default:
326 break;
327 }
328}
329
330
Note: See TracBrowser for help on using the repository browser.