adc pwm fix, curpid gains

This commit is contained in:
crinq
2017-10-05 00:54:07 +02:00
parent d65a72df75
commit 8d3d7bbfda
3 changed files with 27 additions and 22 deletions

View File

@@ -1,5 +1,5 @@
//stmbl
#define AREF 3.338 // analog reference voltage
#define AREF 3.3 // analog reference voltage
#define VDIVUP 20000.0 * 2.0 //HV div pullup R1,R12
#define VDIVDOWN 1000.0 //HV div pulldown R2,R9

View File

@@ -162,28 +162,27 @@ static void rt_func(float period, volatile void *ctx_ptr, volatile hal_pin_inst_
in1 += adc_12_buf[2 * i].in1 + adc_12_buf[2 * i + 1].in1;
bemf0 += adc_12_buf[2 * i].bemf0 + adc_12_buf[2 * i + 1].bemf0;
bemf1 += adc_12_buf[2 * i].bemf1 + adc_12_buf[2 * i + 1].bemf1;
ian += adc_34_buf[2 * i].shunt_a0 + adc_34_buf[2 * i].shunt_a1 + adc_34_buf[2 * i].shunt_a2 + adc_34_buf[2 * i].shunt_a3;
iap += adc_34_buf[2 * i + 1].shunt_a0 + adc_34_buf[2 * i + 1].shunt_a1 + adc_34_buf[2 * i + 1].shunt_a2 + adc_34_buf[2 * i + 1].shunt_a3;
ibn += adc_34_buf[2 * i].shunt_b0 + adc_34_buf[2 * i].shunt_b1 + adc_34_buf[2 * i].shunt_b2 + adc_34_buf[2 * i].shunt_b3;
ibp += adc_34_buf[2 * i + 1].shunt_b0 + adc_34_buf[2 * i + 1].shunt_b1 + adc_34_buf[2 * i + 1].shunt_b2 + adc_34_buf[2 * i + 1].shunt_b3;
in += adc_12_buf[2 * i].shunt_low0 + adc_12_buf[2 * i].shunt_low1;
ip += adc_12_buf[2 * i + 1].shunt_low0 + adc_12_buf[2 * i + 1].shunt_low1;
ian += adc_34_buf[2 * i].shunt_a0;// + adc_34_buf[2 * i].shunt_a1 + adc_34_buf[2 * i].shunt_a2 + adc_34_buf[2 * i].shunt_a3;
iap += adc_34_buf[2 * i + 1].shunt_a0;// + adc_34_buf[2 * i + 1].shunt_a1 + adc_34_buf[2 * i + 1].shunt_a2 + adc_34_buf[2 * i + 1].shunt_a3;
ibn += adc_34_buf[2 * i].shunt_b0;// + adc_34_buf[2 * i].shunt_b1 + adc_34_buf[2 * i].shunt_b2 + adc_34_buf[2 * i].shunt_b3;
ibp += adc_34_buf[2 * i + 1].shunt_b0;// + adc_34_buf[2 * i + 1].shunt_b1 + adc_34_buf[2 * i + 1].shunt_b2 + adc_34_buf[2 * i + 1].shunt_b3;
in += adc_12_buf[2 * i].shunt_low0;// + adc_12_buf[2 * i].shunt_low1;
ip += adc_12_buf[2 * i + 1].shunt_low0;// + adc_12_buf[2 * i + 1].shunt_low1;
}
PIN(hv_temp) = r2temp(HV_R(ADC(hv_temp / 20.0)));//258.0 - hv_temp * 3.3 / ARES * 114.4 * ADC_OVER / ADC_COUNT;
PIN(hv_temp) = r2temp(HV_R(ADC(hv_temp * ADC_OVER / ADC_COUNT)));
PIN(dc_link) = dc_link * 3.3 / ARES * (20.0 + 1.0) / 1.0 * ADC_OVER / ADC_COUNT;
PIN(bemf0) = bemf0 * 3.3 / ARES * (20.0 + 1.0) / 1.0 * ADC_OVER / ADC_COUNT;
PIN(bemf1) = bemf1 * 3.3 / ARES * (20.0 + 1.0) / 1.0 * ADC_OVER / ADC_COUNT;
PIN(in0) = in0 * 3.3 / ARES * (10.0 + 1.5) / 1.5 * ADC_OVER / ADC_COUNT;
PIN(in1) = in1 * 3.3 / ARES * (10.0 + 1.5) / 1.5 * ADC_OVER / ADC_COUNT;
PIN(iap) = AMP(iap * 2.0 * ADC_OVER / ADC_COUNT / 4.0, 8.0);
PIN(ian) = AMP(ian * 2.0 * ADC_OVER / ADC_COUNT / 4.0, 8.0);
PIN(ibp) = AMP(ibp * 2.0 * ADC_OVER / ADC_COUNT / 4.0, 8.0);
PIN(ibn) = AMP(ibn * 2.0 * ADC_OVER / ADC_COUNT / 4.0, 8.0);
PIN(ip) = ip * 2.0 * ADC_OVER / ADC_COUNT / 2.0 * 3.3 / ARES;
PIN(in) = in * 2.0 * ADC_OVER / ADC_COUNT / 2.0 * 3.3 / ARES;
PIN(iap) = AMP(iap * 2.0 * ADC_OVER / ADC_COUNT / 1.0, 8.0);
PIN(ian) = AMP(ian * 2.0 * ADC_OVER / ADC_COUNT / 1.0, 8.0);
PIN(ibp) = AMP(ibp * 2.0 * ADC_OVER / ADC_COUNT / 1.0, 8.0);
PIN(ibn) = AMP(ibn * 2.0 * ADC_OVER / ADC_COUNT / 1.0, 8.0);
PIN(ip) = ip * ADC_OVER / ADC_COUNT * 3.3 / ARES;
PIN(in) = in * ADC_OVER / ADC_COUNT * 3.3 / ARES;
PIN(ia) = PIN(iap) - PIN(ian);
PIN(ib) = PIN(ibp) - PIN(ibn);

