Merge branch 'master' into adm_res

This commit is contained in:
crinq
2015-09-11 04:32:58 +02:00
9 changed files with 51 additions and 37 deletions

3
.gitignore vendored
View File

@@ -8,9 +8,12 @@
*.log
*.net
*.raw
*.swp
.DS_Store
term/build
term/xbuild
new_term/build
new_term/xbuild
term/win32/bin
.depend
*.list

View File

@@ -4072,7 +4072,7 @@ design rules under a new name.</description>
<attribute name="NAME" x="16.75" y="19.25" size="0.5" layer="26" rot="MR180" align="center"/>
<attribute name="VALUE" x="16.865" y="22.155" size="1.27" layer="28" rot="MR180"/>
</element>
<element name="R19" library="rcl" package="R0603" value="330" x="29.5" y="22.5" smashed="yes" rot="MR90">
<element name="R19" library="rcl" package="R0603" value="470" x="29.5" y="22.5" smashed="yes" rot="MR90">
<attribute name="NAME" x="29.5" y="24.75" size="0.5" layer="26" rot="MR90" align="center"/>
<attribute name="VALUE" x="27.595" y="21.865" size="1.27" layer="28" rot="MR90"/>
</element>
@@ -4136,7 +4136,7 @@ design rules under a new name.</description>
<attribute name="NAME" x="16.75" y="9.25" size="0.5" layer="26" rot="MR180" align="center"/>
<attribute name="VALUE" x="16.865" y="12.155" size="1.27" layer="28" rot="MR180"/>
</element>
<element name="R26" library="rcl" package="R0603" value="330" x="28.125" y="22.5" smashed="yes" rot="MR90">
<element name="R26" library="rcl" package="R0603" value="470" x="28.125" y="22.5" smashed="yes" rot="MR90">
<attribute name="NAME" x="28.25" y="24.75" size="0.5" layer="26" rot="MR90" align="center"/>
<attribute name="VALUE" x="26.22" y="21.865" size="1.27" layer="28" rot="MR90"/>
</element>

View File

@@ -29114,7 +29114,7 @@ You are welcome to use this library for commercial purposes. For attribution, we
<part name="R15" library="rcl" deviceset="R-EU_" device="R0603" value="1k"/>
<part name="R16" library="rcl" deviceset="R-EU_" device="R0603" value="1k"/>
<part name="R17" library="rcl" deviceset="R-EU_" device="R0603" value="3.9k"/>
<part name="R19" library="rcl" deviceset="R-EU_" device="R0603" value="330"/>
<part name="R19" library="rcl" deviceset="R-EU_" device="R0603" value="470"/>
<part name="R21" library="rcl" deviceset="R-EU_" device="R0603" value="180"/>
<part name="R22" library="rcl" deviceset="R-EU_" device="R0603" value="3.9k"/>
<part name="C38" library="rcl" deviceset="C-EU" device="C0603" value="1n"/>
@@ -29130,7 +29130,7 @@ You are welcome to use this library for commercial purposes. For attribution, we
<part name="R20" library="rcl" deviceset="R-EU_" device="R0603" value="1k"/>
<part name="R24" library="rcl" deviceset="R-EU_" device="R0603" value="1k"/>
<part name="R25" library="rcl" deviceset="R-EU_" device="R0603" value="3.9k"/>
<part name="R26" library="rcl" deviceset="R-EU_" device="R0603" value="330"/>
<part name="R26" library="rcl" deviceset="R-EU_" device="R0603" value="470"/>
<part name="R27" library="rcl" deviceset="R-EU_" device="R0603" value="180"/>
<part name="R28" library="rcl" deviceset="R-EU_" device="R0603" value="3.9k"/>
<part name="C40" library="rcl" deviceset="C-EU" device="C0603" value="1n"/>

View File

