|
|
@@ -16,7 +16,7 @@
|
|
|
#define CCW (1)
|
|
|
|
|
|
// 基准电压
|
|
|
-#define VREF3_0 (0xA0)
|
|
|
+#define VREF3_0 (0xA0)
|
|
|
#define VREF4_0 (0xB0)
|
|
|
#define VREF4_5 (0xC0)
|
|
|
#define VREF5_0 (0xD0)
|
|
|
@@ -28,7 +28,7 @@
|
|
|
#define UP_L_DOWN_H (0xD0)
|
|
|
|
|
|
// 电流采样模式
|
|
|
-#define Single_Resistor (0xA0)
|
|
|
+#define Single_Resistor (0xA0)
|
|
|
#define Double_Resistor (0xB0)
|
|
|
#define Three_Resistor (0xC0)
|
|
|
|
|
|
@@ -53,20 +53,20 @@
|
|
|
#define _Q14(A) (int16)((A) * 0x3fff) // Q14 128*128= 18383
|
|
|
#define _Q15(A) (int16)((A) * 0x7fff) // Q15 128*256= 32767
|
|
|
#define _Q16 (65535.0) // Q16
|
|
|
-#define _2PI (3.1415926 * 2)
|
|
|
+#define _2PI (3.1415926 * 2)
|
|
|
|
|
|
// 双电阻采样周期配置
|
|
|
-#define DouRes_1_Cycle (0xA0) // 周期采样完 ia, ib
|
|
|
-#define DouRes_2_Cycle (0xB0) // 交替采用ia, ib, 2周期采样完成
|
|
|
+#define DouRes_1_Cycle (0xA0) // 周期采样完 ia, ib
|
|
|
+#define DouRes_2_Cycle (0xB0) // 交替采用ia, ib, 2周期采样完成
|
|
|
|
|
|
// SVPWM模式
|
|
|
#define SVPWM_5_Segment (0xA0)
|
|
|
#define SVPWM_7_Segment (0xB0)
|
|
|
|
|
|
// 估算器
|
|
|
-#define SMO (0xA0)
|
|
|
-#define PLL (0xB0)
|
|
|
-#define AO (0xC0)
|
|
|
+#define SMO (0xA0)
|
|
|
+#define PLL (0xB0)
|
|
|
+#define AO (0xC0)
|
|
|
|
|
|
// 开环启动模式选择
|
|
|
#define Open_Start (0xA0)
|
|
|
@@ -74,44 +74,61 @@
|
|
|
#define Open_Omega_Start (0xC0)
|
|
|
|
|
|
//调速模式
|
|
|
-#define UARTMODE (0xA0)
|
|
|
-#define NONEMODE (0xB0)
|
|
|
+#define UARTMODE (0xA0)
|
|
|
+#define NONEMODE (0xB0)
|
|
|
|
|
|
// 外环
|
|
|
#define POWER_CONTROL_MODE (0xA0)
|
|
|
-#define SPEED_CONTROL_MODE (0xB0)
|
|
|
+#define SPEED_CONTROL_MODE (0xB0)
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------------------------
|
|
|
// 2.电机控制参数定义与配置
|
|
|
|
|
|
-#define MCU_CLOCK (24.0)
|
|
|
+#define MCU_CLOCK (24.0)
|
|
|
|
|
|
-#define PWM_LEVEL_MODE (HIGH_LEVEL)
|
|
|
+#define DLL_TIME (1.3) // 双电阻最小脉宽设置(us),建议值为死区时间值+0.2us以上
|
|
|
+#define OVERMOD_TIME (2.0) // 三电阻过调制时间(us),建议值2.0
|
|
|
+#define DT_TIME (1.0) // 死区补偿时间(us)适用于双电阻和三电阻,建议值是1/2死区时间
|
|
|
+#define GLI_TIME (0.5) // 桥臂窄脉宽消除(us),建议值0.5
|
|
|
|
|
|
-// DQ轴最大限幅值
|
|
|
-#define DOUTMAX _Q15(0.99)
|
|
|
-#define DOUTMIN _Q15(-0.99)
|
|
|
-#define QOUTMAX _Q15(0.99)
|
|
|
-#define QOUTMIN _Q15(-0.99)
|
|
|
+#define PWM_CYCLE (1000.0 / PWM_FREQUENCY) // 周期us
|
|
|
+#define SAMP_FREQ (PWM_FREQUENCY * 1000) // 采样频率(HZ)
|
|
|
+#define TPWM_VALUE (1.0 / SAMP_FREQ) // 载波周期(S)
|
|
|
+#define PWM_VALUE_LOAD (uint16)(MCU_CLOCK * 1000 *2 / PWM_FREQUENCY) // PWM 定时器重载值
|
|
|
|
|
|
-// 过调制
|
|
|
-#define OverModulation (0)
|
|
|
+#define PWM_LOAD_DEADTIME (PWM_DEADTIME * MCU_CLOCK) // 死区设置值
|
|
|
+#define PWM_OVERMODULE_TIME (OVERMOD_TIME * MCU_CLOCK / 2) // 过调制时间
|
|
|
+#define PWM_DLOWL_TIME (DLL_TIME * MCU_CLOCK / 2) //下桥臂最小时间
|
|
|
+
|
|
|
+#define PWM_TS_LOAD (uint16)(_Q16 / PWM_CYCLE * MIN_WIND_TIME / 16) // 单电阻采样设置值
|
|
|
+#define PWM_DT_LOAD (uint16)(_Q16 / PWM_CYCLE * DT_TIME / 16) // 死区补偿值
|
|
|
+#define PWM_TGLI_LOAD (uint16)(_Q16 / PWM_CYCLE * (GLI_TIME + PWM_DEADTIME) / 16) // 最小脉冲
|
|
|
+
|
|
|
+#define BASE_FREQ ((MOTOR_SPEED_BASE / 60) * Pole_Pairs) // 基准频率
|
|
|
+
|
|
|
+
|
|
|
+#define PWM_LEVEL_MODE (HIGH_LEVEL)
|
|
|
+
|
|
|
+// DQ轴最大限幅值
|
|
|
+#define DOUTMAX _Q15(0.2)
|
|
|
+#define DOUTMIN _Q15(-0.2)
|
|
|
+#define QOUTMAX _Q15(0.2)
|
|
|
+#define QOUTMIN _Q15(-0.2)
|
|
|
|
|
|
-#define EstimateAlgorithm (AO)
|
|
|
-#define Open_Start_Mode (Omega_Start)
|
|
|
-#define Shunt_Resistor_Mode (Double_Resistor)
|
|
|
|
|
|
|
|
|
#define LPF_K(K) _Q15(_2PI / 1000 * K)
|
|
|
+#define VC1 (1.0)
|
|
|
+#define RV ((RV1 + RV2 + RV3) / RV3)
|
|
|
|
|
|
|
|
|
// 电流基准
|
|
|
#define HW_BOARD_CURR_MAX (HW_ADC_REF / 2 / HW_AMPGAIN / HW_RSHUNT)
|
|
|
#define HW_BOARD_CURR_MIN (-HW_BOARD_CURR_MAX)
|
|
|
-#define HW_BOARD_CURR_BASE (HW_BOARD_CURR_MAX * 2)
|
|
|
+#define HW_BOARD_CURR_BASE (HW_BOARD_CURR_MAX * 2)
|
|
|
|
|
|
// 母线电压采样分压电路
|
|
|
-#define HW_BOARD_VOLT_MAX (HW_ADC_REF * RV)
|
|
|
+#define HW_BOARD_VOLT_MAX (HW_ADC_REF * RV)
|
|
|
#define HW_BOARD_VOLTAGE_BASE (HW_BOARD_VOLT_MAX / 1.732)
|
|
|
#define HW_BOARD_VOLTAGE_VC ((RV1 + RV2 + RV3 * VC1) / (RV3 * VC1))
|
|
|
#define HW_BOARD_VOLTAGE_BASE_Start (HW_ADC_REF * HW_BOARD_VOLTAGE_VC / 1.732)
|
|
|
@@ -119,25 +136,41 @@
|
|
|
#define I_ValueX(Curr_Value) (Curr_Value * HW_RSHUNT * HW_AMPGAIN / (HW_ADC_REF))
|
|
|
#define I_Value(Curr_Value) _Q15(I_ValueX(Curr_Value))
|
|
|
|
|
|
+// 速度带宽的滤波值,经典值为5.0-40.0
|
|
|
+#define SPD_BW (25.0)
|
|
|
+#define ATT_COEF (0.95)
|
|
|
+
|
|
|
+
|
|
|
+// 过调制
|
|
|
+#define OverModulation (0)
|
|
|
+
|
|
|
+#define EstimateAlgorithm (AO)
|
|
|
+#define Open_Start_Mode (Omega_Start)
|
|
|
+#define Shunt_Resistor_Mode (Double_Resistor)
|
|
|
+
|
|
|
+#define CalibENDIS (1)
|
|
|
+#define SVPMW_Mode (SVPWM_7_Segment)
|
|
|
+#define DouRes_Sample_Mode (DouRes_1_Cycle)
|
|
|
+
|
|
|
// ------------------------------------------------------------------------------------------------------------------
|
|
|
// 3.其他宏定义
|
|
|
|
|
|
-#define LED_PIN (GP03)
|
|
|
-#define LED_ON (LED_PIN = 0) // LED 点亮
|
|
|
-#define LED_OFF (LED_PIN = 1) // LED 熄灭
|
|
|
-#define LED_OFF_STATE (LED_PIN == 1) // LED 熄灭状态
|
|
|
-#define LED_TOGGLE (LED_PIN = ~LED_PIN) // LED 翻转
|
|
|
+#define LED_PIN (GP03)
|
|
|
+#define LED_ON (LED_PIN = 0) // LED 点亮
|
|
|
+#define LED_OFF (LED_PIN = 1) // LED 熄灭
|
|
|
+#define LED_OFF_STATE (LED_PIN == 1) // LED 熄灭状态
|
|
|
+#define LED_TOGGLE (LED_PIN = ~LED_PIN) // LED 翻转
|
|
|
|
|
|
|
|
|
|
|
|
-#define VDCBUS_ADC ADC2_DR // 高压直流
|
|
|
-#define VACBUS_ADC ADC3_DR // 高压交流
|
|
|
-#define NTC1_ADC ADC6_DR // NTC1
|
|
|
-#define NTC2_ADC ADC7_DR // NTC2
|
|
|
-#define IGBT_NTC_ADC ADC11_DR // IGBT
|
|
|
+#define VDCBUS_ADC ADC2_DR // 高压直流
|
|
|
+#define VACBUS_ADC ADC3_DR // 高压交流
|
|
|
+#define NTC1_ADC ADC6_DR // NTC1
|
|
|
+#define NTC2_ADC ADC7_DR // NTC2
|
|
|
+#define IGBT_NTC_ADC ADC11_DR // IGBT
|
|
|
|
|
|
-#define PRE_DRIVER_RST GP04 // 驱动复位
|
|
|
-#define MAIN_RELAY GP51 // 母线主继电器
|
|
|
+#define PRE_DRIVER_RST GP04 // 驱动复位
|
|
|
+#define MAIN_RELAY GP51 // 母线主继电器
|
|
|
|
|
|
|
|
|
|
|
|
@@ -148,17 +181,17 @@
|
|
|
// LED控制
|
|
|
typedef struct
|
|
|
{
|
|
|
- enum
|
|
|
- {
|
|
|
- LED_STATE_OFF, // 熄灭
|
|
|
- LED_STATE_ON, // 常亮
|
|
|
- LED_STATE_BLINK_FAULT, // 故障闪烁
|
|
|
- LED_STATE_POST_FAULT_DELAY // 延时等待
|
|
|
- }LedState ;
|
|
|
-
|
|
|
- uint16_t PauseDelayCnt;
|
|
|
- uint8_t BlinkCnt;
|
|
|
-}LED_Control_t;
|
|
|
+ enum
|
|
|
+ {
|
|
|
+ LED_STATE_OFF, // 熄灭
|
|
|
+ LED_STATE_ON, // 常亮
|
|
|
+ LED_STATE_BLINK_FAULT, // 故障闪烁
|
|
|
+ LED_STATE_POST_FAULT_DELAY // 延时等待
|
|
|
+ } LedState ;
|
|
|
+
|
|
|
+ uint16_t PauseDelayCnt;
|
|
|
+ uint8_t BlinkCnt;
|
|
|
+} LED_Control_t;
|
|
|
extern volatile LED_Control_t ledControl;
|
|
|
void LED_State_Display(uint8_t Xn0);
|
|
|
|
|
|
@@ -166,14 +199,14 @@ void LED_State_Display(uint8_t Xn0);
|
|
|
// 上电控制
|
|
|
typedef struct
|
|
|
{
|
|
|
- enum
|
|
|
- {
|
|
|
- DELAY_POWER_ON, // 等待上电
|
|
|
- DELAY_FREE_RST, // 等待释放复位
|
|
|
- POWER_RUN // 上电完成
|
|
|
- }PowerSate;
|
|
|
- uint16_t PowerInCnt; // 上电时间计数
|
|
|
-}Power_Control_t;
|
|
|
+ enum
|
|
|
+ {
|
|
|
+ DELAY_POWER_ON, // 等待上电
|
|
|
+ DELAY_FREE_RST, // 等待释放复位
|
|
|
+ POWER_RUN // 上电完成
|
|
|
+ } PowerSate;
|
|
|
+ uint16_t PowerInCnt; // 上电时间计数
|
|
|
+} Power_Control_t;
|
|
|
|
|
|
extern volatile Power_Control_t powerControl;
|
|
|
void Power_In_Control(void);
|
|
|
@@ -182,32 +215,32 @@ void Power_In_Control(void);
|
|
|
// 电机控制
|
|
|
typedef struct
|
|
|
{
|
|
|
- // 模拟数据
|
|
|
- uint16_t DCBus;
|
|
|
- uint16_t ACBus;
|
|
|
- uint16_t IGBTTemp;
|
|
|
-
|
|
|
- // 数据处理
|
|
|
- uint16_t ACBusMax;
|
|
|
- uint16_t ACBusMin;
|
|
|
-
|
|
|
- // 速度相关
|
|
|
- int16_t RampInc;
|
|
|
- int16_t RampDec;
|
|
|
- int16_t TargetRef;
|
|
|
- int16_t ActualRef;
|
|
|
- int16_t ActualSpeed;
|
|
|
- int16_t QOutRef;
|
|
|
-
|
|
|
- int16_t IQRef;
|
|
|
- int16_t IDRef;
|
|
|
-
|
|
|
- // 保护相关
|
|
|
- uint16_t BackEMF;
|
|
|
- // 测试
|
|
|
- int16_t uPhaseCurr;
|
|
|
- int16_t vPhaseCurr;
|
|
|
-}Motor_Control_t;
|
|
|
+ // 模拟数据
|
|
|
+ uint16_t DCBus;
|
|
|
+ uint16_t ACBus;
|
|
|
+ uint16_t IGBTTemp;
|
|
|
+
|
|
|
+ // 数据处理
|
|
|
+ uint16_t ACBusMax;
|
|
|
+ uint16_t ACBusMin;
|
|
|
+
|
|
|
+ // 速度相关
|
|
|
+ int16_t RampInc;
|
|
|
+ int16_t RampDec;
|
|
|
+ int16_t TargetRef;
|
|
|
+ int16_t ActualRef;
|
|
|
+ int16_t ActualSpeed;
|
|
|
+ int16_t QOutRef;
|
|
|
+
|
|
|
+ int16_t IQRef;
|
|
|
+ int16_t IDRef;
|
|
|
+
|
|
|
+ // 保护相关
|
|
|
+ uint16_t BackEMF;
|
|
|
+ // 测试
|
|
|
+ int16_t uPhaseCurr;
|
|
|
+ int16_t vPhaseCurr;
|
|
|
+} Motor_Control_t;
|
|
|
|
|
|
extern Motor_Control_t motorControl;
|
|
|
|