View File

@@ -359,6 +359,7 @@ int main(void) {
load_comp(comp_by_name("vel"));
load_comp(comp_by_name("vel"));
load_comp(comp_by_name("ypid"));
load_comp(comp_by_name("trc"));
load_comp(comp_by_name("hv"));
load_comp(comp_by_name("curpid"));
@@ -370,6 +371,7 @@ int main(void) {
hal_parse("pole0.rt_prio = 4.0");
hal_parse("dq0.rt_prio = 5.0");
hal_parse("ypid0.rt_prio = 6.0");
hal_parse("trc0.rt_prio = 6.5");
hal_parse("curpid0.rt_prio = 7.0");
hal_parse("idq0.rt_prio = 8.0");
hal_parse("hv0.rt_prio = 9.0");
@@ -404,11 +406,11 @@ int main(void) {
hal_parse("curpid0.ld = 0.0038");
hal_parse("curpid0.lq = 0.0038");
hal_parse("curpid0.psi = 0.005");
hal_parse("curpid0.kp = 0.1");
hal_parse("curpid0.ki = 0.0001");
hal_parse("curpid0.kp = 0.6");
hal_parse("curpid0.ki = 0.0002");
hal_parse("curpid0.ff = 1");
hal_parse("curpid0.kind = 0");
hal_parse("curpid0.max_cur = 3.5");
hal_parse("curpid0.max_cur = 4");
hal_parse("curpid0.pwm_volt = io0.dc_link");
hal_parse("pole0.p = 50.0");
@@ -426,10 +428,14 @@ int main(void) {
hal_parse("ypid0.pos_fb = map0.pos_out2");
hal_parse("ypid0.vel_fb = vel1.vel");
hal_parse("curpid0.iq_cmd = ypid0.out");
hal_parse("ypid0.max_vel = 30");
hal_parse("ypid0.max_acc = 200000");
hal_parse("ypid0.max_out = 3.5");
// hal_parse("trc0.in = ypid0.out");
// hal_parse("curpid0.iq_cmd = trc0.out");
// hal_parse("trc0.pos = map0.pos_out2");
// hal_parse("trc0.mult = 200");
hal_parse("ypid0.max_vel = 50");
hal_parse("ypid0.max_acc = 10000");
hal_parse("ypid0.max_out = 4");
hal_parse("ypid0.pos_p = 100");
hal_parse("ypid0.vel_p = 0.1");
hal_parse("ypid0.vel_i = 0.05");