@@ -1,5 +1,17 @@
COMP(adc);
#define AREF 3.3// analog reference voltage
#define ARES 4096.0// analog resolution, 12 bit
#define R15 1000.0
#define R22 3900.0
#define R21 180.0
#define R19 470.0
#define V_REF 5.0
#define INPUT_REF (V_REF * R21 / (R19 + R21))
#define INPUT_GAIN (R22 / R15 * R21 / (R19 + R21))
#define V_DIFF(ADC) ((ADC/ADC_ANZ/ARES*AREF-INPUT_REF)/INPUT_GAIN)
HAL_PIN(sin) = 0.0;
HAL_PIN(cos) = 0.0;
HAL_PIN(sin3) = 0.0;
@@ -17,8 +29,8 @@ HAL_PIN(tim2_oc) = 150.0;
HAL_PIN(tim2_rv) = 420.0;
RT(
uint32_t si[PID_WAVES];
uint32_t co[PID_WAVES];
float si[PID_WAVES];
float co[PID_WAVES];
uint32_t sc[PID_WAVES];
float s_o = PIN(sin_offset);
@@ -26,9 +38,6 @@ RT(
float s_g = PIN(sin_gain);
float c_g = PIN(cos_gain);
float s = 0.0;
float c = 0.0;
for(int i = 0; i < PID_WAVES; i++){
sc[i] = 0.0;
for(int j = 0; j < ADC_ANZ; j++){
@@ -45,29 +54,22 @@ RT(
si[i] = 0.0;
co[i] = 0.0;
si[i] = sc[i] & 0x0000ffff;
co[i] = sc[i] >> 16;
si[i] = s_g * V_DIFF((sc[i] & 0x0000ffff)) + s_o;
co[i] = c_g * V_DIFF((sc[i] >> 16)) + c_o;
}
s = s_g * (si[3] + s_o);
c = c_g * (co[3] + c_o);
PIN(sin3) = s;
PIN(cos3) = c;
PIN(sin3) = si[3];
PIN(cos3) = co[3];
if(PIN(res_en) > 0.0){
s = s_g * (0.5 * si[3] - 0.25 * si[2] + 0.125 * si[1] - 0.125 * si[0] + 0.25 * s_o);
c = c_g * (0.5 * co[3] - 0.25 * co[2] + 0.125 * co[1] - 0.125 * co[0] + 0.25 * c_o);
PIN(sin) = 0.5 * si[3] - 0.25 * si[2] + 0.125 * si[1] - 0.125 * si[0] + 0.25;
PIN(cos) = 0.5 * co[3] - 0.25 * co[2] + 0.125 * co[1] - 0.125 * co[0] + 0.25;
}
else{
s = s_g * (0.5 * si[3] + 0.25 * si[2] + 0.125 * si[1] + 0.125 * si[0] + s_o);
c = c_g * (0.5 * co[3] + 0.25 * co[2] + 0.125 * co[1] + 0.125 * co[0] + c_o);
PIN(sin) = 0.5 * si[3] + 0.25 * si[2] + 0.125 * si[1] + 0.125 * si[0];
PIN(cos) = 0.5 * co[3] + 0.25 * co[2] + 0.125 * co[1] + 0.125 * co[0];
}
PIN(sin) = s;
PIN(cos) = c;
);
ENDCOMP;

View File

@@ -29,6 +29,9 @@ HAL_PIN(kind) = 0.0;
HAL_PIN(id_error) = 0.0;
HAL_PIN(iq_error) = 0.0;
HAL_PIN(res) = 1200.0;
HAL_PIN(volt_res) = 0.0;
MEM(float id_error_sum) = 0.0;
MEM(float iq_error_sum) = 0.0;
@@ -37,6 +40,7 @@ RT(
float rq = MAX(PIN(rq), 0.1);
float ld = MAX(PIN(ld), 0.001);
float lq = MAX(PIN(lq), 0.001);
float volt_res = PIN(volt) / MAX(PIN(res), 1.0);
float volt = MAX(PIN(volt) * PIN(max_pwm) * 1.15, 0.1);
float ff = PIN(ff);
@@ -70,8 +74,12 @@ RT(
float ud = CLAMP(ff * rd * idc + kpd * id_error + kpd * kid * id_error_sum + kind * indd, -volt / 2.0, volt / 2.0);
float uq = CLAMP(ff * rq * iqc + kpq * iq_error + kpq * kiq * iq_error_sum + kind * indq, -volt / 2.0, volt / 2.0);
ud = ((int)(ud / volt_res)) * volt_res;
uq = ((int)(uq / volt_res)) * volt_res;
PIN(ud) = ud;
PIN(uq) = uq;
PIN(volt_res) = volt_res;
PIN(id_error) = id_error;
PIN(iq_error) = iq_error;

View File

@@ -74,13 +74,14 @@ RT(
float s = PIN(sin);
float c = PIN(cos);
float a = s * s + c * c;
float a = sqrtf(s * s + c * c);
PIN(amp) = a;
p = mod(TIM_GetCounter(ENC1_TIM) * 2.0f * M_PI / (float)e_res);
PIN(pos) = p;
if(a < 0.3 * 0.3){
if(a < 0.15){
PIN(error) = 1.0;
}
else{

View File

@@ -41,16 +41,16 @@ RT(
float indd = vel_e * psi_q;
float indq = vel_e * psi_d;
id += (ud - r * id - indd) / ld * period / 4.0;
id += (ud - r * id + indd) / ld * period / 4.0;
iq += (uq - r * iq - indq) / lq * period / 4.0;
id += (ud - r * id - indd) / ld * period / 4.0;
id += (ud - r * id + indd) / ld * period / 4.0;
iq += (uq - r * iq - indq) / lq * period / 4.0;
id += (ud - r * id - indd) / ld * period / 4.0;
id += (ud - r * id + indd) / ld * period / 4.0;
iq += (uq - r * iq - indq) / lq * period / 4.0;
id += (ud - r * id - indd) / ld * period / 4.0;
id += (ud - r * id + indd) / ld * period / 4.0;
iq += (uq - r * iq - indq) / lq * period / 4.0;
float t = 3.0 / 2.0 * p * (psi_m * iq + (ld - lq) * id * iq);

View File

@@ -713,10 +713,10 @@ void set_mitsubishi(){ // TODO
set_hal_pin("conf0.fb_rev", 0.0);
set_hal_pin("conf0.out_rev", 0.0);
set_hal_pin("conf0.fb_res", 16384.0);
set_hal_pin("conf0.r", 1.5);
set_hal_pin("conf0.r", 1.2); // 0.75, 1.2
set_hal_pin("conf0.l", 0.0025);
set_hal_pin("conf0.j", KGCM2(0.5));
set_hal_pin("conf0.psi", 0.34);
set_hal_pin("conf0.psi", 0.3); //0.3
set_hal_pin("conf0.pos_p", 50.0);
set_hal_pin("conf0.acc_p", 0.1);

View File

@@ -206,10 +206,10 @@ int main(void)
HAL_PIN(out_rev) = 0.0;
HAL_PIN(fb_res) = 1.0;
HAL_PIN(cmd_res) = 2000.0;
HAL_PIN(sin_offset) = -17600.0;
HAL_PIN(cos_offset) = -17661.0;
HAL_PIN(sin_gain) = 0.0001515;
HAL_PIN(cos_gain) = 0.00015;
HAL_PIN(sin_offset) = 0.0;
HAL_PIN(cos_offset) = 0.0;
HAL_PIN(sin_gain) = 1.0;
HAL_PIN(cos_gain) = 1.0;
HAL_PIN(max_dc_volt) = 370.0;
HAL_PIN(max_hv_temp) = 90.0;