Skip to content

Commit

Permalink
Motors are disabled as soon as poweroff() is called.
Browse files Browse the repository at this point in the history
  • Loading branch information
p-h-a-i-l committed Jan 2, 2019
1 parent c541607 commit c84f3d4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
6 changes: 3 additions & 3 deletions platformio.ini
Expand Up @@ -3,7 +3,7 @@

[platformio]
include_dir = inc
;env_default = genericSTM32F103RC
env_default = genericSTM32F103RC
;env_default = transport_board
;env_default = paddelec

Expand Down Expand Up @@ -42,7 +42,7 @@ build_flags =
-D PWM_FREQ=16000 ; PWM frequency in Hz
-D DEAD_TIME=32 ; PWM deadtime
-D DELAY_IN_MAIN_LOOP=5 ; in ms. default 5. it is independent of all the timing critical stuff. do not touch if you do not know what you are doing.
-D TIMEOUT=5 ; number of wrong / missing input commands before emergency off
-D TIMEOUT=50 ; number of wrong / missing input commands before emergency off
-D SOFTWATCHDOG_TIMEOUT=50 ; Watchdog, Monitors main loop. Stops motors and shuts down when not called after xx ms.
; ############################### GENERAL ###############################
-D BAT_CALIB_REAL_VOLTAGE=43.0 ; input voltage measured by multimeter
Expand Down Expand Up @@ -146,7 +146,7 @@ build_flags =
-D PWM_FREQ=16000 ; PWM frequency in Hz
-D DEAD_TIME=32 ; PWM deadtime
-D DELAY_IN_MAIN_LOOP=5 ; in ms. default 5. it is independent of all the timing critical stuff. do not touch if you do not know what you are doing.
-D TIMEOUT=5 ; number of wrong / missing input commands before emergency off
-D TIMEOUT=50 ; number of wrong / missing input commands before emergency off
-D SOFTWATCHDOG_TIMEOUT=50 ; Watchdog, Monitors main loop. Stops motors and shuts down when not called after xx ms.
; ############################### GENERAL ###############################
-D BAT_CALIB_REAL_VOLTAGE=43.0 ; input voltage measured by multimeter
Expand Down
41 changes: 22 additions & 19 deletions src/main.c
Expand Up @@ -91,27 +91,28 @@ int milli_vel_error_sum = 0;


void poweroff() {
if (ABS(speed) < 20) {
buzzerPattern = 0;
enable = 0;
for (int i = 0; i < 8; i++) {
buzzerFreq = i;
enable = 0; // disable Motors
if (ABS(speed) < 20) {
buzzerPattern = 0;
for (int i = 0; i < 8; i++) {
buzzerFreq = i;

#ifdef SOFTWATCHDOG_TIMEOUT
for(int j = 0; j < 50; j++) {
__HAL_TIM_SET_COUNTER(&htim3, 0); // Kick the Watchdog
HAL_Delay(1);
}
for(int j = 0; j < 50; j++) {
__HAL_TIM_SET_COUNTER(&htim3, 0); // Kick the Watchdog
HAL_Delay(1);
}
}
#else
HAL_Delay(100);
#endif
}
HAL_GPIO_WritePin(OFF_PORT, OFF_PIN, 0); // shutdown power
while(1) {}
} else {
speed=0;
steer=0;
powerofftimer = 1000;
HAL_Delay(100);
}
#endif

HAL_GPIO_WritePin(OFF_PORT, OFF_PIN, 0); // shutdown power
while(1) {}
} else {
powerofftimer = 1000;
}
}

#ifdef CONTROL_SERIAL_NAIVE_CRC
Expand Down Expand Up @@ -456,7 +457,9 @@ int main(void) {


// ####### BEEP AND EMERGENCY POWEROFF #######
if ((TEMP_POWEROFF_ENABLE && board_temp_deg_c >= TEMP_POWEROFF && ABS(speed) < 20) || (batteryVoltage < ((float)BAT_LOW_DEAD * (float)BAT_NUMBER_OF_CELLS) && ABS(speed) < 20)) { // poweroff before mainboard burns OR low bat 3
if (TEMP_POWEROFF_ENABLE && board_temp_deg_c >= TEMP_POWEROFF && ABS(speed) < 20) { // poweroff before mainboard burns
poweroff();
} else if (batteryVoltage < ((float)BAT_LOW_DEAD * (float)BAT_NUMBER_OF_CELLS) && ABS(speed) < 20) { // poweroff low bat 3
poweroff();
} else if (TEMP_WARNING_ENABLE && board_temp_deg_c >= TEMP_WARNING) { // beep if mainboard gets hot
buzzerFreq = 4;
Expand Down

0 comments on commit c84f3d4

Please sign in to comment.