From 191a3304a333aef85bf78ec91c32fd4579225ff1 Mon Sep 17 00:00:00 2001 From: jsphuebner Date: Thu, 3 Oct 2024 19:18:08 +0200 Subject: [PATCH] Code cleanup Removed CAN tests --- sinus.cbp | 6 ++++++ src/pwmgeneration-foc.cpp | 14 +++++++++++--- test/Makefile | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/sinus.cbp b/sinus.cbp index 62c95c7..ed17cf7 100644 --- a/sinus.cbp +++ b/sinus.cbp @@ -142,6 +142,12 @@ + + + + diff --git a/src/pwmgeneration-foc.cpp b/src/pwmgeneration-foc.cpp index 50c13e9..e965a55 100644 --- a/src/pwmgeneration-foc.cpp +++ b/src/pwmgeneration-foc.cpp @@ -33,6 +33,7 @@ #define FRQ_TO_ANGLE(frq) FP_TOINT((frq << SineCore::BITS) / pwmfrq) #define DIGIT_TO_DEGREE(a) FP_FROMINT(angle) / (65536 / 360) +#define DEGREE_TO_DIGIT(a) (((a) * 65536) / 360) #ifndef QLIMIT_FREQUENCY #define QLIMIT_FREQUENCY FP_FROMINT(30) @@ -276,15 +277,22 @@ static s32fp MeasureCoggingCurrent(uint16_t angle, s32fp id) return coggingCurrent; } +/** \brief Generates a trapezoidal wave form to counter the cogging current of IPM motors + * + * \param angle rotor angle + * \param coggingCurrent magnitude of cogging current in A + * \return int32_t counter waveform as integer + * + */ static int32_t GenerateAntiCoggingSignal(uint16_t angle, s32fp coggingCurrent) { angle += Param::GetInt(Param::cogph); - if (angle < 16384) + if (angle < DEGREE_TO_DIGIT(90)) angle = angle; //no change - else if (angle < 32768) //90 to 180° + else if (angle < DEGREE_TO_DIGIT(180)) //90 to 180° angle = 32767 - angle; - else if (angle < 49152) //180 to 270° + else if (angle < DEGREE_TO_DIGIT(270)) //180 to 270° angle = angle - 32767; else //270 to 360° angle = 65535 - angle; diff --git a/test/Makefile b/test/Makefile index e030ea4..8ed3409 100644 --- a/test/Makefile +++ b/test/Makefile @@ -7,7 +7,7 @@ CPPFLAGS = -ggdb -DSTM32F1 -DCTRL_FOC=1 -DCTRL_SINE=0 -DCTRL=CTRL_FOC -I../in LDFLAGS = -g BINARY = test_sine OBJS = test_main.o fu.o test_fu.o test_fp.o test_vcu.o my_fp.o my_string.o params.o vehiclecontrol.o \ - test_throttle.o throttle.o sine_core.o temp_meas.o stub_canhardware.o test_canmap.o canmap.o \ + test_throttle.o throttle.o sine_core.o temp_meas.o stub_canhardware.o \ stub_libopencm3.o VPATH = ../src ../libopeninv/src