use SVM in square wave test

This commit is contained in:
Oskar Weigl
2016-11-20 14:23:13 +09:00
parent f22af031c0
commit 94c2b384d6
3 changed files with 47 additions and 28 deletions
+6 -6
View File
@@ -132,23 +132,23 @@ OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
vpath %.s $(sort $(dir $(ASM_SOURCES)))
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
@$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
$(AS) -c $(CFLAGS) $< -o $@
@$(AS) -c $(CFLAGS) $< -o $@
$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
$(CC) $(OBJECTS) $(LDFLAGS) -o $@
@$(CC) $(OBJECTS) $(LDFLAGS) -o $@
$(SZ) $@
$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(HEX) $< $@
@$(HEX) $< $@
$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(BIN) $< $@
@$(BIN) $< $@
$(BUILD_DIR):
mkdir -p $@
mkdir -p $@
#######################################
# clean up
+26 -21
View File
@@ -7,7 +7,7 @@
#include <adc.h>
#include <tim.h>
#include <spi.h>
#include <utils.h>
// Global variables
Motor_t motors[] = {
@@ -246,10 +246,29 @@ void mark_timing() {
timings[idx] = htim1.Instance->CNT;
}
float measure_phase_resistance(Motor_t* motor) {
void wait_for_current_meas(osMailQId queue, float* phB_current, float* phC_current) {
//Current measurements not occurring in a timely manner can be handled by the watchdog
//@TODO Actually make watchdog
//Hence we can use osWaitForever
osEvent evt = osMailGet(M0_Iph_queue, osWaitForever);
//Since we wait forever, we do not expect timeouts here.
safe_assert(evt.status == osEventMail);
//Fetch current out of the mail queue
Iph_BC_queue_item_t* mail_ptr = evt.value.p;
*phB_current = mail_ptr->current_phB;
*phC_current = mail_ptr->current_phC;
osMailFree(M0_Iph_queue, mail_ptr);
}
float measure_phase_resistance(Motor_t* motor, float test_current) {
static const float kI = 0.1f; //[(V/s)/A]
}
//Set the rising edge timings (0.0 - 1.0)
void set_timings(Motor_t* motor, float tA, float tB, float tC) {
TIM_TypeDef* tim = motor->timer_handle->Instance;
@@ -275,21 +294,8 @@ void motor_thread(void const * argument) {
for (int i = 0; i < num_test; ++i) {
for (int rep = 0; rep < 10000; ++rep) {
//Current measurements not occurring in a timely manner can be handled by the watchdog
//@TODO Actually make watchdog
//Hence we can use osWaitForever
osEvent evt = osMailGet(M0_Iph_queue, osWaitForever);
mark_timing();
//Since we wait forever, we do not expect timeouts here.
safe_assert(evt.status == osEventMail);
//Fetch current out of the mail queue
Iph_BC_queue_item_t* mail_ptr = evt.value.p;
float M0_phB_current = mail_ptr->current_phB;
float M0_phC_current = mail_ptr->current_phC;
osMailFree(M0_Iph_queue, mail_ptr);
float M0_phB_current, M0_phC_current;
wait_for_current_meas(M0_Iph_queue, &M0_phB_current, &M0_phC_current);
test_currentsB[i] += M0_phB_current;
test_currentsC[i] += M0_phC_current;
@@ -297,12 +303,11 @@ void motor_thread(void const * argument) {
float DC_bus_voltage = 12.0f;
float mod = test_voltages[i]/DC_bus_voltage;
float dmod = mod/2.0f;
float tA, tB, tC;
//Test voltage along phase A
set_timings(&motors[0], 0.5f - dmod, 0.5f + dmod, 0.5f + dmod);
mark_timing();
SVM(mod, 0.0f, &tA, &tB, &tC);
set_timings(&motors[0], tA, tB, tC);
}
}
}
+15 -1
View File
@@ -1,6 +1,9 @@
#include <utils.h>
static const float one_by_sqrt3 = 0.57735026919f;
static const float two_by_sqrt3 = 1.15470053838f;
int SVM(float alpha, float beta, float* tA, float* tB, float* tC) {
int Sextant;
@@ -110,9 +113,20 @@ int SVM(float alpha, float beta, float* tA, float* tB, float* tC) {
// PWM timings
*tA = (1.0f - t6 - t1) * 0.5f;
*tC = *tA + t1;
*tB = tC + t6;
*tB = *tC + t6;
break;
}
}
int retval = 0;
if (
*tA < 0.0f
|| *tA > 1.0f
|| *tB < 0.0f
|| *tB > 1.0f
|| *tC < 0.0f
|| *tC > 1.0f
) retval = -1;
return retval;
}