From 7ad0175e31d445a5c84730bca2dbb0ca66b596c3 Mon Sep 17 00:00:00 2001 From: crinq Date: Sun, 23 Feb 2020 18:39:20 +0100 Subject: [PATCH] wire saving --- conf/template/en.txt | 6 ++++++ conf/template/encws_fb0.txt | 4 ++++ conf/template/uvw_fb0.txt | 14 ++++++++++++++ shared/comps/uvw.c | 24 ++++++++++++++---------- src/comps/adc.c | 4 ++-- 5 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 conf/template/en.txt create mode 100644 conf/template/encws_fb0.txt create mode 100644 conf/template/uvw_fb0.txt diff --git a/conf/template/en.txt b/conf/template/en.txt new file mode 100644 index 00000000..6f902baf --- /dev/null +++ b/conf/template/en.txt @@ -0,0 +1,6 @@ +load en +en0.rt_prio = 2 +en0.en_in = 1 +fault0.en = en0.en_out0 +en0.fault = fault0.fault +en0.time = 1 \ No newline at end of file diff --git a/conf/template/encws_fb0.txt b/conf/template/encws_fb0.txt new file mode 100644 index 00000000..ae5595b2 --- /dev/null +++ b/conf/template/encws_fb0.txt @@ -0,0 +1,4 @@ +link enc_fb0 +link uvw_fb0 +uvw0.mode = 1 +enc_fb0.en_index = 0 diff --git a/conf/template/uvw_fb0.txt b/conf/template/uvw_fb0.txt new file mode 100644 index 00000000..9e51e195 --- /dev/null +++ b/conf/template/uvw_fb0.txt @@ -0,0 +1,14 @@ +load uvw +uvw0.rt_prio = 3 +uvw0.u = io0.fb0a +uvw0.v = io0.fb0b +uvw0.w = io0.fb0z + +uvw0.amp = adc0.amp0 + +fb_switch0.com_pos = uvw0.pos +fb_switch0.com_abs_pos = uvw0.pos +fb_switch0.com_state = uvw0.state +fb_switch0.com_polecount = conf0.com_fb_polecount +conf0.com_fb_polecount = conf0.polecount +fault0.com_fb_error = uvw0.error \ No newline at end of file diff --git a/shared/comps/uvw.c b/shared/comps/uvw.c index 53675c13..9fb600a7 100644 --- a/shared/comps/uvw.c +++ b/shared/comps/uvw.c @@ -45,7 +45,7 @@ static void nrt_init(void *ctx_ptr, hal_pin_inst_t *pin_ptr) { PIN(p5) = 5; //u + w = -1.047198 PIN(p6) = 3; //v + w = -3.141593 PIN(p7) = -1; //fault - PIN(en_time) = 0.02; + PIN(en_time) = 0.01; } static void rt_func(float period, void *ctx_ptr, hal_pin_inst_t *pin_ptr) { @@ -65,7 +65,7 @@ static void rt_func(float period, void *ctx_ptr, hal_pin_inst_t *pin_ptr) { t[6] = PIN(p6); t[7] = PIN(p7); PIN(rpos) = rpos; - if(rpos < 0 | PIN(amp) < 0.5){ + if(PIN(amp) < 0.75){ PIN(error) = 1.0; PIN(state) = 0.0; PIN(timer) = 0.0; @@ -73,20 +73,24 @@ static void rt_func(float period, void *ctx_ptr, hal_pin_inst_t *pin_ptr) { else{ switch((int) PIN(mode)){ case 0: - PIN(state) = 3.0; - PIN(error) = 0.0; - PIN(pos) = mod((float)t[rpos] / 6.0 * 2.0 * M_PI); + if(t[rpos] < 0.0){ + PIN(state) = 3.0; + PIN(error) = 0.0; + PIN(pos) = mod((float)t[rpos] / 6.0 * 2.0 * M_PI); + } + else{ + PIN(error) = 1.0; + PIN(state) = 0.0; + } break; case 1: if(PIN(timer) < PIN(en_time) / 2.0){ PIN(pos) = mod((float)t[rpos] / 6.0 * 2.0 * M_PI); - } - if(PIN(timer) > PIN(en_time)){ - PIN(state) = 2.0; - PIN(error) = 0.0; + PIN(timer) += period; } else{ - PIN(timer) += period; + PIN(state) = 2.0; + PIN(error) = 0.0; } } } diff --git a/src/comps/adc.c b/src/comps/adc.c index 584d56ff..6684f46e 100644 --- a/src/comps/adc.c +++ b/src/comps/adc.c @@ -143,7 +143,7 @@ static void rt_func(float period, void *ctx_ptr, hal_pin_inst_t *pin_ptr) { PIN(cos0l) = co0[ADC_GROUPS - 1]; PIN(sin0) = sin0all / (float)ADC_GROUPS; PIN(cos0) = cos0all / (float)ADC_GROUPS; - PIN(amp0) = PIN(amp0) * 0.99 + sqrtf(s * s + c * c) * 0.01; + PIN(amp0) = PIN(amp0) * 0.9 + sqrtf(s * s + c * c) * 0.1; #ifdef FB1 s = V_DIFF(ADC_DMA_Buffer[ADC_OVER_FB0] & 0x0000ffff, 1); c = V_DIFF(ADC_DMA_Buffer[ADC_OVER_FB0] >> 16, 1); @@ -151,7 +151,7 @@ static void rt_func(float period, void *ctx_ptr, hal_pin_inst_t *pin_ptr) { PIN(cos1l) = co1[ADC_GROUPS - 1]; PIN(sin1) = sin1all / (float)ADC_GROUPS; PIN(cos1) = cos1all / (float)ADC_GROUPS; - PIN(amp1) = PIN(amp1) * 0.99 + sqrtf(s * s + c * c) * 0.01; + PIN(amp1) = PIN(amp1) * 0.9 + sqrtf(s * s + c * c) * 0.1; #endif // if(PIN(res_en) > 0.0) {