Skip to content

Commit 960cd3b

Browse files
committed
Some updates to MTPA PR
1 parent dea04a5 commit 960cd3b

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
lines changed

CHANGELOG

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Fixed motor temperature reading on hw with ADC mux.
66
* Added speed PID input ramping option.
77
* Added LSM6DS3 IMU support.
8+
* Added MTPA support. See See: https://github.com/vedderb/bldc/pull/179
89

910
=== FW 5.01 ===
1011
* Fixed PPM bug in previous release.

conf_general.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#define FW_VERSION_MAJOR 5
2525
#define FW_VERSION_MINOR 02
2626
// Set to 0 for building a release and iterate during beta test builds
27-
#define FW_TEST_VERSION_NUMBER 3
27+
#define FW_TEST_VERSION_NUMBER 4
2828

2929
#include "datatypes.h"
3030

confgenerator.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
#include <stdbool.h>
99

1010
// Constants
11-
#define MCCONF_SIGNATURE 2013508732
12-
#define APPCONF_SIGNATURE 2460147246
11+
#define MCCONF_SIGNATURE 1358025204
12+
#define APPCONF_SIGNATURE 2662993821
1313

1414
// Functions
1515
int32_t confgenerator_serialize_mcconf(uint8_t *buffer, const mc_configuration *conf);

mcpwm_foc.c

+8-13
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ static void terminal_plot_hfi(int argc, const char **argv);
195195
static void timer_update(volatile motor_all_state_t *motor, float dt);
196196
static void input_current_offset_measurement( void );
197197
static void hfi_update(volatile motor_all_state_t *motor);
198-
static void apply_mtpa(float *id, float *iq, volatile motor_all_state_t *motor);
199198

200199
// Threads
201200
static THD_WORKING_AREA(timer_thread_wa, 1024);
@@ -2547,7 +2546,14 @@ void mcpwm_foc_adc_int_handler(void *p, uint32_t flags) {
25472546
motor_now->m_motor_state.phase = motor_now->m_phase_now_override;
25482547
}
25492548

2550-
apply_mtpa(&id_set_tmp, &iq_set_tmp, motor_now);
2549+
// Apply MTPA. See: https://github.com/vedderb/bldc/pull/179
2550+
float ld_lq_diff = conf_now->foc_motor_ld_lq_diff;
2551+
if (ld_lq_diff != 0.0) {
2552+
float lambda = conf_now->foc_motor_flux_linkage;
2553+
2554+
id_set_tmp = (lambda - sqrtf(SQ(lambda) + 8.0 * SQ(ld_lq_diff) * SQ(iq_set_tmp))) / (4.0 * ld_lq_diff);
2555+
iq_set_tmp = SIGN(iq_set_tmp) * sqrtf(SQ(iq_set_tmp) - SQ(id_set_tmp));
2556+
}
25512557

25522558
// Apply current limits
25532559
// TODO: Consider D axis current for the input current as well.
@@ -3989,14 +3995,3 @@ static void terminal_plot_hfi(int argc, const char **argv) {
39893995
commands_printf("This command requires one argument.\n");
39903996
}
39913997
}
3992-
3993-
static void apply_mtpa(float *id, float *iq, volatile motor_all_state_t *motor) {
3994-
float ld_lq_diff = motor->m_conf->foc_motor_ld_lq_diff;
3995-
3996-
if(ld_lq_diff != 0.0){
3997-
float lambda = motor->m_conf->foc_motor_flux_linkage;
3998-
3999-
*id = (lambda - sqrtf(SQ(lambda) + 8.0 * SQ(ld_lq_diff) * SQ(*iq))) / (4.0 * ld_lq_diff);
4000-
*iq = SIGN(*iq) * sqrtf(SQ(*iq) - SQ(*id));
4001-
}
4002-
}

0 commit comments

Comments
 (0)