source: trunk/firmware_v2/SES/src/mode_ovp.c@ 20

Last change on this file since 20 was 17, checked in by f.jahn, 4 months ago
File size: 7.2 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_ovp.h"
26#include "button.h"
27#include "relais.h"
28#include "main.h"
29#include "leds.h"
30#include "buzzer.h"
31
32
33
34typedef enum OVP_State_enum
35{
36 OVP_OFF,
37 OVP_ON,
38 OVP_MANUAL_ON,
39 OVP_ERROR
40} OVP_state_t;
41
42
43static OVP_state_t smState;
44
45
46static void OVP_SM_Off(void)
47{
48 int faultInput;
49 int ovpInput;
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 if (HAL_GPIO_ReadPin(GPIO_INPUT_OVP_GPIO_Port, GPIO_INPUT_OVP_Pin) == GPIO_PIN_SET)
61 {
62 ovpInput = 1;
63 }else {
64 ovpInput = 0;
65 }
66
67
68
69
70 //Prüfe auf Wechsel des Modus AUTO / SM ON
71 if (BUTTON_GetMode() == BUTTON_AUTO)
72 {
73 if (faultInput == 0)
74 {
75 RELAIS_SetPuls();
76 BUZZER_Beep(BUZZER_ON_TIME_CONFIRM);
77 LEDS_GN_Blink_Start(LED_GN_ON_TIME_ON_MODE, LED_GN_OFF_TIME);
78 printf("NEW_STATE: LVP_ON\n");
79 smState = OVP_ON;
80
81 }
82 else
83 {
84 //Wechsel nicht möglich. Fehler Eingang aktiv
85 BUZZER_Beep(BUZZER_ON_TIME_REJECT);
86 BUTTON_SetModeOff();
87 //LEDS_RT_Blink_Start(LED_RT_ON_TIME_WARN_FAULT_INPUT, LED_GN_OFF_TIME); //Fehler Anzeigen
88 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
89 printf("NEW_STATE: LVP_ERROR\n");
90 smState = OVP_ERROR;
91 }
92 }
93
94
95 //Prüfe auf Wechsel in MANUAL ON Mode
96 //Keine Fehlerüberprüfungen. In diesem Modus werdem alle Alarme ignoriert.
97 if (BUTTON_GetMode() == BUTTON_MANUAL_ON)
98 {
99
100 RELAIS_SetPuls();
101 BUZZER_Alarm_Start(BUZZER_ON_TIME_ALARM_MANUAL_MODE, BUZZER_OFF_TIME);
102 LEDS_GN_On();
103 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
104 printf("NEW_STATE: LVP_MANUAL_ON\n");
105 smState = OVP_MANUAL_ON;
106 }
107
108
109
110}
111
112static void OVP_SM_On(void)
113{
114 int faultInput = 0;
115 int ovpInput = 0;
116 static int ovpInputTimeCounter = 0;
117 static int oldtime;
118
119 if (HAL_GPIO_ReadPin(GPIO_INPUT_FAULT_GPIO_Port, GPIO_INPUT_FAULT_Pin) == GPIO_PIN_RESET)
120 {
121 faultInput = 1;
122 }
123 else
124 {
125 faultInput = 0;
126 }
127
128 if (HAL_GPIO_ReadPin(GPIO_INPUT_OVP_GPIO_Port, GPIO_INPUT_OVP_Pin) == GPIO_PIN_RESET)
129 {
130 if (HAL_GetTick() != oldtime)
131 {
132 ovpInputTimeCounter++;
133 if (ovpInputTimeCounter > 30000)
134 {
135 ovpInput = 0;
136 ovpInputTimeCounter=0;
137 }
138 oldtime = HAL_GetTick();
139 }
140 }
141 else
142 {
143 ovpInputTimeCounter = 0;
144 ovpInput = 1;
145 }
146
147
148
149 // Prüfe Wechsel in off mode
150 if (BUTTON_GetMode() == BUTTON_OFF)
151 {
152 //Ausschalten muss immer möglich sein
153 RELAIS_ResetPuls();
154 BUZZER_Beep(BUZZER_ON_TIME_CONFIRM); //Bestätigung
155 LEDS_GN_Off();
156 LEDS_RT_Off();
157 printf("NEW_STATE: LVP_OFF\n");
158 smState = OVP_OFF;
159 }
160
161 //Prüfe auf Fehlermode
162 if (faultInput == 1)
163 {
164 RELAIS_ResetPuls();
165 BUZZER_Beep(BUZZER_ON_TIME_REJECT); //Warnung
166 LEDS_GN_Off();
167 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
168 BUTTON_SetModeOff(); //Damit nicht von alleine wieder eingeschaltet wird
169 printf("FAULT INPUT EVENT DETECTED!\n");
170 printf("NEW_STATE: OVP_ERROR\n");
171 smState = OVP_ERROR;
172 }
173
174 if ((ovpInput == 0) && ( RELAIS_GetState() == 1))
175 {
176 RELAIS_ResetPuls();
177 BUZZER_Beep(BUZZER_ON_TIME_REJECT); //Warnung
178 LEDS_GN_Off();
179 BUTTON_SetModeOff(); //Damit nicht von alleine wieder eingeschaltet wird
180 printf("OVP Falling )!\n");
181 printf("NEW_STATE: OVP AUTO, Relais off\n");
182 }
183
184
185 if ((ovpInput == 1) && ( RELAIS_GetState() == 0))
186 {
187 RELAIS_SetPuls();
188 BUZZER_Beep(BUZZER_ON_TIME_CONFIRM); //Warnung
189 LEDS_GN_Blink_Start(LED_GN_ON_TIME_ON_MODE, LED_GN_OFF_TIME*5);
190 BUTTON_SetModeOff(); //Damit nicht von alleine wieder eingeschaltet wird
191 printf("OVP RISING!\n");
192 printf("NEW_STATE: OVP AUTO, Relais off\n");
193 }
194
195
196}
197
198static void OVP_SM_ManualOn(void)
199{
200 // Prüfe Wechsel in off mode
201 if (BUTTON_GetMode() == BUTTON_OFF)
202 {
203 //Ausschalten muss immer möglich sein
204 RELAIS_ResetPuls();
205 BUZZER_Alarm_Stop();
206 LEDS_GN_Off();
207 LEDS_RT_Off();
208 printf("NEW_STATE: SECONDARYPROTECTION_OFF\n");
209 smState = OVP_OFF;
210 }
211
212}
213
214static void OVP_SM_Error(void)
215{
216 int faultInput;
217
218
219 if (HAL_GPIO_ReadPin(GPIO_INPUT_FAULT_GPIO_Port, GPIO_INPUT_FAULT_Pin) == GPIO_PIN_RESET)
220 {
221 faultInput = 1;
222 }
223 else
224 {
225 faultInput = 0;
226 }
227
228
229
230 //Prüfe auf Wechsel des Modus AUTO / SM ON
231 if (BUTTON_GetMode() == BUTTON_AUTO)
232 {
233 if (faultInput == 0)
234 {
235 RELAIS_SetPuls();
236 BUZZER_Beep(BUZZER_ON_TIME_CONFIRM);
237 LEDS_GN_Blink_Start(LED_GN_ON_TIME_ON_MODE, LED_GN_OFF_TIME);
238 LEDS_RT_Off(); //Fehler löschen
239 printf("NEW_STATE: OVP_ON\n");
240 smState = OVP_ON;
241 }
242 else
243 {
244 //Wechsel nicht möglich. Fehler Eingang weiterhin aktiv
245 BUZZER_Beep(BUZZER_ON_TIME_REJECT);
246 BUTTON_SetModeOff();
247 }
248 }
249
250 //Prüfe auf Wechsel in MANUAL ON Mode
251 //Keine Fehlerüberprüfungen. In diesem Modus werdem alle Alarme ignoriert.
252 if (BUTTON_GetMode() == BUTTON_MANUAL_ON)
253 {
254
255 RELAIS_SetPuls();
256 BUZZER_Alarm_Start(BUZZER_ON_TIME_ALARM_MANUAL_MODE, BUZZER_OFF_TIME);
257 LEDS_GN_On();
258 LEDS_RT_Off();
259 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
260 printf("NEW_STATE: OVP_MANUAL_ON\n");
261 smState = OVP_MANUAL_ON;
262 }
263
264
265
266}
267
268
269
270void MODE_OVP_Exec(void)
271{
272
273
274
275 switch (smState)
276 {
277 case OVP_OFF:
278 OVP_SM_Off();
279 break;
280
281 case OVP_ON:
282 OVP_SM_On();
283 break;
284
285 case OVP_MANUAL_ON:
286 OVP_SM_ManualOn();
287 break;
288
289 case OVP_ERROR:
290 OVP_SM_Error();
291 break;
292
293 default:
294 break;
295 }
296}
297
298
Note: See TracBrowser for help on using the repository browser.