v4.0 working

This commit is contained in:
crinq
2017-01-19 01:38:53 +01:00
parent 432835dfac
commit d5db466ec3
11 changed files with 116 additions and 94 deletions

View File

@@ -91,7 +91,7 @@ LDSCRIPT = stm32_flash.ld
#============================================================================
OBJECTS += $(addprefix $(OBJDIR)/,$(addsuffix .o,$(basename $(SOURCES))))
OBJECTS += hv_firmware.o
# OBJECTS += hv_firmware.o
CPPFLAGS += $(addprefix -I,$(INCDIRS))
#---------------- Preprocessor Options ----------------
@@ -171,7 +171,7 @@ LDFLAGS += $(CPU)
# Default target
#
all: hv gccversion boot build showsize
all: gccversion boot build showsize
build: elf hex bin lss sym
@@ -213,12 +213,12 @@ showsize: build
# Flash the device
#
btburn: hv build showsize $(TARGET).dfu
btburn: build showsize $(TARGET).dfu
@tools/bootloader.py
@sleep 1
@dfu-util -d 0483:df11 -a 0 -s 0x08010000:leave -D $(TARGET).dfu
flash: hv $(TARGET).bin
flash: $(TARGET).bin
st-flash --reset write $(TARGET).bin 0x08010000
# Create a DFU file from bin file
@@ -230,7 +230,7 @@ flash: hv $(TARGET).bin
#
clean:
@echo Cleaning project:
rm -rf hv_firmware.o
# rm -rf hv_firmware.o
rm -rf $(OBJDIR)
@$(MAKE) -f bootloader/Makefile clean
@$(MAKE) -f stm32f103/Makefile clean

View File

@@ -7,8 +7,8 @@ conf0.mot_type = 0.000000
conf0.out_rev = 0.000000
conf0.high_motor_temp = 80.000000
conf0.max_motor_temp = 100.000000
conf0.phase_time = 0.500000
conf0.phase_cur = 2.000000
conf0.phase_time = 0.700000
conf0.phase_cur = 3.000000
conf0.max_vel = 800.000000
conf0.max_acc = 100000.000000
conf0.max_force = 11.760000
@@ -41,11 +41,11 @@ conf0.high_hv_temp = 70.000000
conf0.fan_hv_temp = 60.000000
conf0.fan_core_temp = 450.000000
conf0.fan_motor_temp = 60.000000
conf0.p = 0.990000
conf0.g = 0.990000
conf0.pos_p = 150.000000
conf0.vel_p = 1.000000
conf0.acc_p = 0.200000
conf0.acc_pi = 100.000000
conf0.vel_p = 1000.000000
conf0.vel_i = 5.000000
conf0.vel_g = 1.000000
conf0.cur_p = 0.500000
conf0.cur_i = 0.000000
conf0.cur_ff = 1.000000

View File

