UVW 3 phases Brushless DC motor control
Dependencies: QEI mbed-rtos mbed
Fork of DCmotor by
Diff: controller.h
- Revision:
- 13:791e20f1af43
- Parent:
- 12:a4b17bb682eb
--- a/controller.h Fri Dec 21 22:06:56 2012 +0000 +++ b/controller.h Sun Mar 03 09:09:34 2013 +0000 @@ -4,13 +4,9 @@ //#define PI 3.14159265358979 // def. of PI /*********** User setting for control parameters (begin) ***************/ #define SIMULATION // Comment this line if not simulation -#define PWM_FREQ 1000.0 //[Hz], pwm freq. (> 1/(DEAD_TIME*10)) -#define DEADTIME 0.0001 // [s], deadtime to be set between plus volt. to/from minus #define USE_CURRENT_CONTROL // Current control on. Comment if current control off. -#define CONTROL_MODE 0 // 0:PID control, 1:Frequency response, 2:Step response, 3. u=Rand to identify G(s), 4) FFT identification #define DEADZONE_PLUS 1. // deadzone of plus side #define DEADZONE_MINUS -1.5 // deadzone of minus side -#define GOOD_DATA // Comment this line if the length of data TMAX/TS2 > 1000 // encoder #define N_ENC (24*4) // "*4": QEI::X4_ENCODING. Number of pulses in one revolution(=360 deg) of rotary encoder. #define CH_A p29 // A phase port @@ -18,22 +14,27 @@ #define DA_PORT p18 // analog out (DA) port of mbed +#define PWM_FREQ 1000.0 //[Hz], pwm freq. (> 1/(DEAD_TIME*10)) +#define DEADTIME 0.0001 // [s], deadtime to be set between plus volt. to/from minus #define TS0 0.001//08//8 // [s], sampling time (priority highest: Ticker IRQ) of motor current i control PID using timer interrupt #define TS1 0.002//0.01 // [s], sampling time (priority high: RtosTimer) of motor angle th PID using rtos-timer #define TS2 0.2 // [s], sampling time (priority =main(): precision 4ms) to save data to PC using thread. But, max data length is 1000. #define TS3 0.002 // [s], sampling time (priority low: precision 4ms) -#define TS4 0.1 // [s], sampling time (priority lowest: precision 4ms) to display data to PC tera term +#define TS4 0.2 // [s], sampling time (priority lowest: precision 4ms) to display data to PC tera term //void timerTS1(void const *argument), CallTimerTS3(void const *argument), CallTimerTS4(void const *argument); // RtosTimer RtosTimerTS1(timerTS1); // RtosTimer priority is osPriorityAboveNormal, just one above main() // Thread ThreadTimerTS3(CallTimerTS3,NULL,osPriorityBelowNormal); // Thread ThreadTimerTS4(CallTimerTS4,NULL,osPriorityLow); #define TMAX 3.0 // [s], experiment starts from 0[s] to TMAX[s] +#define TMAX_FIND_ORIGIN 0.1//1.0 // [s], finding th origin starts from 0[s] to TMAX[s] // 電流制御マイナーループ #define iKPd 10./2 // 電流制御d軸PIDのPゲイン (d-axis) #define iKId 100./2 // 電流制御d軸PIDのIゲイン (d-axis) +#define iKDd 0 // 電流制御d軸PIDのDゲイン (d-axis) #define iKPq 10./2 // 電流制御q軸PIDのPゲイン (q-axis) #define iKIq 100./2 // 電流制御q軸PIDのIゲイン (q-axis) +#define iKDq 0 // 電流制御q軸PIDのDゲイン (q-axis) #define vdqMAX 300. #define SQRvdqMAX (vdqMAX*vdqMAX) // [V^2] vdqの大きさの最大値の二乗 @@ -42,15 +43,16 @@ #ifdef USE_CURRENT_CONTROL #define wKp 0.05 // 速度制御PIDのPゲイン #define wKi 2.50 // 速度制御PIDのIゲイン + #define wKd 0 // 速度制御PIDのDゲイン #else - #define wKp 0.005//0.05 // 速度制御PIDのPゲイン - #define wKi 0.2//2.50 // 速度制御PIDのIゲイン + #define wKp 0.005 // 速度制御PIDのPゲイン + #define wKi 0.2 // 速度制御PIDのIゲイン + #define wKd 0 // 速度制御PIDのDゲイン #endif #define iLPF 0.9 // 0-1, 速度に対する1次LPF; Low Pass Filter, G(z)=(1-a)/(z-a) #define iqMAX 100 // [A], q軸電流指令のMAX制限(異常に大きい指令値を制限する) -#define R_SHUNT 1.25 // [Ohm], shunt resistanse /*********** User setting for control parameters (end) ***************/ @@ -84,6 +86,7 @@ float idq_ref[2]; // idqの目標値 float vdq_ref[2]; // vdqの目標値 float eI_idq[2]; // 電流制御用偏差の積分値(積分項) + float e_old[2]; // 電流制御用偏差の1サンプル過去の値 }current_loop_parameters; typedef struct struct_velocity_loop_parameters{ @@ -92,7 +95,8 @@ float w_ref; // [rad/s], モータ目標速度 float tan_beta_ref; // [rad], モータ電流位相 float iq_ref; // q軸電流指令[A] - float eI_w; // 速度制御用偏差の積分値(積分項) + float eI; // 速度制御用偏差の積分値(積分項) + float e_old; // 速度制御用偏差の1サンプル過去の値 }velocity_loop_parameters; extern void timerTS0(); // timer called every TS0[s].