Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
Removed CAN tests
  • Loading branch information
jsphuebner committed Oct 3, 2024
1 parent 63762a7 commit 191a330
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 6 additions & 0 deletions sinus.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@
<Unit filename="test/Makefile">
<Option target="Test" />
</Unit>
<Unit filename="test/stub_canhardware.cpp">
<Option target="Test" />
</Unit>
<Unit filename="test/stub_canhardware.h">
<Option target="Test" />
</Unit>
<Unit filename="test/test.h">
<Option target="Test" />
</Unit>
Expand Down
14 changes: 11 additions & 3 deletions src/pwmgeneration-foc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 191a330

Please sign in to comment.