source: trunk/firmware_v2/SES/src/mode_lvp_ovp.c @ 24

Last change on this file since 24 was 24, checked in by f.jahn, 4 days ago
LVP, OVP, LVP
OVP modes implementiert
  • Lüftersteuerung in eigenes Modul verlagert
File size: 8.5 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      printf("LVP_OVP_SM_Off: NEW_STATE: LVP_OVP_ON\n");
72      smState = LVP_OVP_ON;
73
74    }
75    else   
76    {
77      //Wechsel nicht möglich. Fehler Eingang aktiv
78      BUZZER_Beep(BUZZER_ON_TIME_REJECT);
79      BUTTON_SetModeOff();
80      //LEDS_RT_Blink_Start(LED_RT_ON_TIME_WARN_FAULT_INPUT, LED_GN_OFF_TIME); //Fehler Anzeigen
81          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
82      printf("LVP_OVP_SM_Off: NEW_STATE: LVP_OVP_ERROR_FAULT_INPUT\n");
83      smState =LVP_OVP_ERROR;
84    }
85  }
86
87
88  //Prüfe auf Wechsel in MANUAL ON Mode
89  //Keine Fehlerüberprüfungen. In diesem Modus werdem alle Alarme ignoriert.
90  if (BUTTON_GetMode() == BUTTON_MANUAL_ON)
91  {
92     
93      RELAIS_SetPuls();
94      BUZZER_Alarm_Start(BUZZER_ON_TIME_ALARM_MANUAL_MODE, BUZZER_OFF_TIME);
95      LEDS_GN_On();
96      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
97      printf("NEW_STATE: LVP_OVP_MANUAL_ON\n");
98      smState = LVP_OVP_MANUAL_ON;
99  }
100
101
102
103}
104
105static void LVP_OVP_SM_On(void)
106{
107  int faultInput = 0;
108  static int lvpOROvpInput = 0;
109  static int lvpAndOvpInputTimeCounter = 0;
110  static int oldtime;
111
112  if (HAL_GPIO_ReadPin(GPIO_INPUT_FAULT_GPIO_Port, GPIO_INPUT_FAULT_Pin) == GPIO_PIN_RESET)       
113  {
114    faultInput = 1;
115  }
116  else
117  {
118    faultInput = 0;
119  }
120 
121  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))
122  {
123    if (HAL_GetTick() != oldtime)
124    {
125      if (lvpAndOvpInputTimeCounter < 5000)lvpAndOvpInputTimeCounter++;
126      if (lvpAndOvpInputTimeCounter >= 5000)
127      {
128        lvpOROvpInput = 1;
129        lvpAndOvpInputTimeCounter=0;
130      }
131      oldtime = HAL_GetTick();
132    }
133  }
134
135  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))
136  {
137//    if (HAL_GetTick() != oldtime)
138//    {
139//      lvpAndOvpInputTimeCounter++;
140//      if (lvpAndOvpInputTimeCounter > 30000)
141//      {
142        lvpOROvpInput = 0;
143        lvpAndOvpInputTimeCounter=0;
144//      }
145//      oldtime = HAL_GetTick();
146//    }
147  }
148
149 
150
151
152  //Prüfe auf Fehlermode
153  if (faultInput == 1)
154  {
155    RELAIS_ResetPuls();
156    BUZZER_Beep(BUZZER_ON_TIME_REJECT); //Warnung
157    LEDS_GN_Off();
158    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
159    BUTTON_SetModeOff(); //Damit nicht von alleine wieder eingeschaltet wird
160    printf("FAULT INPUT EVENT DETECTED!\n");
161    printf("NEW_STATE: LVP_OVP_ERROR\n");
162    smState = LVP_OVP_ERROR;
163  }
164
165    if (CHIP_TEMPERATURE_GetTemp() > 80)
166  {
167        RELAIS_ResetPuls();
168        BUZZER_Beep(BUZZER_ON_TIME_REJECT); //Warnung
169        LEDS_GN_Off();
170        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
171        BUTTON_SetModeOff(); //Damit nicht von alleine wieder eingeschaltet wird
172        printf("NEW_STATE: MAINSWITCH_ERROR, Temp too high\n");
173        smState = LVP_OVP_ERROR;         
174  }
175
176
177  //LVP oder OVP hat stattgefunden, und Relais ist ein, dann aus
178  if ((lvpOROvpInput == 1) && (RELAIS_GetState() == 1)) 
179  {
180    RELAIS_ResetPuls();
181    BUZZER_Beep(BUZZER_ON_TIME_REJECT); //Warnung
182    LEDS_GN_Off();
183    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
184    printf("LVP OR OVP OFF!\n");
185    printf("NEW_STATE: LVP_OVP_Auto On, Relais off\n");
186   
187  }
188
189  //KEIN LVP und keine OVP Abschaltung, Relais ist aber noch aus, dann einschalten
190  if ((lvpOROvpInput == 0) && (RELAIS_GetState() == 0))
191  {
192    RELAIS_SetPuls();
193    BUZZER_Beep(BUZZER_ON_TIME_CONFIRM); //Warnung
194    LEDS_GN_Off();
195    LEDS_GN_Blink_Start(LED_GN_ON_TIME_ON_MODE, LED_GN_OFF_TIME);
196    printf("LVP AND OVP ON!\n");
197    printf("NEW_STATE: LVP_OVP_Auto On, Relais on\n");
198   
199  }
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_Beep(BUZZER_ON_TIME_CONFIRM); //Bestätigung
207    LEDS_GN_Off();
208    LEDS_RT_Off();
209    printf("NEW_STATE: LVP_OVP_OFF\n");
210    smState = LVP_OVP_OFF;
211        //Damit beim drücken auf on erstmal eingeschaltet wird
212        lvpAndOvpInputTimeCounter=0;
213        lvpOROvpInput = 0;
214  }
215
216
217}
218
219static void LVP_OVP_SM_ManualOn(void)
220{
221  // Prüfe Wechsel in off mode
222  if (BUTTON_GetMode() == BUTTON_OFF)
223  {
224    //Ausschalten muss immer möglich sein
225    RELAIS_ResetPuls();
226    BUZZER_Alarm_Stop();
227    LEDS_GN_Off();
228    LEDS_RT_Off();
229    printf("NEW_STATE: LVP_OVP_OFF\n");
230    smState = LVP_OVP_OFF;
231  }
232
233}
234
235static void LVP_OVP_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      printf("NEW_STATE: LVP_OVP_ON\n");
261      smState = LVP_OVP_ON;
262    }
263    else
264    {
265      //Wechsel nicht möglich. Fehler Eingang weiterhin aktiv
266      BUZZER_Beep(BUZZER_ON_TIME_REJECT);
267      BUTTON_SetModeOff();
268    }
269  }
270
271  //Prüfe auf Wechsel in MANUAL ON Mode
272  //Keine Fehlerüberprüfungen. In diesem Modus werdem alle Alarme ignoriert.
273  if (BUTTON_GetMode() == BUTTON_MANUAL_ON)
274  {
275     
276      RELAIS_SetPuls();
277      BUZZER_Alarm_Start(BUZZER_ON_TIME_ALARM_MANUAL_MODE, BUZZER_OFF_TIME);
278      LEDS_GN_On();
279      LEDS_RT_Off();
280      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
281      printf("NEW_STATE: LVP_OVP_MANUAL_ON\n");
282      smState = LVP_OVP_MANUAL_ON;
283  }
284
285
286
287}
288
289
290
291void MODE_LVP_OVP_Exec(void)
292{
293
294 
295
296  switch (smState)
297  {
298    case LVP_OVP_OFF:
299     LVP_OVP_SM_Off();
300    break;
301
302    case LVP_OVP_ON:
303      LVP_OVP_SM_On();
304    break;
305
306    case LVP_OVP_MANUAL_ON:
307      LVP_OVP_SM_ManualOn();
308    break;
309
310    case LVP_OVP_ERROR:
311      LVP_OVP_SM_Error();
312    break;
313
314    default:
315    break;
316  }
317}
318
319
Note: See TracBrowser for help on using the repository browser.