@@ -24,9 +24,10 @@ typedef struct{
//data from f1 to f4
#pragma pack(1)
typedef struct{
int16_t dc_cur;
int16_t dc_volt;
int16_t hv_temp;
float id;
float iq;
float dc_volt;
float hv_temp;
uint8_t high_volt : 1;//hardware hi limit
uint8_t low_volt : 1;//hardware low limit
uint8_t over_cur : 1;//hardware cur limit

View File

@@ -84,8 +84,9 @@ FRT(
PIN(pos) = p;
//TODO: this gets triggered by wire saving abs encoders. add timeout?
if(RISING_EDGE(!GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_11)) && PIN(isabs) != 1.0){
absoffset = -p;
PIN(isabs) = 1.0;
// TODO: fix
//absoffset = -p;
//PIN(isabs) = 1.0;
}
PIN(abspos) = mod(p + absoffset);
);

View File

@@ -58,6 +58,7 @@ HAL_PIN(mot_fan) = 0.0;
HAL_PIN(phase_with_brake) = 1.0;
HAL_PIN(phase_on_start) = 1.0;
HAL_PIN(rephase) = 0.0;
HAL_PIN(print) = 0.0;
@@ -77,6 +78,9 @@ RT(
switch(state){
case DISABLED:
if(RISING_EDGE(PIN(en)) & (PIN(cmd_ready) > 0.0) & (PIN(fb0_ready) > 0.0) & (PIN(fb1_ready) > 0.0) & (PIN(hv_ready) > 0.0)){
if(PIN(rephase) > 0.0){ // TODO: check phase_on_start
phased = 0;
}
if(phased == 0){
state = PHASING;
}

View File

@@ -1,23 +1,25 @@
HAL_COMP(hv);
HAL_PIN(a) = 0.0;
HAL_PIN(b) = 0.0;
HAL_PIN(d) = 0.0;
HAL_PIN(q) = 0.0;
HAL_PIN(pos) = 0.0;
HAL_PIN(mode) = 0.0;
HAL_PIN(id) = 0.0;
HAL_PIN(iq) = 0.0;
HAL_PIN(enable) = 0.0;
HAL_PIN(error) = 0.0;
HAL_PIN(over_cur);
HAL_PIN(over_temp);
HAL_PIN(hv_fault);
HAL_PIN(dc_cur) = 0.0;
HAL_PIN(dc_volt) = 0.0;
HAL_PIN(pwm_volt) = 0.0;
HAL_PIN(hv_temp) = 0.0;
HAL_PIN(power) = 0.0;
HAL_PIN(dc_cur_sim) = 0.0;
HAL_PIN(ac_cur_sim) = 0.0;
HAL_PIN(iq) = 0.0;
HAL_PIN(polecount) = 1.0;
HAL_PIN(rev) = 0.0;
@@ -123,12 +125,15 @@ INIT(
RT(
float e = PIN(enable);
float p = (int)MAX(PIN(polecount), 1.0);
float pos = mod(PIN(pos) * p);
if(packet_from_hv.head.start == 255){
unbuff_packet((packet_header_t*)&packet_from_hv, sizeof(from_hv_t));
packet_from_hv.head.start = 0;
PIN(dc_cur) = TOFLOAT(packet_from_hv.data.dc_cur)*0.5 + PIN(dc_cur)*0.5;
PIN(dc_volt) = TOFLOAT(packet_from_hv.data.dc_volt);
PIN(id) = packet_from_hv.data.id;
PIN(iq) = packet_from_hv.data.iq;
PIN(dc_volt) = packet_from_hv.data.dc_volt;
if(PIN(mode) == 0){//AC
PIN(pwm_volt) = PIN(dc_volt) / 2.0 * 0.95 * 1.15;
}else if(PIN(mode) == 1){//DC
@@ -138,7 +143,7 @@ RT(
}else{
PIN(pwm_volt) = 0.0;
}
PIN(hv_temp) = TOFLOAT(packet_from_hv.data.hv_temp);
PIN(hv_temp) = packet_from_hv.data.hv_temp;
PIN(over_cur) = packet_from_hv.data.over_cur;//hardware cur limit
PIN(over_temp) = packet_from_hv.data.over_temp;//hardware temp limit
PIN(hv_fault) = packet_from_hv.data.hv_fault;//iramx fault
@@ -154,22 +159,24 @@ RT(
PIN(error) = 1.0;
}
float a = PIN(a);
float b = PIN(b);
float d = PIN(d);
float q = PIN(q);
if(PIN(rev) > 0.0){//TODO: rev DC
b *= -1.0;
q *= -1.0;
}
packet_to_hv.data.mode = CLAMP(PIN(mode),0,16);
if(e > 0.0){
packet_to_hv.data.a = a;
packet_to_hv.data.b = b;
packet_to_hv.data.d = d;
packet_to_hv.data.q = q;
packet_to_hv.data.pos = pos;
packet_to_hv.data.enable = 1;
}
else{
packet_to_hv.data.a = 0;
packet_to_hv.data.b = 0;
packet_to_hv.data.d = 0.0;
packet_to_hv.data.q = 0.0;
packet_to_hv.data.pos = pos;
packet_to_hv.data.enable = 0;
}
buff_packet((packet_header_t*)&packet_to_hv, sizeof(to_hv_t));
@@ -184,13 +191,13 @@ RT(
DMA_ClearFlag(UART_DRV_RX_DMA, UART_DRV_RX_DMA_TCIF);
DMA_Cmd(UART_DRV_RX_DMA, ENABLE);
PIN(power) = PIN(dc_cur) * PIN(dc_volt);
if(PIN(pwm_volt) > 0.0){
PIN(dc_cur_sim) = ABS(PIN(iq)) / PIN(pwm_volt) * sqrtf(a*a + b*b)*0.5 + PIN(dc_cur_sim)*0.5;
}
if(ABS(a*b) > 0.01){
PIN(ac_cur_sim) = PIN(dc_cur) / sqrtf(a*a+b*b) * PIN(pwm_volt);
}
// PIN(power) = PIN(dc_cur) * PIN(dc_volt);
// if(PIN(pwm_volt) > 0.0){
// PIN(dc_cur_sim) = ABS(PIN(iq)) / PIN(pwm_volt) * sqrtf(a*a + b*b)*0.5 + PIN(dc_cur_sim)*0.5;
// }
// if(ABS(a*b) > 0.01){
// PIN(ac_cur_sim) = PIN(dc_cur) / sqrtf(a*a+b*b) * PIN(pwm_volt);
// }
);
ENDCOMP;

View File

@@ -71,14 +71,14 @@ NRT(
void about(){
//hv firmware. defined by the linker script
extern const char _binary_obj_hv_hv_bin_start;
extern const char _binary_obj_hv_hv_bin_size;
extern const char _binary_obj_hv_hv_bin_end;
// extern const char _binary_obj_hv_hv_bin_start;
// extern const char _binary_obj_hv_hv_bin_size;
// extern const char _binary_obj_hv_hv_bin_end;
//version info of bootloader
volatile const struct version_info* bt_version_info = (void*)0x08000188;
//version info of embedded hv firmware
volatile const struct version_info* hv_version_info = (void*)(&_binary_obj_hv_hv_bin_start + 0x10c);
// volatile const struct version_info* hv_version_info = (void*)(&_binary_obj_hv_hv_bin_start + 0x10c);
printf("######## software info ########\n");
print_version_info(&version_info);
@@ -98,9 +98,9 @@ NRT(
printf("######## Bootloader info ########\n");
print_version_info(bt_version_info);
printf("######## HV info ########\n");
printf("hv: start:%p ,size:%p ,end%p \n",&_binary_obj_hv_hv_bin_start,&_binary_obj_hv_hv_bin_size,&_binary_obj_hv_hv_bin_end);
print_version_info(hv_version_info);
// printf("######## HV info ########\n");
// printf("hv: start:%p ,size:%p ,end%p \n",&_binary_obj_hv_hv_bin_start,&_binary_obj_hv_hv_bin_size,&_binary_obj_hv_hv_bin_end);
// print_version_info(hv_version_info);
}
void sysinfo(){

View File

@@ -3,45 +3,51 @@
void link_ac(){
hal_set_pin("t2c0.rt_prio", 9.0);
hal_set_pin("curpid0.rt_prio", 10.0);
hal_set_pin("pmsm0.rt_prio", 11.0);
// hal_set_pin("curpid0.rt_prio", 10.0);
// hal_set_pin("pmsm0.rt_prio", 11.0);
hal_set_pin("pmsm_limits0.rt_prio", 12.0);
hal_set_pin("idq0.rt_prio", 13.0);
hal_set_pin("dq0.rt_prio", 14.1);
// hal_set_pin("idq0.rt_prio", 13.0);
// hal_set_pin("dq0.rt_prio", 14.1);
hal_set_pin("i2t0.rt_prio", 15.0);
// t2c
hal_link_pins("conf0.polecount", "t2c0.polecount");
hal_link_pins("conf0.psi", "t2c0.psi");
hal_link_pins("t2c0.cur", "hv0.q");
hal_link_pins("cauto0.i_d", "hv0.d");
hal_link_pins("cauto0.pos", "hv0.pos");
hal_link_pins("conf0.polecount", "hv0.polecount");
hal_link_pins("pid0.torque_cor_cmd", "vel1.torque");
// curpid
hal_link_pins("cauto0.i_d", "curpid0.id_cmd");
hal_link_pins("t2c0.cur", "curpid0.iq_cmd");
hal_link_pins("hv0.dc_volt", "curpid0.dc_volt");
hal_link_pins("hv0.pwm_volt", "curpid0.ac_volt");
hal_link_pins("conf0.r", "curpid0.rd");
hal_link_pins("conf0.r", "curpid0.rq");
hal_link_pins("conf0.l", "curpid0.ld");
hal_link_pins("conf0.l", "curpid0.lq");
hal_link_pins("conf0.cur_ff", "curpid0.ff");
hal_link_pins("conf0.cur_p", "curpid0.kp");
hal_link_pins("conf0.cur_i", "curpid0.ki");
hal_link_pins("conf0.cur_ind", "curpid0.kind");
// hal_link_pins("cauto0.i_d", "curpid0.id_cmd");
// hal_link_pins("t2c0.cur", "curpid0.iq_cmd");
// hal_link_pins("hv0.dc_volt", "curpid0.dc_volt");
// hal_link_pins("hv0.pwm_volt", "curpid0.ac_volt");
// hal_link_pins("conf0.r", "curpid0.rd");
// hal_link_pins("conf0.r", "curpid0.rq");
// hal_link_pins("conf0.l", "curpid0.ld");
// hal_link_pins("conf0.l", "curpid0.lq");
// hal_link_pins("conf0.cur_ff", "curpid0.ff");
// hal_link_pins("conf0.cur_p", "curpid0.kp");
// hal_link_pins("conf0.cur_i", "curpid0.ki");
// hal_link_pins("conf0.cur_ind", "curpid0.kind");
// pmsm
hal_link_pins("curpid0.ud", "pmsm0.ud");
hal_link_pins("curpid0.uq", "pmsm0.uq");
hal_link_pins("net0.fb_d", "pmsm0.vel");
hal_link_pins("conf0.r", "pmsm0.r");
hal_link_pins("conf0.l", "pmsm0.ld");
hal_link_pins("conf0.l", "pmsm0.lq");
hal_link_pins("conf0.psi", "pmsm0.psi");
hal_link_pins("pmsm0.id", "curpid0.id_fb");
hal_link_pins("pmsm0.iq", "curpid0.iq_fb");
hal_link_pins("pmsm0.indd", "curpid0.indd_fb");
hal_link_pins("pmsm0.indq", "curpid0.indq_fb");
hal_link_pins("conf0.polecount", "pmsm0.polecount");
hal_link_pins("pmsm0.iq", "hv0.iq");
// hal_link_pins("curpid0.ud", "pmsm0.ud");
// hal_link_pins("curpid0.uq", "pmsm0.uq");
// hal_link_pins("net0.fb_d", "pmsm0.vel");
// hal_link_pins("conf0.r", "pmsm0.r");
// hal_link_pins("conf0.l", "pmsm0.ld");
// hal_link_pins("conf0.l", "pmsm0.lq");
// hal_link_pins("conf0.psi", "pmsm0.psi");
// hal_link_pins("pmsm0.id", "curpid0.id_fb");
// hal_link_pins("pmsm0.iq", "curpid0.iq_fb");
// hal_link_pins("pmsm0.indd", "curpid0.indd_fb");
// hal_link_pins("pmsm0.indq", "curpid0.indq_fb");
// hal_link_pins("conf0.polecount", "pmsm0.polecount");
// hal_link_pins("pmsm0.iq", "hv0.iq");
// pmsm_limits
hal_link_pins("conf0.r", "pmsm_limits0.r");
@@ -189,7 +195,7 @@ void link_pid(){
// misc
hal_link_pins("conf0.out_rev", "hv0.rev");
hal_link_pins("cauto0.pos", "idq0.pos");
// hal_link_pins("cauto0.pos", "idq0.pos");
hal_link_pins("conf0.cmd_res", "sim0.res");
// term

View File

@@ -206,11 +206,11 @@ int main(void)
#include "comps/ypid.comp"
#include "comps/pid.comp"
#include "comps/pmsm_t2c.comp"
#include "comps/curpid.comp"
#include "comps/pmsm.comp"
//#include "comps/curpid.comp"
//#include "comps/pmsm.comp"
#include "comps/pmsm_limits.comp"
#include "comps/idq.comp"
#include "comps/dq.comp"
//#include "comps/idq.comp"
//#include "comps/dq.comp"
#include "comps/hv.comp"
//other comps

View File

@@ -18,16 +18,15 @@ HAL_PIN(dc_volt) = 0.0;
HAL_PIN(pwm_volt) = 0.0;
HAL_PIN(hv_temp) = 0.0;
HAL_PIN(ia) = 0.0;
HAL_PIN(ib) = 0.0;
HAL_PIN(id) = 0.0;
HAL_PIN(iq) = 0.0;
MEM(packet_to_hv_t packet_to_hv);
MEM(packet_from_hv_t packet_from_hv);
MEM(uint32_t timeout) = 99999;
MEM(volatile uint8_t rxbuf[128]);
MEM(volatile uint8_t txbuf[20]);
MEM(volatile uint8_t rxbuf[sizeof(packet_to_hv) * 2]);
MEM(uint32_t rxpos) = 0;//UART rx buffer position
MEM(int32_t datapos) = -1;
@@ -106,9 +105,10 @@ RT(
if(buf == 255){ //start condition
datapos = 0;
((uint8_t*)&packet_to_hv)[datapos++] = (uint8_t)buf;
packet_from_hv.data.dc_volt = TOFIXED(PIN(dc_volt));
packet_from_hv.data.dc_cur = TOFIXED(0.0f);
packet_from_hv.data.hv_temp = TOFIXED(PIN(hv_temp));
packet_from_hv.data.dc_volt = PIN(dc_volt);
packet_from_hv.data.id = PIN(id);
packet_from_hv.data.iq = PIN(iq);
packet_from_hv.data.hv_temp = PIN(hv_temp);
buff_packet((packet_header_t*)&packet_from_hv, sizeof(from_hv_t));
DMA1_Channel2->CCR &= (uint16_t)(~DMA_CCR_EN);
DMA1_Channel2->CNDTR = sizeof(packet_from_hv);

View File

@@ -281,7 +281,7 @@ int main(void)
hal_set_comp_type("foo"); // default pin for mem errors
HAL_PIN(bar) = 0.0;
#include "../src/comps/sim.comp"
// #include "../src/comps/sim.comp"
#include "comps/term.comp"
#include "../src/comps/idq.comp"
#include "../src/comps/dq.comp"
@@ -319,7 +319,7 @@ int main(void)
//hal_set_pin("iclarke0.rt_prio", 3.0);
//hal_set_pin("clarke0.rt_prio", 3.1);
hal_set_pin("term0.rt_prio", 0.1);
hal_set_pin("sim0.rt_prio", 0.5);
// hal_set_pin("sim0.rt_prio", 0.5);
hal_set_pin("ls0.rt_prio", 0.6);
hal_set_pin("io0.rt_prio", 1.0);
hal_set_pin("dq0.rt_prio", 2.0);
@@ -345,7 +345,7 @@ int main(void)
hal_link_pins("ls0.d", "curpid0.id_cmd");
hal_link_pins("ls0.q", "curpid0.iq_cmd");
hal_link_pins("ls0.pos", "idq0.pos");
hal_link_pins("ls0.b", "dq0.pos");
hal_link_pins("ls0.pos", "dq0.pos");
hal_link_pins("ls0.en", "hv0.en");
//ADC TEST
@@ -354,10 +354,10 @@ int main(void)
hal_link_pins("io0.iu", "dq0.u");
hal_link_pins("io0.iv", "dq0.v");
hal_link_pins("io0.iw", "dq0.w");
hal_link_pins("clarke0.y", "term0.wave4");
// hal_link_pins("clarke0.y", "term0.wave4");
hal_link_pins("sim0.vel", "idq0.pos");
hal_link_pins("sim0.vel", "dq0.pos");
// hal_link_pins("sim0.vel", "idq0.pos");
// hal_link_pins("sim0.vel", "dq0.pos");
hal_link_pins("idq0.u", "svm0.u");
hal_link_pins("idq0.v", "svm0.v");
@@ -371,6 +371,9 @@ int main(void)
hal_link_pins("dq0.d", "curpid0.id_fb");
hal_link_pins("dq0.q", "curpid0.iq_fb");
hal_link_pins("dq0.d", "ls0.id");
hal_link_pins("dq0.q", "ls0.iq");
hal_link_pins("curpid0.ud", "idq0.d");
hal_link_pins("curpid0.uq", "idq0.q");
@@ -385,7 +388,7 @@ int main(void)
hal_comp_init();//call init function of all comps
if(hal.pin_errors + hal.comp_errors == 0){
//hal_start();
hal_start();
}
else{
hal.hal_state = MEM_ERROR;