source: trunk/firmware_v2/SES/src/mode_lvp.c@ 17

Last change on this file since 17 was 17, checked in by f.jahn, 4 months ago
File size: 7.4 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.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 LVP_State_enum
35{
36 LVP_OFF,
37 LVP_ON,
38 LVP_MANUAL_ON,
39 LVP_ERROR
40} LVP_state_t;
41
42
43static LVP_state_t smState;
44
45
46static void LVP_SM_Off(void)
47{
48 int faultInput;
49 int lvpInput;
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_LVP_GPIO_Port, GPIO_INPUT_LVP_Pin) == GPIO_PIN_SET)
61 {
62 lvpInput = 1;
63 }else {
64 lvpInput = 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: SECONDARYPROTECTION_ON\n");
79 smState = LVP_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: SECONDARYPROTECTION_ERROR\n");
90 smState =LVP_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: SECONDARYPROTECTION_MANUAL_ON\n");
105 smState = LVP_MANUAL_ON;
106 }
107
108
109
110}
111
112static void LVP_SM_On(void)
113{
114 int faultInput = 0;
115 int lvpInput = 0;
116 static int lvpInputTimeCounter = 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_LVP_GPIO_Port, GPIO_INPUT_LVP_Pin) == GPIO_PIN_RESET)
129 {
130 if (HAL_GetTick() != oldtime)
131 {
132 lvpInputTimeCounter++;
133 if (lvpInputTimeCounter > 30000)
134 {
135 lvpInput = 0;
136 lvpInputTimeCounter=0;
137 }
138 oldtime = HAL_GetTick();
139 }
140 }
141 else
142 {
143 lvpInputTimeCounter = 0;
144 lvpInput = 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: SECONDARYPROTECTION_OFF\n");
158 smState = LVP_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: SECONDARYPROTECTION_ERROR\n");
171 smState = LVP_ERROR;
172 }
173
174 if ((lvpInput == 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("LVP FALLING EVENT DETECTED!\n");
181 printf("NEW_STATE: LVP OFF\n");
182 }
183
184
185 //Einkommentieren für auto Reconnect
186 //if ((lvpInput == 1) && ( RELAIS_GetState() == 0))
187 //{
188 // RELAIS_SetPuls();
189 // BUZZER_Beep(BUZZER_ON_TIME_CONFIRM); //Warnung
190 // LEDS_GN_Blink_Start(LED_GN_ON_TIME_ON_MODE, LED_GN_OFF_TIME);
191 // BUTTON_SetModeOff(); //Damit nicht von alleine wieder eingeschaltet wird
192 // printf("BMS SECONDARY PROTECTION FAULT EVENT DETECTED (LVP & OVP )!\n");
193 // printf("NEW_STATE: SECONDARYPROTECTION_ERROR\n");
194 //}
195
196
197}
198
199static void LVP_SM_ManualOn(void)
200{
201 // Prüfe Wechsel in off mode
202 if (BUTTON_GetMode() == BUTTON_OFF)
203 {
204 //Ausschalten muss immer möglich sein
205 RELAIS_ResetPuls();
206 BUZZER_Alarm_Stop();
207 LEDS_GN_Off();
208 LEDS_RT_Off();
209 printf("NEW_STATE: LVP_OFF\n");
210 smState = LVP_OFF;
211 }
212
213}
214
215static void LVP_SM_Error(void)
216{
217 int faultInput;
218 int lvpAndOvpInput;
219
220 if (HAL_GPIO_ReadPin(GPIO_INPUT_FAULT_GPIO_Port, GPIO_INPUT_FAULT_Pin) == GPIO_PIN_RESET)
221 {
222 faultInput = 1;
223 }
224 else
225 {
226 faultInput = 0;
227 }
228
229
230
231 //Prüfe auf Wechsel des Modus AUTO / SM ON
232 if (BUTTON_GetMode() == BUTTON_AUTO)
233 {
234 if (faultInput == 0)
235 {
236 RELAIS_SetPuls();
237 BUZZER_Beep(BUZZER_ON_TIME_CONFIRM);
238 LEDS_GN_Blink_Start(LED_GN_ON_TIME_ON_MODE, LED_GN_OFF_TIME);
239 LEDS_RT_Off(); //Fehler löschen
240 printf("NEW_STATE: LVP_ON\n");
241 smState = LVP_ON;
242 }
243 else
244 {
245 //Wechsel nicht möglich. Fehler Eingang weiterhin aktiv
246 BUZZER_Beep(BUZZER_ON_TIME_REJECT);
247 BUTTON_SetModeOff();
248 }
249 }
250
251 //Prüfe auf Wechsel in MANUAL ON Mode
252 //Keine Fehlerüberprüfungen. In diesem Modus werdem alle Alarme ignoriert.
253 if (BUTTON_GetMode() == BUTTON_MANUAL_ON)
254 {
255
256 RELAIS_SetPuls();
257 BUZZER_Alarm_Start(BUZZER_ON_TIME_ALARM_MANUAL_MODE, BUZZER_OFF_TIME);
258 LEDS_GN_On();
259 LEDS_RT_Off();
260 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
261 printf("NEW_STATE: SECONDARYPROTECTION_MANUAL_ON\n");
262 smState = LVP_MANUAL_ON;
263 }
264
265
266
267}
268
269
270
271void MODE_LVP_Exec(void)
272{
273
274
275
276 switch (smState)
277 {
278 case LVP_OFF:
279 LVP_SM_Off();
280 break;
281
282 case LVP_ON:
283 LVP_SM_On();
284 break;
285
286 case LVP_MANUAL_ON:
287 LVP_SM_ManualOn();
288 break;
289
290 case LVP_ERROR:
291 LVP_SM_Error();
292 break;
293
294 default:
295 break;
296 }
297}
298
299
Note: See TracBrowser for help on using the repository browser.