Created
May 23, 2020 22:50
-
-
Save juodumas/8901073a670a0942e3b89aac68917d7d to your computer and use it in GitHub Desktop.
FOC-AT32-patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hoverboard-firmware-hack-FOC>>git diff Src/bldc.c Makefile | |
diff --git a/Makefile b/Makefile | |
index 94b9a6a..1e6d40c 100644 | |
--- a/Makefile | |
+++ b/Makefile | |
@@ -179,6 +179,9 @@ clean: | |
flash: | |
st-flash --reset write $(BUILD_DIR)/$(TARGET).bin 0x8000000 | |
+flash-at32: | |
+ openocd -f interface/stlink-v2.cfg -f target/stm32f3x.cfg -c init -c "reset halt" -c "stm32f1x unlock 0" -c "flash write_image erase $(BUILD_DIR)/$(TARGET).hex 0 ihex" -c "shutdown" | |
+ | |
unlock: | |
openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg -c init -c "reset halt" -c "stm32f1x unlock 0" | |
diff --git a/Src/bldc.c b/Src/bldc.c | |
index 680d70f..a943d97 100644 | |
--- a/Src/bldc.c | |
+++ b/Src/bldc.c | |
@@ -63,6 +63,7 @@ uint8_t buzzerFreq = 0; | |
uint8_t buzzerPattern = 0; | |
static uint32_t buzzerTimer = 0; | |
+uint8_t enablePrev = 0; // initially motors are disabled for SAFETY | |
uint8_t enable = 0; // initially motors are disabled for SAFETY | |
static uint8_t enableFin = 0; | |
@@ -98,6 +99,9 @@ void DMA1_Channel1_IRQHandler(void) { | |
offsetdcr = (adc_buffer.dcr + offsetdcr) / 2; | |
return; | |
} | |
+ else if (enablePrev == 0 && enable == 1) { | |
+ offsetcount = 0; | |
+ } | |
if (buzzerTimer % 1000 == 0) { // because you get float rounding errors if it would run every time -> not any more, everything converted to fixed-point | |
filtLowPass32(adc_buffer.batt1, BAT_FILT_COEF, &batVoltageFixdt); | |
@@ -152,6 +156,7 @@ void DMA1_Channel1_IRQHandler(void) { | |
/* Make sure to stop BOTH motors in case of an error */ | |
enableFin = enable && !rtY_Left.z_errCode && !rtY_Right.z_errCode; | |
+ enablePrev = enable; | |
// ========================= LEFT MOTOR ============================ | |
// Get hall sensors values |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment