| 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 |
|
|---|
| 32 |
|
|---|
| 33 | typedef enum LVP_OVP_State_enum
|
|---|
| 34 | {
|
|---|
| 35 | LVP_OVP_OFF,
|
|---|
| 36 | LVP_OVP_ON,
|
|---|
| 37 | LVP_OVP_MANUAL_ON,
|
|---|
| 38 | LVP_OVP_ERROR
|
|---|
| 39 | } LVP_OVP_state_t;
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 | static LVP_OVP_state_t smState;
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 | static void LVP_OVP_SM_Off(void)
|
|---|
| 46 | {
|
|---|
| 47 | int faultInput;
|
|---|
| 48 | int lvpOROvpInput;
|
|---|
| 49 |
|
|---|
| 50 | if (HAL_GPIO_ReadPin(GPIO_INPUT_FAULT_GPIO_Port, GPIO_INPUT_FAULT_Pin) == GPIO_PIN_RESET)
|
|---|
| 51 | {
|
|---|
| 52 | faultInput = 1;
|
|---|
| 53 | }
|
|---|
| 54 | else
|
|---|
| 55 | {
|
|---|
| 56 | faultInput = 0;
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | 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))
|
|---|
| 60 | {
|
|---|
| 61 | lvpOROvpInput = 1;
|
|---|
| 62 | }else {
|
|---|
| 63 | lvpOROvpInput = 0;
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 | //Prüfe auf Wechsel des Modus AUTO / SM ON
|
|---|
| 70 | if (BUTTON_GetMode() == BUTTON_AUTO)
|
|---|
| 71 | {
|
|---|
| 72 | if (faultInput == 0)
|
|---|
| 73 | {
|
|---|
| 74 | RELAIS_SetPuls();
|
|---|
| 75 | BUZZER_Beep(BUZZER_ON_TIME_CONFIRM);
|
|---|
| 76 | LEDS_GN_Blink_Start(LED_GN_ON_TIME_ON_MODE, LED_GN_OFF_TIME);
|
|---|
| 77 | printf("NEW_STATE: LVP_OVP_ON\n");
|
|---|
| 78 | smState = LVP_OVP_ON;
|
|---|
| 79 |
|
|---|
| 80 | }
|
|---|
| 81 | else
|
|---|
| 82 | {
|
|---|
| 83 | //Wechsel nicht möglich. Fehler Eingang aktiv
|
|---|
| 84 | BUZZER_Beep(BUZZER_ON_TIME_REJECT);
|
|---|
| 85 | BUTTON_SetModeOff();
|
|---|
| 86 | //LEDS_RT_Blink_Start(LED_RT_ON_TIME_WARN_FAULT_INPUT, LED_GN_OFF_TIME); //Fehler Anzeigen
|
|---|
| 87 | 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
|
|---|
| 88 | printf("NEW_STATE: LVP_OVP_ERROR\n");
|
|---|
| 89 | smState =LVP_OVP_ERROR;
|
|---|
| 90 | }
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 | //Prüfe auf Wechsel in MANUAL ON Mode
|
|---|
| 95 | //Keine Fehlerüberprüfungen. In diesem Modus werdem alle Alarme ignoriert.
|
|---|
| 96 | if (BUTTON_GetMode() == BUTTON_MANUAL_ON)
|
|---|
| 97 | {
|
|---|
| 98 |
|
|---|
| 99 | RELAIS_SetPuls();
|
|---|
| 100 | BUZZER_Alarm_Start(BUZZER_ON_TIME_ALARM_MANUAL_MODE, BUZZER_OFF_TIME);
|
|---|
| 101 | LEDS_GN_On();
|
|---|
| 102 | 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
|
|---|
| 103 | printf("NEW_STATE: LVP_OVP_MANUAL_ON\n");
|
|---|
| 104 | smState = LVP_OVP_MANUAL_ON;
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | static void LVP_OVP_SM_On(void)
|
|---|
| 112 | {
|
|---|
| 113 | int faultInput = 0;
|
|---|
| 114 | int lvpOROvpInput = 0;
|
|---|
| 115 | static int lvpAndOvpInputTimeCounter = 0;
|
|---|
| 116 | static int oldtime;
|
|---|
| 117 |
|
|---|
| 118 | if (HAL_GPIO_ReadPin(GPIO_INPUT_FAULT_GPIO_Port, GPIO_INPUT_FAULT_Pin) == GPIO_PIN_RESET)
|
|---|
| 119 | {
|
|---|
| 120 | faultInput = 1;
|
|---|
| 121 | }
|
|---|
| 122 | else
|
|---|
| 123 | {
|
|---|
| 124 | faultInput = 0;
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | 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))
|
|---|
| 128 | {
|
|---|
| 129 | if (HAL_GetTick() != oldtime)
|
|---|
| 130 | {
|
|---|
| 131 | lvpAndOvpInputTimeCounter++;
|
|---|
| 132 | if (lvpAndOvpInputTimeCounter > 30000)
|
|---|
| 133 | {
|
|---|
| 134 | lvpOROvpInput = 0;
|
|---|
| 135 | lvpAndOvpInputTimeCounter=0;
|
|---|
| 136 | }
|
|---|
| 137 | oldtime = HAL_GetTick();
|
|---|
| 138 | }
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | 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))
|
|---|
| 142 | {
|
|---|
| 143 | if (HAL_GetTick() != oldtime)
|
|---|
| 144 | {
|
|---|
| 145 | lvpAndOvpInputTimeCounter++;
|
|---|
| 146 | if (lvpAndOvpInputTimeCounter > 30000)
|
|---|
| 147 | {
|
|---|
| 148 | lvpOROvpInput = 1;
|
|---|
| 149 | lvpAndOvpInputTimeCounter=0;
|
|---|
| 150 | }
|
|---|
| 151 | oldtime = HAL_GetTick();
|
|---|
| 152 | }
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 | // Prüfe Wechsel in off mode
|
|---|
| 158 | if (BUTTON_GetMode() == BUTTON_OFF)
|
|---|
| 159 | {
|
|---|
| 160 | //Ausschalten muss immer möglich sein
|
|---|
| 161 | RELAIS_ResetPuls();
|
|---|
| 162 | BUZZER_Beep(BUZZER_ON_TIME_CONFIRM); //Bestätigung
|
|---|
| 163 | LEDS_GN_Off();
|
|---|
| 164 | LEDS_RT_Off();
|
|---|
| 165 | printf("NEW_STATE: LVP_OVP_OFF\n");
|
|---|
| 166 | smState = LVP_OVP_OFF;
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | //Prüfe auf Fehlermode
|
|---|
| 170 | if (faultInput == 1)
|
|---|
| 171 | {
|
|---|
| 172 | RELAIS_ResetPuls();
|
|---|
| 173 | BUZZER_Beep(BUZZER_ON_TIME_REJECT); //Warnung
|
|---|
| 174 | LEDS_GN_Off();
|
|---|
| 175 | 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
|
|---|
| 176 | BUTTON_SetModeOff(); //Damit nicht von alleine wieder eingeschaltet wird
|
|---|
| 177 | printf("FAULT INPUT EVENT DETECTED!\n");
|
|---|
| 178 | printf("NEW_STATE: LVP_OVP_ERROR\n");
|
|---|
| 179 | smState = LVP_OVP_ERROR;
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 | if (lvpOROvpInput == 0)
|
|---|
| 183 | {
|
|---|
| 184 | RELAIS_ResetPuls();
|
|---|
| 185 | BUZZER_Beep(BUZZER_ON_TIME_REJECT); //Warnung
|
|---|
| 186 | LEDS_GN_Off();
|
|---|
| 187 | 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
|
|---|
| 188 | printf("LVP OR OVP FALLING!\n");
|
|---|
| 189 | printf("NEW_STATE: LVP_OVP_Auto On, Relais off\n");
|
|---|
| 190 |
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | if (lvpOROvpInput == 1)
|
|---|
| 194 | {
|
|---|
| 195 | RELAIS_SetPuls();
|
|---|
| 196 | BUZZER_Beep(BUZZER_ON_TIME_CONFIRM); //Warnung
|
|---|
| 197 | LEDS_GN_Off();
|
|---|
| 198 | LEDS_GN_Blink_Start(LED_GN_ON_TIME_ON_MODE, LED_GN_OFF_TIME);
|
|---|
| 199 | printf("LVP AND OVP RISING!\n");
|
|---|
| 200 | printf("NEW_STATE: LVP_OVP_Auto On, Relais on\n");
|
|---|
| 201 |
|
|---|
| 202 | }
|
|---|
| 203 |
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | static void LVP_OVP_SM_ManualOn(void)
|
|---|
| 207 | {
|
|---|
| 208 | // Prüfe Wechsel in off mode
|
|---|
| 209 | if (BUTTON_GetMode() == BUTTON_OFF)
|
|---|
| 210 | {
|
|---|
| 211 | //Ausschalten muss immer möglich sein
|
|---|
| 212 | RELAIS_ResetPuls();
|
|---|
| 213 | BUZZER_Alarm_Stop();
|
|---|
| 214 | LEDS_GN_Off();
|
|---|
| 215 | LEDS_RT_Off();
|
|---|
| 216 | printf("NEW_STATE: LVP_OVP_OFF\n");
|
|---|
| 217 | smState = LVP_OVP_OFF;
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | }
|
|---|
| 221 |
|
|---|
| 222 | static void LVP_OVP_SM_Error(void)
|
|---|
| 223 | {
|
|---|
| 224 | int faultInput;
|
|---|
| 225 | int lvpAndOvpInput;
|
|---|
| 226 |
|
|---|
| 227 | if (HAL_GPIO_ReadPin(GPIO_INPUT_FAULT_GPIO_Port, GPIO_INPUT_FAULT_Pin) == GPIO_PIN_RESET)
|
|---|
| 228 | {
|
|---|
| 229 | faultInput = 1;
|
|---|
| 230 | }
|
|---|
| 231 | else
|
|---|
| 232 | {
|
|---|
| 233 | faultInput = 0;
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 |
|
|---|
| 238 | //Prüfe auf Wechsel des Modus AUTO / SM ON
|
|---|
| 239 | if (BUTTON_GetMode() == BUTTON_AUTO)
|
|---|
| 240 | {
|
|---|
| 241 | if (faultInput == 0)
|
|---|
| 242 | {
|
|---|
| 243 | RELAIS_SetPuls();
|
|---|
| 244 | BUZZER_Beep(BUZZER_ON_TIME_CONFIRM);
|
|---|
| 245 | LEDS_GN_Blink_Start(LED_GN_ON_TIME_ON_MODE, LED_GN_OFF_TIME);
|
|---|
| 246 | LEDS_RT_Off(); //Fehler löschen
|
|---|
| 247 | printf("NEW_STATE: LVP_OVP_ON\n");
|
|---|
| 248 | smState = LVP_OVP_ON;
|
|---|
| 249 | }
|
|---|
| 250 | else
|
|---|
| 251 | {
|
|---|
| 252 | //Wechsel nicht möglich. Fehler Eingang weiterhin aktiv
|
|---|
| 253 | BUZZER_Beep(BUZZER_ON_TIME_REJECT);
|
|---|
| 254 | BUTTON_SetModeOff();
|
|---|
| 255 | }
|
|---|
| 256 | }
|
|---|
| 257 |
|
|---|
| 258 | //Prüfe auf Wechsel in MANUAL ON Mode
|
|---|
| 259 | //Keine Fehlerüberprüfungen. In diesem Modus werdem alle Alarme ignoriert.
|
|---|
| 260 | if (BUTTON_GetMode() == BUTTON_MANUAL_ON)
|
|---|
| 261 | {
|
|---|
| 262 |
|
|---|
| 263 | RELAIS_SetPuls();
|
|---|
| 264 | BUZZER_Alarm_Start(BUZZER_ON_TIME_ALARM_MANUAL_MODE, BUZZER_OFF_TIME);
|
|---|
| 265 | LEDS_GN_On();
|
|---|
| 266 | LEDS_RT_Off();
|
|---|
| 267 | 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
|
|---|
| 268 | printf("NEW_STATE: LVP_OVP_MANUAL_ON\n");
|
|---|
| 269 | smState = LVP_OVP_MANUAL_ON;
|
|---|
| 270 | }
|
|---|
| 271 |
|
|---|
| 272 |
|
|---|
| 273 |
|
|---|
| 274 | }
|
|---|
| 275 |
|
|---|
| 276 |
|
|---|
| 277 |
|
|---|
| 278 | void MODE_LVP_OVP_Exec(void)
|
|---|
| 279 | {
|
|---|
| 280 |
|
|---|
| 281 |
|
|---|
| 282 |
|
|---|
| 283 | switch (smState)
|
|---|
| 284 | {
|
|---|
| 285 | case LVP_OVP_OFF:
|
|---|
| 286 | LVP_OVP_SM_Off();
|
|---|
| 287 | break;
|
|---|
| 288 |
|
|---|
| 289 | case LVP_OVP_ON:
|
|---|
| 290 | LVP_OVP_SM_On();
|
|---|
| 291 | break;
|
|---|
| 292 |
|
|---|
| 293 | case LVP_OVP_MANUAL_ON:
|
|---|
| 294 | LVP_OVP_SM_ManualOn();
|
|---|
| 295 | break;
|
|---|
| 296 |
|
|---|
| 297 | case LVP_OVP_ERROR:
|
|---|
| 298 | LVP_OVP_SM_Error();
|
|---|
| 299 | break;
|
|---|
| 300 |
|
|---|
| 301 | default:
|
|---|
| 302 | break;
|
|---|
| 303 | }
|
|---|
| 304 | }
|
|---|
| 305 |
|
|---|
| 306 |
|
|---|