CCW CW Control BLDC

Dependencies:   mbed mbed-rtos

Committer:
oguro
Date:
Sun Feb 17 02:58:08 2019 +0000
Revision:
0:faa58403944a
Child:
1:333d2cdd26d0
CCW/CW Control  Kukei seigen HA

Who changed what in which revision?

UserRevisionLine numberNew contents of line
oguro 0:faa58403944a 1 Serial pc(USBTX,USBRX);
oguro 0:faa58403944a 2
oguro 0:faa58403944a 3 PwmOut PWM_IN1_U(PA_8);
oguro 0:faa58403944a 4 PwmOut PWM_IN2_V(PA_9);
oguro 0:faa58403944a 5 PwmOut PWM_IN3_W(PA_10);
oguro 0:faa58403944a 6
oguro 0:faa58403944a 7 DigitalOut EN1_U(PC_10);
oguro 0:faa58403944a 8 DigitalOut EN2_V(PC_11);
oguro 0:faa58403944a 9 DigitalOut EN3_W(PC_12);
oguro 0:faa58403944a 10
oguro 0:faa58403944a 11 DigitalIn HALL_U(PA_15);
oguro 0:faa58403944a 12 DigitalIn HALL_V(PB_3);
oguro 0:faa58403944a 13 DigitalIn HALL_W(PB_10);
oguro 0:faa58403944a 14
oguro 0:faa58403944a 15 /*DigitalIn HALL_U(PC_8);
oguro 0:faa58403944a 16 DigitalIn HALL_V(PC_6);
oguro 0:faa58403944a 17 DigitalIn HALL_W(PC_10);*/
oguro 0:faa58403944a 18
oguro 0:faa58403944a 19
oguro 0:faa58403944a 20 /*InterruptIn HALL_Ui(PC_8);
oguro 0:faa58403944a 21 InterruptIn HALL_Vi(PC_6);
oguro 0:faa58403944a 22 InterruptIn HALL_Wi(PC_5);*/
oguro 0:faa58403944a 23
oguro 0:faa58403944a 24 InterruptIn HALL_Ui(PA_15);
oguro 0:faa58403944a 25 InterruptIn HALL_Vi(PB_3);
oguro 0:faa58403944a 26 InterruptIn HALL_Wi(PB_10);
oguro 0:faa58403944a 27
oguro 0:faa58403944a 28 AnalogIn V_adc(PC_2); // gaibu Volume
oguro 0:faa58403944a 29 //AnalogIn V_adc(PB_1); //On Board Volume
oguro 0:faa58403944a 30 AnalogIn Curr_ui(PA_0);
oguro 0:faa58403944a 31 AnalogIn Curr_vi(PC_1);
oguro 0:faa58403944a 32 AnalogIn Curr_wi(PC_0);
oguro 0:faa58403944a 33
oguro 0:faa58403944a 34 AnalogOut aout(PA_4);
oguro 0:faa58403944a 35
oguro 0:faa58403944a 36 float Vr_adc,Vr_adc_i;
oguro 0:faa58403944a 37
oguro 0:faa58403944a 38 unsigned short SH,frd=1,q;
oguro 0:faa58403944a 39 short f1=0,a1=0,f1c=0,a1c=0;
oguro 0:faa58403944a 40 float kido=0.5,START=10.0,STOP=1.0,power;
oguro 0:faa58403944a 41 float y,ay,Speed;
oguro 0:faa58403944a 42
oguro 0:faa58403944a 43 float ut1=0,ut2=0,usi=0;
oguro 0:faa58403944a 44 float vt1=0,vt2=0,vsi=0;
oguro 0:faa58403944a 45 float wt1=0,wt2=0,wsi=0;
oguro 0:faa58403944a 46 float ut1c=0,ut2c=0,usic=0;
oguro 0:faa58403944a 47
oguro 0:faa58403944a 48 float tau=50; //drone 50
oguro 0:faa58403944a 49 float zint=tau*1E-6;
oguro 0:faa58403944a 50
oguro 0:faa58403944a 51 Timer uT;
oguro 0:faa58403944a 52 Timer vT;
oguro 0:faa58403944a 53 Timer wT;
oguro 0:faa58403944a 54 Timer uTc;
oguro 0:faa58403944a 55
oguro 0:faa58403944a 56 Ticker zt;
oguro 0:faa58403944a 57 Ticker ztc;
oguro 0:faa58403944a 58 Ticker cnt;
oguro 0:faa58403944a 59
oguro 0:faa58403944a 60 float Curr_u=0,Curr_uf=0,iu;
oguro 0:faa58403944a 61 float Curr_v=0,Curr_vf=0,iv;
oguro 0:faa58403944a 62 float Curr_w=0,Curr_wf=0,iw;
oguro 0:faa58403944a 63
oguro 0:faa58403944a 64 short uz[5]={0x7FFF,0xC000,0,0x0001,0};//a1,a2,f0,f1,f2
oguro 0:faa58403944a 65 short vz[5]={0x7FFF,0xC000,0,0x0001,0};//a1,a2,f0,f1,f2
oguro 0:faa58403944a 66 short wz[5]={0x7FFF,0xC000,0,0x0001,0};//a1,a2,f0,f1,f2
oguro 0:faa58403944a 67
oguro 0:faa58403944a 68 short uc[5]={0x7FFF,0xC000,0,0x0001,0};//a1,a2,f0,f1,f2
oguro 0:faa58403944a 69
oguro 0:faa58403944a 70 float PI=3.141592;
oguro 0:faa58403944a 71 float ia=0,iaf=0,ib=0,ibf=0,iq=0,iqf=0,id=0,idf=0;
oguro 0:faa58403944a 72 float th;
oguro 0:faa58403944a 73
oguro 0:faa58403944a 74 float zet=sqrt(2.0f/3.0f),cos23=cos((2.0f/3.0f)*PI);
oguro 0:faa58403944a 75 float cos43=cos((4.0f/3.0f)*PI),sin23=sin((2.0f/3.0f)*PI),sin43=sin((4.0f/3.0f)*PI);
oguro 0:faa58403944a 76
oguro 0:faa58403944a 77 float sinth,costh;
oguro 0:faa58403944a 78 float id_diff,id_p,iq_diff,iq_p;
oguro 0:faa58403944a 79 float s_ki_id, ki_id,kp_id, s_ki_iq ,ki_iq,kp_iq;
oguro 0:faa58403944a 80
oguro 0:faa58403944a 81 float Vd,Vq;
oguro 0:faa58403944a 82 float Wz,s_ki_errth,s_kp_errth,derrth;
oguro 0:faa58403944a 83 float therr,dth,eth,phm;
oguro 0:faa58403944a 84 float sq32=sqrt(3.0f/2.0f);
oguro 0:faa58403944a 85 float sq23=2.0f/sqrt(3.0f);
oguro 0:faa58403944a 86 float sq3=1.0f/sqrt(3.0f);
oguro 0:faa58403944a 87 float Vdlink=0.6; //3.0f/5.0f; 0.45
oguro 0:faa58403944a 88 float aVa;
oguro 0:faa58403944a 89 float a3Vb;
oguro 0:faa58403944a 90
oguro 0:faa58403944a 91 float W,Ed;
oguro 0:faa58403944a 92 float errth,vst;
oguro 0:faa58403944a 93
oguro 0:faa58403944a 94 float z=0.5;//0.7
oguro 0:faa58403944a 95 float Va,Vb;
oguro 0:faa58403944a 96 float d1,d2,d3,d4,d5,d6,d07;
oguro 0:faa58403944a 97 float du,dv,dw;
oguro 0:faa58403944a 98