akiyoshi oguro
/
Vector_SVPWM_drive_F302R8
Vector SVPWM Drive SPMSM
Diff: main.cpp
- Revision:
- 1:74d7a989b741
- Parent:
- 0:866aafac0128
- Child:
- 2:0058dae8606d
--- a/main.cpp Tue Apr 02 04:38:25 2019 +0000 +++ b/main.cpp Sat Jun 01 03:13:36 2019 +0000 @@ -1,8 +1,8 @@ - #include "mbed.h" +#include "mbed.h" #include "rtos.h" #define TS1 0.2 #include <math.h> -int q=0,START=10,i=0,r=0,s=0; +int q=0,START=15,i=0,r=0,s=0; float uii=0,ut=0,ut1=0,ut2=0,usi=0; float vii=0,vt=0,vt1=0,vt2=0,vsi=0; float wii=0,wt=0,wt1=0,wt2=0,wsi=0; @@ -13,7 +13,6 @@ float vst=0,vstt=0,vsti=0,vstf=0,Edw=0,PI=3.141592; float Speed; float Wnon,Ednon,W,PLL; -float uti,vti,wti; PwmOut mypwmA(PA_8); //PWM_OUT 8 PwmOut mypwmB(PA_9); //9 PwmOut mypwmC(PA_10);//10 @@ -25,8 +24,6 @@ DigitalOut EN2(PC_11); DigitalOut EN3(PC_12); -DigitalOut vcl(PC_8); - InterruptIn HA(PA_15); InterruptIn HB(PB_3); InterruptIn HC(PB_10); @@ -35,9 +32,9 @@ AnalogIn V_adc(PC_2); // Gaibu Potention -/*AnalogIn Vshuntu(PA_0); -AnalogIn Vshuntv(PC_1); -AnalogIn Vshuntw(PC_0);*/ +AnalogIn Vshuntu(PA_1); +AnalogIn Vshuntv(PA_0); +AnalogIn Vshuntw(PB_0); AnalogIn BEMF1(PC_3);//C7_37 AnalogIn BEMF2(PB_0);//C7_34 @@ -46,14 +43,13 @@ DigitalIn GPIO_BEMF(PC_9); DigitalIn CPOUT(PA_12); - AnalogIn Curr_ui(PA_0); AnalogIn Curr_vi(PC_1); AnalogIn Curr_wi(PC_0); //PA_1 Timer uT; Timer vT; Timer wT; -AnalogOut SWAVE(PA_4); +//AnalogOut SWAVE(PA_4); Serial pc(USBTX,USBRX); @@ -73,17 +69,17 @@ float Idin,Vdout,Iqin,Vqout,Xsi; int vstctle=0,vstctlz=0; float Vr_adc=0.0f,iso=0,Vqp;; -int adc,vtv=1; +int adc; float therr,dth,eth,phm; float sq32=sqrt(3.0f/2.0f); float sq23=2.0f/sqrt(3.0f); float sq3=1.0f/sqrt(3.0f); -float Vdlink=0.6; //3.0f/5.0f; 0.45 +float Vdlink=0.5; //3.0f/5.0f; float aVa; float a3Vb; -float z=0.5;//0.7 +float z=0.7;//0.7 float Va,Vb; float d1,d2,d3,d4,d5,d6,d07; float du,dv,dw; @@ -95,36 +91,30 @@ ut1=uT.read_us(); ut=0; ui=0; - } void HAL(){ ut2=uT.read_us(); uT.reset(); - ui=0; } void HBH(){ vt1=vT.read_us(); vi=0; - } void HBL(){ vt2=vT.read_us(); vT.reset(); - } void HCH(){ wt1=wT.read_us(); wi=0; et=0; - } void HCL(){ wt2=wT.read_us(); wT.reset(); - } void CPLT(){ @@ -144,7 +134,7 @@ EN2=1; EN3=1; - mypwmA.period_us(20); //20 + mypwmA.period_us(20); mypwmB.period_us(20); @@ -182,8 +172,6 @@ mypwmB.write(0.0); mypwmC.write(0.5f); wait_ms(START); - - q++; } @@ -196,9 +184,7 @@ HA.fall(&HAL); HC.rise(&HCH); HB.fall(&HBL); - - - Speed=60*(1/(7.0*2.0*usi*1E-6)); + Speed=60*(1/(7.0*2.0*wsi*1E-6)); if(Vr_adc < 0.08f){ q=0; @@ -213,100 +199,92 @@ vi=vi+1; wi=wi+1; et=et+1; - - uti=fabs(ut1-ut2)/float(ui)*1E-6; - vti=fabs(vt1-vt2)/float(vi)*1E-6; - wti=fabs(wt1-wt2)/float(wi)*1E-6; - //pc.printf("%.3f %.3f %.3f \r\n", uti, vti, wti); - //pc.printf(" %d \r\n",ui); - thu=2*PI*(1/(2*usi*1E-6))*ui*1.3E-4; //usi 1.3E-4 vst - thv=2*PI*(1/(2*vsi*1E-6))*vi*1.3E-4; - thw=2*PI*(1/(2*wsi*1E-6))*wi*1.3E-4; - + + thu=2*PI*(1/(2*usi*1E-6))*ui*2.30E-4; //usi 1.3E-4 vst + thv=2*PI*(1/(2*vsi*1E-6))*vi*2.30E-4; + thw=2*PI*(1/(2*wsi*1E-6))*wi*2.30E-4; + //th=(thu+thv+thw)/3; if(r==0){ thave=(thu+thv+thw)/3; th=thu; - + //th=thave; s=0; } if(r==1){ - if((Speed > 1000)&&(Speed <=1500)){ iso=-0.3; - Vqp=0.3*Vq; - Vdlink=0.3; - + Vqp=0.2*Vq; //0.8 + Vdlink=0.4; + Edw=3500; z=0.7; } if((Speed > 1500)&&(Speed <=2000)){ iso=0.7; - Vqp=0.3*Vq; - Vdlink=0.3; - + Vqp=0.2*Vq; //0.7 + Vdlink=0.45; + Edw=3600; z=0.7; } if((Speed > 2000)&&(Speed <=3000)){ iso=0.8; - Vqp=0.3*Vq; - Vdlink=0.35; - + Vqp=0.2*Vq; //0.3 + Vdlink=0.5; + Edw=3700; z=0.7; } if((Speed > 3000)&&(Speed <=4000)){ - iso=1.2; - Vqp=0.4*Vq; - Vdlink=0.5; - + iso=1.2; //1.2 + Vqp=0.3*Vq; //0.3 + Vdlink=0.5; //0.5 + Edw=3700; //3700 z=0.7; } if((Speed > 4000)&&(Speed <=5000)){ - iso=1.8; - Vqp=0.5*Vq; - Vdlink=0.5; - + iso=1.8; //1.8 + Vqp=0.3*Vq; //0.3 + Vdlink=0.6; //0.6 + Edw=3800; //3800 z=0.7; } if((Speed > 5000)&&(Speed <=5500)){ - iso=2.2; - Vqp=0.5*Vq; - Vdlink=0.5; - - z=0.8; + iso=2.2; //2.2 + Vqp=0.3*Vq; //0.3 + Vdlink=0.5; //0.7 + Edw=3900; //3900 + z=0.7; //0.66 } if((Speed > 5500)&&(Speed <=6000)){ - iso=2.8; - Vqp=0.7*Vq; - Vdlink=0.6; - - z=0.9; + iso=2.8; //2.2 + Vqp=1.0*Vq; //0.35 + Vdlink=0.5; //0.8 + Edw=6000; //6000 + z=0.8; //0.7 } if((Speed > 6000)){ - iso=3.2; - Vqp=0.7*Vq; - Vdlink=0.9; - - z=0.95; + iso=2.2; //2.2 + Vqp=1.0*Vq; // 0.4 + Vdlink=0.5; //0.9 + Edw=7000;//7000 + z=0.8; //0.8 } - - - // th=(W*et*1.9E-4)+iso; //1.9E-4 - // th=(W*et*7.0E-4)+iso; //5.0E-4 +iso 1.9 - // th=Wo*wi*1.85E-4; + // th=(Wz*et*1.9E-4)+iso; //1.99E-4 + th=(W*et*1.9E-4)+iso; + // th=Wo*wi*1.85E-4; } if(r==0){ - su=(sin(thu)+0.2);//-0.2f; // p51 0.5 - sv=(sin(thv)+0.2);//-0.05f; - sw=(sin(thw)+0.2);//-0.05f;//-0.7 + su=sin(thu);//-0.2f; // p51 0.5 + sv=sin(thv);//-0.05f; + sw=sin(thw);//-0.05f;//-0.7 - mypwmA.write(su*Vr_adc); - mypwmB.write(sv*Vr_adc); - mypwmC.write(sw*Vr_adc); + mypwmA.write(su*Vr_adc); //kaisha sv ier su + mypwmB.write(sv*Vr_adc); //kaisha sw ie sv + mypwmC.write(sw*Vr_adc); //kaisha su ie sw } if(r==1){ - mypwmA.write(du); - mypwmB.write(dv); - mypwmC.write(dw); + mypwmA.write(du); // dw ie no white and Black + mypwmB.write(dv); // du + mypwmC.write(dw); // dv } @@ -314,10 +292,12 @@ // } // } - Curr_u=(Curr_ui); - Curr_v=(Curr_vi); - Curr_w=(Curr_wi); - + Curr_u=(Curr_ui);//0.33f; kaisha v w u narabikae + Curr_v=(Curr_vi);///0.33f; + Curr_w=(Curr_wi);///0.33f; + /* iuvw[0]=(Curr_ui); + iuvw[1]=(Curr_vi); + iuvw[2]=(Curr_wi);*/ float Itau=1.0E-6,Idt=1.0E-6; // Itau=1.0E-6,Idt=1.0E-6; /****Filter Iu********/ float Iu1,Iu2,Iu3,Iu4;//0.01 @@ -343,14 +323,13 @@ Iw4=Idt*(Curr_w-(iuvw[2]+Iw3/2.0))/Itau; iuvw[2]=iuvw[2]+(Iw1+2.0*Iw2+2.0*Iw3+Iw4)/6.0; /*************************************/ - - + iab[0]=(iuvw[0]+iuvw[1]*cos23+iuvw[2]*cos43)*zet; iab[1]=(iuvw[1]*sin23+iuvw[2]*sin43)*zet; - idq[0]=cos(th)*iab[0]+sin(th)*iab[1]+0.5; //thave - idq[1]=-sin(th)*iab[0]+cos(th)*iab[1]+0.5; //th + idq[0]=cos(th)*iab[0]+sin(th)*iab[1]; //thave + idq[1]=-sin(th)*iab[0]+cos(th)*iab[1]; //th /****Filter Id********/ @@ -374,11 +353,17 @@ Iq4=Iqdt*(idqi[1]-(idqo[1]+Iq3/2.0))/Iqtau; idq[1]=idqo[1]+(Iq1+2.0*Iq2+2.0*Iq3+Iq4)/6.0; /*************************************/ - + + // Wcom=(2*PI)/(vstf*1E-6); + + + // Vd=(idq[0]);//tmp vdq + // Vq=(idq[1]);//tmp vdq + /*****PID Id *****/ - Idin=(-0.25)-idq[0]; + Idin=(-0.25)-idq[0]; // -0.2 float adi,bdi,cdi,workdi[2]; - float kpdi=1.0,kidi=0.5,kddi=0.0; + float kpdi=1.0,kidi=0.5,kddi=0.0; //p51 0.5 1.2 0.0 float dtdi=1.0E-6;//1E-6 adi=Idin; bdi=workdi[1]+(Idin+workdi[0])/2.0*dtdi; @@ -387,9 +372,9 @@ workdi[1]=bdi; Vd=adi*kpdi+bdi*kidi+cdi*kddi; /**********************************/ - + //Icom=0.5; /*****PID Iq *****/ - Iqin=Vr_adc-idq[1]; + Iqin=Vr_adc-idq[1]; //kaisha 600 ie 500 float aqi,bqi,cqi,workqi[2]; float kpqi=2.0,kiqi=1.2,kdqi=0.0; // 1.5 0.8 float dtqi=1.0E-6;//1E-2 @@ -400,7 +385,16 @@ workdi[1]=bqi; Vq=aqi*kpqi+bqi*kiqi+cqi*kdqi; /**********************************/ - + /****Filter Vq********/ + /*float Vq1,Vq2,Vq3,Vq4;//0.01 + float Vqtau= 1.0E-6,Vqdt=1.0E-6; + Vq1=Vqdt*(Vqi-Vq)/Vqtau; + Vq2=Vqdt*(Vqi-(Vq+Vq1/2.0))/Vqtau; + Vq3=Vqdt*(Vqi-(Vq+Vq2/2.0))/Vqtau; + Vq4=Vqdt*(Vqi-(Vq+Vq3/2.0))/Vqtau; + Vq=Vq+(Vq1+2.0*Vq2+2.0*Vq3+Vq4)/6.0;*/ + /*************************************/ + //Vq=Vr_adc; //if(i<10000){ //if(r==0){ usi=ut2-ut1; @@ -417,11 +411,22 @@ vst=vstf; i=10000; - // } // r=i%100; // i++; + // Vd=(idq[0]);//tmp vdq + // Vq=(idq[1]);//tmp vdq + + + /* Ed= (Vd)-0.11f*idq[0]+Wz*0.018E-3*idq[1];//0.018 + + if(Ed>=0){ + Wz=(2*PI)/((vst+Edw*Ed*0.2)*1E-6);// 0.2 + } + else{ + Wz=(2*PI)/((vst-Edw*Ed*0.2)*1E-6); //0.45 + } */ Wz=(2*PI)/(vst*1E-6); //vst Ed= (Vq)-0.11f*idq[1]-Wz*0.018E-3*idq[0];//0.018E-3 @@ -430,9 +435,11 @@ eth=asin(dth); /*****PID θ *****/ - - PLL=4.0; - //float WPLL=150.0; + // PLL=(Speed/100); //7 21 28 + //PLL=Speed*2*PI/(60*28); + // PLL=W/Wz; + PLL=1.0; //30 + //float WPLL=150.0; // 170 float as,bs,cs,works[2]; float kps=PLL,kis=PLL*PLL/5.0,kds=0.0; float dts=1.0E-6; @@ -452,21 +459,29 @@ } /*****PID ω *****/ - Xin=5500*(1.07-Vr_adc)-vstf; // 5500 1.05 + Xin=5500*(1.05-Vr_adc)-vst; // 5500 float a,b,c,work[2]; float kp=2.0,ki=0.5,kd=0.0; // 1.2 0.7 - float dt=1.0E-6;//10.0E-6 + float dt=10.0E-6;//1E-6 a=Xin; b=work[1]+(Xin+work[0])/2.0*dt; c=(Xin-work[0])/dt; work[0]=Xin; work[1]=b; Xout=a*kp+b*ki+c*kd; - + /**********************************/ + // float dtt=1000.0E-6; + + /*float k1,k2,k3,k4,tau=0.001;//0.01 + k1=dtt*(Xout-vstt)/tau; + k2=dtt*(Xout-(vstt+k1/2.0))/tau; + k3=dtt*(Xout-(vstt+k2/2.0))/tau; + k4=dtt*(Xout-(vstt+k3/2.0))/tau; + vstt=vstt+(k1+2.0*k2+2.0*k3+k4)/6.0;*/ vstt=Xout; /********************************/ if(2000>abs(vst-vstt)){ // ie 1000 - vsti=vstf; + vsti=vstt; // vsti=vst; r=1; } @@ -476,8 +491,8 @@ }*/ /****Filter********/ float vstfo=vstf; - float dttt=10.0E-6;//100E-6 - float k11,k22,k33,k44,tau1=0.01;//0.01 + float dttt=100.0E-6;//100E-6 + float k11,k22,k33,k44,tau1=0.1;//0.01 k11=dttt*(vsti-vstfo)/tau1; k22=dttt*(vsti-(vstfo+k11/2.0))/tau1; k33=dttt*(vsti-(vstfo+k22/2.0))/tau1; @@ -489,31 +504,38 @@ }//else kokomade - + /* if((Vr_adc > 0.9f)&&(Vr_adc <= 0.95f)){ + vstf =800.0f; + } + if((Vr_adc > 0.95f)&&(Vr_adc < 0.975f)){ + vstf=700.0f; + } + if(Vr_adc >= 0.975f){ + vstf=600.0f; + } */ + - Va=cos(th)*Vd-sin(th)*Vq; //Vqp - Vb=sin(th)*Vd+cos(th)*Vq; //Vqp + Va=cos(th)*Vd-sin(th)*Vqp; //Vqp 負荷小 Vq*0.8~1.0負荷大 + Vb=sin(th)*Vd+cos(th)*Vqp; //Vqp aVa=abs(Va); a3Vb=abs(sq3*Vb); - if((Va>=0)&&(Vb>=0)&&(aVa>=a3Vb)){ //sect 0 + + if((Va>=0)&&(Vb>=0)&&(aVa>=a3Vb)){ //sect 0 d1=sq32*(Va-sq3*Vb)*Vdlink; d2=sq32*(sq23*Vb)*Vdlink; - d07=(z-(d1+d2))*0.5; - // d07=0; + d07=z-(d1+d2); du=d1+d2+d07; dv=d2+d07; dw=d07; - } if((aVa<=sq3*Vb)){ //sect 1 d3=sq32*(-Va+sq3*Vb)*Vdlink; d2=sq32*(Va+sq3*Vb)*Vdlink; - d07=(z-(d2+d3))*0.5; - //d07=0; + d07=z-(d2+d3); du=d2+d07; dv=d2+d3+d07; dw=d07; @@ -523,10 +545,9 @@ d3=sq32*sq23*Vb*Vdlink; d4=sq32*(-Va-sq3*Vb)*Vdlink; - d07=(z-(d3+d4))*0.5; - // d07=0; + d07=z-(d3+d4); du=d07; - dv=d3+d4+d07; + dv=d3+d2+d07; dw=d4+d07; } @@ -534,8 +555,7 @@ d5=-sq32*sq23*Vb*Vdlink; d4=sq32*(-Va+sq3*Vb)*Vdlink; - d07=(z-(d4+d5))*0.5; - //d07=0; + d07=z-(d4+d5); du=d07; dv=d4+d07; dw=d4+d5+d07; @@ -545,8 +565,7 @@ d5=sq32*(-Va-sq3*Vb)*Vdlink;; d6=sq32*(Va-sq3*Vb)*Vdlink; - d07=(z-(d5+d6))*0.5; - //d07=0; + d07=z-(d5+d6); du=d6+d07; dv=d07; dw=d5+d6+d07; @@ -556,14 +575,20 @@ d1=sq32*(Va+sq3*Vb)*Vdlink;; d6=-sq32*sq23*Vb*Vdlink;; - d07=(z-(d1+d6))*0.5; - //d07=0; + d07=z-(d1+d6); du=d1+d6+d07; dv=d07; dw=d6+d07; } - - + + /* mypwmA.write(du); + mypwmB.write(dv); + mypwmC.write(dw);*/ + + + /* suv=Vab[0]*zet; + svv=(Vab[0]*cos23+Vab[1]*sin23)*zet; + swv=(Vab[0]*cos43+Vab[1]*sin43)*zet;*/ // SWAVE=Vd; // SWAVE=th/4; @@ -578,8 +603,7 @@ // SWAVE=sin(th); // SWAVE=vst/5000; //SWAVE=Vb; - //SWAVE=iuvw[0]; - SWAVE=su; + // SWAVE=iuvw[0]; Vector=r; i++; }