CAN总线控制步进电机驱动PI算法和PI参数调整的问题
本帖最后由 suxiaobo 于 2012-7-19 11:49 编辑最近使用使用dsPIC33FJ128MC804芯片做了一个CAN控制的步进电机驱动器,电机控制部分代码使用AN1307的范例代码。 但做出来的东西和商用驱动器差远了主要是运行噪音大 力矩比较小.不知道是PI参数没调整好还是算法不对。希望能得到大家的帮忙.
我的续流方式采用慢速续流D_SLOW_L_MOSFET
细分采用32细分
PWM频率:20kHz
相电流设定:1.8A
电机电阻:2.1欧姆
电机电感:4mH
电机相电流经电流采集电阻和运放放大后的信号直接送MCU的A/D波形如下
使用Microchip的电机调试工具得到的数据
DMCI显示的A(红线)相B(绿线)相电流
DMCI显示的B相实际电流(绿线)和B相参考电流(蓝线)
Microchip的步进电机应用文档里面的PI算法部分看不懂呀
比例系数有2个 PI_GAIN_1 和 PI_GAIN_2
//PI controller defines
//硬件部分定义
#define ADC_CURRENT_RANGE 6.6 //Value in Amps; maximum current the ADC input can read根据运放的放大倍数来算 如安原厂开发板式是0.75V每安 1.65V/0.75=2.2这里按我的电路修改
#define DC_BUS_RESISTOR 19.0 //Value in KOhms; 1:19 is the voltage divider scale in HW
#define ADC_VOLTAGE 3.3 //value in Volts; voltage used by the ADC as reference
//电机部分参数
#define MOTOR_R 2.1 //motor resistance in the configuration in which it's conected
#define MOTOR_L 0.004 //motorinductance
#define DC_BUS 24.0 //board power supply
#define PI_GAIN 1800 //PI gain value
#define PI_ANTI_WIND_UP_SCALE1300 //anti wind-up scale; Anti Wind-up value at low speeds 低速参数
#define PI_ANTI_WIND_UP_SCALE2600 //anti wind-up scale; Anti Wind-up value at high speeds 高速参数
#define PI_ANTI_WIND_UP_SPEED 1600 //speed at which the anti wind-up is changed; corresponds to 336RPM 高低速分界线
这里主要是当电机的速度小与 PI_ANTI_WIND_UP_SPEED定义值时 PI_antiWindUp=PI_ANTI_WIND_UP_SCALE1
反之电机速度大与 PI_ANTI_WIND_UP_SPEED定义值时 PI_antiWindUp=PI_ANTI_WIND_UP_SCALE2
#define PI_PARAM_1 ((MOTOR_L+MOTOR_T*MOTOR_R/2)*ADC_CURRENT_RANGE*32768/DC_BUS_RESISTOR /ADC_VOLTAGE)
#define PI_PARAM_2 ((MOTOR_L-MOTOR_T*MOTOR_R/2)*ADC_CURRENT_RANGE*32768/DC_BUS_RESISTOR /ADC_VOLTAGE)
//80V = max voltage on Board
#define PI_GAIN_1 (int)(PI_GAIN*PI_PARAM_1)
#define PI_GAIN_2 (int)(PI_GAIN*PI_PARAM_2)
PI算法部分代码 currentReference 为参考电流 currentMeasurement为A/D采集的实际电流
/******************************************************************************
* Function: CalcPI1(int currentReference,int currentMeasurement)
*
* Output: PI_out1
*
* Overview: This function implements PI control for Winding 1 current
* The discrete PI controller has the following format:
* PI_PARAM_1 * z - PI_PARAM_2
* H(z) = PI_GAIN * ---------------------------
* z - 1
*
* Note: None
*******************************************************************************/
int CalcPI1(int currentReference,int currentMeasurement)
{
long currentError;
//calculate the current currentErroror
currentError = (((long)currentReference - currentMeasurement));
//calculate the controller equation, including anti wind-up
PI_sum1 = PI_sum1+((currentError * PI_GAIN_1 - PI_err1 * PI_GAIN_2)>>13)-(((PI_sum1-PI_out1) * PI_antiWindUp)>>15);
//limit the controller output to the available drive voltage
if(PI_sum1 > dcBus)
PI_out1 = dcBus;
else if(PI_sum1 < -dcBus)
PI_out1 = -dcBus;
else
PI_out1 = (int)PI_sum1;
//resonance compensation active only in full step at slow speeds
if(resonanceCompensation == ON)
{
PI_out1 = PI_out1>>2; //reduce output magnitude to allow more time for slow decay
}
PI_err1 = currentError; //save the error for use in the next cycle
return PI_out1; //controller voltage output
}
另外说是硬件上和商业驱动器的区别
1.MCU 商用驱动器使用的是MC56F8036 我使用的是dsPIC33FJ128MC804 应该处理能力上相差不大
2.MOSFET 商用驱动器使用的是IRFU39100.115欧姆 输入电容640PF 我使用的是IRFU34100.039欧姆 输入电容1690PF 2A左右的应用选择IRFU3910是不是要好些呀,毕竟输入电容小驱动容易些
3.MOSFET驱动IC 商用驱动器使用的是FAN7080 驱动电流IO+ 300IO- 600 我使用的是:FAN7384 驱动电流IO+ 250IO- 500 驱动电流要小一些而MOSFET的输入电容又要大一些会不会对电路有引响
页:
[1]