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

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