123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551 |
- /************************************************************************
- Project: Welling Motor Control Paltform
- Filename: user.h
- Partner Filename: Null
- Description: User parameters
- Complier: IAR Embedded Workbench for ARM 7.80, IAR Systems.
- CPU TYPE : STM32F30x
- *************************************************************************
- Copyright (c) 2019 Welling Motor Technology(Shanghai) Co. Ltd.
- All rights reserved.
- *************************************************************************
- *************************************************************************
- Revising History (ECL of this file):
- ************************************************************************/
- #ifndef USER_H
- #define USER_H
- /************************************************************************
- Compiler Directives
- *************************************************************************/
- #include "typedefine.h"
- #ifdef __cplusplus
- extern "C" {
- #endif // __cplusplus
- /************************************************************************
- Definitions & Macros
- *************************************************************************/
- /*======================================================================*
- Update Time
- 2021-06-21 13:47:04
- *=======================================================================*/
- /*======================================================================*
- Software version
- *=======================================================================*/
- #define SOFTWARE_VERSION 0x1C10
- #define SOFTWARE_VERSION_WELLING 0x0001
- /*======================================================================*
- Motor Parameters
- *=======================================================================*/
- /*======================================================================*
- Motor Number Selection
- *=======================================================================*/
- #define MOTOR_WELLING_CITY_36V 0x20
- #define MOTOR_WELLING_MTB_36V 0x21
- #define MOTOR_WELLING_CITY_48V 0x30
- #define MOTOR_WELLING_MTB_48V 0x31
- #define MOTOR_ID_SEL MOTOR_WELLING_MTB_36V ///< syspar.hÖÐÒ²ÐèҪѡÔñ36V/48Vϵͳ
- /*======================================================================*
- Motor Parameters
- *=======================================================================*/
- #if (MOTOR_ID_SEL == MOTOR_WELLING_MTB_36V)
- #define M_POLE_PAIRS 7 // unit:Null,Pole pairs
- #define M_RS_OHM 170 // unit: 0.1mOhm, Phase resistance
- #define M_MATERIAL Al // unit:Null
- #define M_LD_NOLOAD_MH 11000 // unit: 0.01uH, D axis inductance
- #define M_LQ_NOLOAD_MH 11500 // unit: 0.01uH, Q axis inductance
- #define M_LD_TURN1_ID_AP 5000 // unit: 0.01A,
- #define M_LD_TURN1_LD_MH 11000 // unit: 0.01uH,D axis inductance
- #define M_LD_TURN2_ID_AP 700 // unit: 0.01A,
- #define M_LD_TURN2_LD_MH 11000 // unit: 0.01uH,D axis inductance
- #define M_LD_MIN_MH 11000 // unit: 0.01uH,D axis inductance
- #define M_LQ_TURN1_IQ_AP 200 // unit: 0.01A,
- #define M_LQ_TURN1_LQ_MH 11500 // unit: 0.01uH,Q axis inductance
- #define M_LQ_TURN2_IQ_AP 700 // unit: 0.01A,
- #define M_LQ_TURN2_LQ_MH 11500 // unit: 0.01uH,Q axis inductance
- #define M_LQ_MIN_MH 11500 // unit: 0.01uH,Q axis inductance
- #define M_JD 2500 // unit: 10-7Kg*m2, Rotational inertia
- #define M_MAGNETIC_MATERIAL Ferrite // unit:Null
- #define M_FLUX_WB 5360 // unit: 0.001mWb, Flux linkage
- #define M_ID_MAX_AP 0 //-25 // unit: 0.01A, Max d axis current
- #define M_ID_MIN_AP -300 // unit: 0.01A, Min d axis current
- #define M_IS_PEAK_MAX_AP 5500 // unit: 0.01A, Max phase current(below base speed)
- #define M_POWER_MAX_WT 600 // unit: W, Max power
- #define M_R_SPD_RPM 5000 // unit: r/min, rate spd
- #define M_R_PWR_WT 250 // unit: W, rate power
- #define M_R_IRMS_A 2500 // unit: 0.01A, rate Irms
- #define M_R_UDC_v 360 // unit: 0.1V, rate Udc
- #define M_MAX_TOR_NM 30 // unit: 0.1Nm, Max tor
- #elif (MOTOR_ID_SEL == MOTOR_WELLING_MTB_48V)
- #define M_POLE_PAIRS 7 // unit:Null,Pole pairs
- #define M_RS_OHM 170 // unit: 0.1mOhm, Phase resistance
- #define M_MATERIAL Al // unit:Null
- #define M_LD_NOLOAD_MH 11000 // unit: 0.01uH, D axis inductance
- #define M_LQ_NOLOAD_MH 11500 // unit: 0.01uH, Q axis inductance
- #define M_LD_TURN1_ID_AP 5000 // unit: 0.01A,
- #define M_LD_TURN1_LD_MH 11000 // unit: 0.01uH,D axis inductance
- #define M_LD_TURN2_ID_AP 700 // unit: 0.01A,
- #define M_LD_TURN2_LD_MH 11000 // unit: 0.01uH,D axis inductance
- #define M_LD_MIN_MH 11000 // unit: 0.01uH,D axis inductance
- #define M_LQ_TURN1_IQ_AP 200 // unit: 0.01A,
- #define M_LQ_TURN1_LQ_MH 11500 // unit: 0.01uH,Q axis inductance
- #define M_LQ_TURN2_IQ_AP 700 // unit: 0.01A,
- #define M_LQ_TURN2_LQ_MH 11500 // unit: 0.01uH,Q axis inductance
- #define M_LQ_MIN_MH 11500 // unit: 0.01uH,Q axis inductance
- #define M_JD 2500 // unit: 10-7Kg*m2, Rotational inertia
- #define M_MAGNETIC_MATERIAL Ferrite // unit:Null
- #define M_FLUX_WB 5360 // unit: 0.001mWb, Flux linkage
- #define M_ID_MAX_AP 0 //-25 // unit: 0.01A, Max d axis current
- #define M_ID_MIN_AP -300 // unit: 0.01A, Min d axis current
- #define M_IS_PEAK_MAX_AP 5500 // unit: 0.01A, Max phase current(below base speed)
- #define M_POWER_MAX_WT 600 // unit: W, Max power
- #define M_R_SPD_RPM 5000 // unit: r/min, rate spd
- #define M_R_PWR_WT 250 // unit: W, rate power
- #define M_R_IRMS_A 2500 // unit: 0.01A, rate Irms
- #define M_R_UDC_v 480 // unit: 0.1V, rate Udc
- #define M_MAX_TOR_NM 30 // unit: 0.1Nm, Max tor
- #elif (MOTOR_ID_SEL == MOTOR_WELLING_CITY_36V)
- #define M_POLE_PAIRS 7 // unit:Null,Pole pairs
- #define M_RS_OHM 150 // unit: 0.1mOhm, Phase resistance
- #define M_MATERIAL Al // unit:Null
- #define M_LD_NOLOAD_MH 7650 // unit: 0.01uH, D axis inductance
- #define M_LQ_NOLOAD_MH 10200 // unit: 0.01uH, Q axis inductance
- #define M_LD_TURN1_ID_AP 5000 // unit: 0.01A,
- #define M_LD_TURN1_LD_MH 7650 // unit: 0.01uH,D axis inductance
- #define M_LD_TURN2_ID_AP 700 // unit: 0.01A,
- #define M_LD_TURN2_LD_MH 7650 // unit: 0.01uH,D axis inductance
- #define M_LD_MIN_MH 7650 // unit: 0.01uH,D axis inductance
- #define M_LQ_TURN1_IQ_AP 200 // unit: 0.01A,
- #define M_LQ_TURN1_LQ_MH 10200 // unit: 0.01uH,Q axis inductance
- #define M_LQ_TURN2_IQ_AP 700 // unit: 0.01A,
- #define M_LQ_TURN2_LQ_MH 10200 // unit: 0.01uH,Q axis inductance
- #define M_LQ_MIN_MH 10200 // unit: 0.01uH,Q axis inductance
- #define M_JD 2500 // unit: 10-7Kg*m2, Rotational inertia
- #define M_MAGNETIC_MATERIAL Ferrite // unit:Null
- #define M_FLUX_WB 4800//5056 // unit: 0.001mWb, Flux linkage
- #define M_ID_MAX_AP 0 //-25 // unit: 0.01A, Max d axis current
- #define M_ID_MIN_AP -300 // unit: 0.01A, Min d axis current
- #define M_IS_PEAK_MAX_AP 5500 // unit: 0.01A, Max phase current(below base speed)
- #define M_POWER_MAX_WT 600 // unit: W, Max power
- #define M_R_SPD_RPM 5000 // unit: r/min, rate spd
- #define M_R_PWR_WT 250 // unit: W, rate power
- #define M_R_IRMS_A 2500 // unit: 0.01A, rate Irms
- #define M_R_UDC_v 360 // unit: 0.1V, rate Udc
- #define M_MAX_TOR_NM 30 // unit: 0.1Nm, Max tor
- #elif (MOTOR_ID_SEL == MOTOR_WELLING_CITY_48V)
- #define M_POLE_PAIRS 7 // unit:Null,Pole pairs
- #define M_RS_OHM 150 // unit: 0.1mOhm, Phase resistance
- #define M_MATERIAL Al // unit:Null
- #define M_LD_NOLOAD_MH 7650 // unit: 0.01uH, D axis inductance
- #define M_LQ_NOLOAD_MH 10200 // unit: 0.01uH, Q axis inductance
- #define M_LD_TURN1_ID_AP 5000 // unit: 0.01A,
- #define M_LD_TURN1_LD_MH 7650 // unit: 0.01uH,D axis inductance
- #define M_LD_TURN2_ID_AP 700 // unit: 0.01A,
- #define M_LD_TURN2_LD_MH 7650 // unit: 0.01uH,D axis inductance
- #define M_LD_MIN_MH 7650 // unit: 0.01uH,D axis inductance
- #define M_LQ_TURN1_IQ_AP 200 // unit: 0.01A,
- #define M_LQ_TURN1_LQ_MH 10200 // unit: 0.01uH,Q axis inductance
- #define M_LQ_TURN2_IQ_AP 700 // unit: 0.01A,
- #define M_LQ_TURN2_LQ_MH 10200 // unit: 0.01uH,Q axis inductance
- #define M_LQ_MIN_MH 10200 // unit: 0.01uH,Q axis inductance
- #define M_JD 2500 // unit: 10-7Kg*m2, Rotational inertia
- #define M_MAGNETIC_MATERIAL Ferrite // unit:Null
- #define M_FLUX_WB 4800//5056 // unit: 0.001mWb, Flux linkage
- #define M_ID_MAX_AP 0 //-25 // unit: 0.01A, Max d axis current
- #define M_ID_MIN_AP -300 // unit: 0.01A, Min d axis current
- #define M_IS_PEAK_MAX_AP 5500 // unit: 0.01A, Max phase current(below base speed)
- #define M_POWER_MAX_WT 600 // unit: W, Max power
- #define M_R_SPD_RPM 5000 // unit: r/min, rate spd
- #define M_R_PWR_WT 250 // unit: W, rate power
- #define M_R_IRMS_A 2500 // unit: 0.01A, rate Irms
- #define M_R_UDC_v 480 // unit: 0.1V, rate Udc
- #define M_MAX_TOR_NM 30 // unit: 0.1Nm, Max tor
- #endif
- /*======================================================================*
- IPM Paremeters
- *=======================================================================*/
- /* SL IPM */
- #define IPM_TURN_ON_TM_NS 300 // 86 // unit:ns
- #define IPM_TURN_OFF_TM_NS 300 // 105 // unit:ns
- #define IPM_DEAD_TM_NS 1000 // unit:ns
- #define IPM_HVIC_CHRG_TM 20 // unit: ms,Bootstrap capacitor charge time
- /*======================================================================*
- Alarm threshold value & time of duration define
- *=======================================================================*/
- /* Over current */
- #define ALM_OVR_CNT_VAL 6400 // unit: 0.01A, Threshold value
- #define ALM_OVR_CNT_TM 500 // unit: us, Time of duration(TBC)
- /* Phase loss */
- #define ALM_PHS_LOSS_VAL 50 // unit: 0.01A, Threshold value
- #define ALM_PHS_LOSS_TM 5 // unit: s, Time of duration(TBC)
- /* Rotor lock */
- #define ALM_ROTOR_LOCK_SPD_K 30 // unit: %, Q10, Ratio of resistance power and motor input power
- #define ALM_ROTOR_LOCK_TM 3 // unit: s, Time of duration(TBC)
- #define ALM_ROTOR_LOCK_IQ_ABS 4500 // unit: 0.01A, Threshold value
- #define ALM_ROTOR_LOCK_SPD 100 // unit: rpm, Threshold value
- #if ((MOTOR_ID_SEL == MOTOR_WELLING_CITY_36V) || (MOTOR_ID_SEL == MOTOR_WELLING_MTB_36V))
- /* Over voltage */
- #define ALM_OVR_VLT_LVL1_VAL 450 // unit: 0.1V, Threshold value level1
- #define ALM_OVR_VLT_LVL1_TM 2 // unit: s, Time of duration level1(TBS)
- #define ALM_OVR_VLT_LVL2_VAL 460 // unit: 0.1V, Threshold value level2
- #define ALM_OVR_VLT_LVL2_TM 100 // unit: ms, Time of duration level2(TBS)
- #define ALM_OVR_VLT_LVL3_VAL 470 // unit: 0.1V, Threshold value level3
- #define ALM_OVR_VLT_LVL3_TM 5 // unit: ms, Time of duration level3(TBS)
- /* Under voltage */
- #define ALM_UNDR_VLT_LVL1_VAL 300 // unit: 0.1V, Threshold value level1
- #define ALM_UNDR_VLT_LVL1_TM 2 // unit: s, Time of duration level1(TBS)
- #define ALM_UNDR_VLT_LVL2_VAL 280 // unit: 0.1V, Threshold value level2
- #define ALM_UNDR_VLT_LVL2_TM 2 // unit: ms, Time of duration level2(TBS)
- #elif ((MOTOR_ID_SEL == MOTOR_WELLING_CITY_48V) || (MOTOR_ID_SEL == MOTOR_WELLING_MTB_48V))
- /* Over voltage */
- #define ALM_OVR_VLT_LVL1_VAL 585 // unit: 0.1V, Threshold value level1
- #define ALM_OVR_VLT_LVL1_TM 2 // unit: s, Time of duration level1(TBS)
- #define ALM_OVR_VLT_LVL2_VAL 598 // unit: 0.1V, Threshold value level2
- #define ALM_OVR_VLT_LVL2_TM 100 // unit: ms, Time of duration level2(TBS)
- #define ALM_OVR_VLT_LVL3_VAL 611 // unit: 0.1V, Threshold value level3
- #define ALM_OVR_VLT_LVL3_TM 5 // unit: ms, Time of duration level3(TBS)
- /* Under voltage */
- #define ALM_UNDR_VLT_LVL1_VAL 390 // unit: 0.1V, Threshold value level1
- #define ALM_UNDR_VLT_LVL1_TM 2 // unit: s, Time of duration level1(TBS)
- #define ALM_UNDR_VLT_LVL2_VAL 364 // unit: 0.1V, Threshold value level2
- #define ALM_UNDR_VLT_LVL2_TM 2 // unit: ms, Time of duration level2(TBS)
- #endif
- /* Over speed */
- #define ALM_OVR_SPD_VAL 6000 // unit: rpm, Threshold value
- #define ALM_OVR_SPD_TM 100 // unit: ms, Time of duration(TBS)
- /* ADC self detecting */
- #define ALM_ADC_DETE_LOW_VAL 155 // unit: 0.01V, ADC offset Voltage min
- #define ALM_ADC_DETE_HIG_VAL 175 // unit: 0.01V, ADC offset Voltage max
- /* IPM over heat */
- #define ALM_IPM_OVR_HEAT_VAL 105//50 //105 // unit: Ce, Threshold value
- #define ALM_IPM_OVR_TM 2 // unit: s, Time of duration(TBS)
- #define PWRLIM_START_THRESHOLD_TEMP 85//40 //80 // Q0,Ce
- /* Stop time of three phase short force */
- #define ALM_THR_PHS_SHRT_FRC_TM 200 // unit: ms, Time of duration(TBC)
- /* Stop time of pwm off */
- #define ALM_PWM_OFF_TM 200 // unit: ms, Time of duration(TBC)
- #define ALM_PWMOFF_SHRT1_SW_TM 100 // unit: ms, Time of duration(TBC)
- /* Stop time of three phase short */
- #define ALM_THR_PHS_SHRT_NORM_TM 100 // unit: ms, Time of duration(TBC)
- #define ALM_SHRT_PWMOFF_SW_TM 100 // unit: ms, Time of duration(TBC)
- /* Stop Minimum Current */
- #define ALM_STOP_IPM_OVER_CUR_TM 100 // unit: ms, Time of duration(TBC)
- /* Recover time of global */
- #define ALM_REC_ALL_TM 5000 // unit: ms, Time of duration(TBC)
- /* Recover time of IPM OC */
- #define ALM_IPM_OC_REC_TM 200 // unit: ms, Time of duration(TBC)
- /* Recover time & value of over voltage */
- #define ALM_OVR_VLT_REC_VAL (ALM_OVR_VLT_LVL1_VAL - 30) // unit: 0.1V
- #define ALM_OVR_VLT_REC_TM 100 // unit: ms, Time of duration(TBC)
- #define ALM_OVR_VLT_REC_TM1 150 // unit: ms, Time of duration(TBC)
- /* Recover time & value of under voltage */
- #define ALM_UNDR_VLT_REC_VAL (ALM_UNDR_VLT_LVL1_VAL + 30) // unit: 0.1V
- #define ALM_UNDR_VLT_REC_TM 200 // unit: ms, Time of duration(TBC)
- #define ALM_UNDR_VLT_REC_TM1 400 // unit: ms, Time of duration(TBC)
- /* Recover time & value of IPM over heat */
- #define ALM_IPM_OVR_HEAT_REC_VAL 90 // unit: Ce, Threshold value
- #define ALM_IPM_OVR_REC_TM 60 // unit: s, Time of duration(TBC)
- #define ALM_IPM_OVR_REC_TM1 120 // unit: s, Time of duration(TBC)
- /* Ebike sensor fault detect*/
- #define ALM_MOTORSPD_MIN_RPM 50 //unit: rpm
- #define ALM_BIKESPD_FLT_TS 10 //unit: s
- #define ALM_CADENCE_FLT_TS 2 //unit: s
- #define ALM_TORQ_MAX_VOL 30 //unit: 0.1V
- #define ALM_TORQ_MIN_VOL 1 //unit: 0.1V
- #define ALM_TORQ_FLT_TS 1 //unit: s
- #define ALM_THROTTLE_MAX_VOL 30 //unit: 0.1V
- #define ALM_THROTTLE_MIN_VOL 1 //unit: 0.1V
- #define ALM_THROTTLE_FLT_TS 1 //unit: s
- #define ALM_NTC_MAX_VOL 32 //unit: 0.1V
- #define ALM_NTC_MIN_VOL 3 //unit: 0.1V
- #define ALM_MOTORNTC_FLT_TS 1 //unit: s
- #define ALM_PCBNTC_FLT_TS 1 //unit: s
- /* Ebike sensor fault recover*/
- #define ALM_BIKE_REC_ALL_TM 1000 //unit: ms
- #define ALM_BIKESPD_REC_TM 200 //unit: ms
- #define ALM_CADENCE_REC_TM 200 //unit: ms
- #define ALM_TORQ_REC_TM 200 //unit: ms
- #define ALM_THROTTLE_REC_TM 200 //unit: ms
- #define ALM_MOTORNTC_REC_TM 200 //unit: ms
- #define ALM_PCBNTC_REC_TM 200 //unit: ms
- /*======================================================================*
- Motor start
- *=======================================================================*/
- /* Start mode */
- #define START_ALIGN 0 // Motor start with three stage
- #define START_MODE START_ALIGN // Motor start mode
- /* InitPosDet mode */
- #define INITPOS_ALIGN 0 // Motor start with three stage
- #define INITPOS_MODE INITPOS_ALIGN // Motor initposdet mode
- /* Park time & current */
- #define ALIGN_CUR_AP 1000 // unit: 0.01A, Park current value
- #define ALIGN_RAMP_TM_MS 500 // unit: ms, Time of current ramp
- #define ALIGN_HOLD_TM_MS 2000 // unit: ms, Time of current hold
- #define ALIGN_ANG_INIT 0 // unit: deg, Park angle init, can not be 90deg
- /* Drag speed & current */
- #define DRAG_CUR_AP 1000 // 1500 //100 Huawei // unit: 0.01A, Drag current value
- #define DRAG_VOL_AP 18 // 0.1v
- #define DRAG_SPD_HZ 20 // unit: Hz, Final speed of drag
- #define DRAG_SPD_RAMP_TM_MS 4000 // unit: ms, Time of speed from 0Hz to target Hz
- /* Open to close */
- #define OPEN2CLZ_CUR_RAMP_TM_MS 5000 // 5000//1000 Huawei // unit: ms, Time of current from drag value to 0
- /* Close loop */
- /* stop loop */
- #define STOP_SPD_REF_RPM 100 // unit: rpm, Speed reference value when status go to stop
- /*======================================================================*
- Flux observer
- *=======================================================================*/
- #define OBS_SPD_PLL_M 2 // Flux observer m coefficient
- #define OBS_SPD_PLL_BANDWIDTH_HZ 150 // Huawei // Flux observer PLL bandwidth
- #define OBS_FLUX_PI_DAMPRATIO 10 // unit:0.1, Flux observer PI regulator dampratio
- #define OBS_FLUX_PI_CROSSFREQ_HZ 10 // unit:Hz, Flux observer PI regulator crossfrequency
- /*======================================================================*
- Current loop PI regulation
- *=======================================================================*/
- #define ACR_PI_BANDWIDTH_FLX 300 // unit: Hz, Current loop bandwidth when flux observer run
- #define ACR_CUR_FLX_FBK_LPF_FRQ 8000 // unit: Hz, Frequency of current feedback LPF when flux observer run
- #define ACR_CUR_OUT_LIM 37837 // Q15, 2/sqrt(3)*Vdc for current output limit //18919
- #define ACR_RA_COEF 1 // Coefficient of Active Resistance
- #define ACR_UDCP_OUT_LIM 18918 // Q15, 2/3*Vdc for Udcp output limit //18918 //21845 //10923
- /*======================================================================*
- Speed loop PI regulation
- *=======================================================================*/
- #define ASR_PI_BANDWIDTH 3 // unit: Hz, Speed loop bandwidth
- #define ASR_PI_M 4 //
- #define ASR_SPD_FBK_LPF_FRQ 50 //
- #define ASR_SPD_INER_RATE 1 //
- /*=====================================================================*
- PWM generation
- *=======================================================================*/
- #define PWM_MAX_DUTY_CYLE_IPM 880 //890 // 938 // unit: 0.1%,Max duty cyle for compare value
- #define PWM_7SVM_TO_5SVM_DUTY_IPM 700 // unit: 0.1%, Switch ratio from 7 to 5 svpwm
- #define PWM_MIN_SAMPLE_DUTY1_IPM 5 * 10000 / PWM_PERIOD_US // unit: 0.1%, 5us TWO MIN ZERO VECTOR = two sample current steady time
- #define PWM_MIN_SAMPLE_DUTY2_IPM 10 * 10000 / PWM_PERIOD_US // unit: 0.1%, 10us TWO (one sample current steady time + one sample time)
- #define PWM_MIN_SAMPLE_DUTY3_IPM \
- ((ULONG)6 * 10000 / PWM_PERIOD_US) // unit: 0.1%, 6 us TWO (one Singel Resistance sample current steady time + one sample time)
- #define PWM_SAMPLE_TOSTEADY_IPM ((ULONG)8 * 10000 / PWM_PERIOD_US) // unit: 0.1%, 4us TWO sample current to steady time
- #define PWM_SAMPLE_SINGELRESIS_IPM ((ULONG)1 * 10000 / PWM_PERIOD_US) // unit: 0.1%, 1us TWO singel Resistance sample time
- #define PWM_1ST_SAMPLE_CTS_IPM 25//43 // 25 // unit: Null, first current sample counts
- #define PWM_2ND_SAMPLE_CTS_IPM 220//280 // 220 // unit: Null, second current sample counts
- #define PWM_MIN_EFF_VECTOR_CTS_IPM 245//323 // unit: Null, Min effective vector counts
- #define PWM_MIN_EFF_VECTOR_PU_IPM 892//1176 // 600 // unit: Q14, Min effective vector pu
- #define PWM_OVR_MDL_MIN_PHS 0 // SVPWM over modulation: min phase error
- #define PWM_OVR_MDL_MIN_AMP 1 // SVPWM over modulation: min amplitude error
- #define PWM_OVR_MDL_OPTIMUM 2 // SVPWM over modulation: amplitude and phase optimum
- #define PWM_OVR_MDL_SEL PWM_OVR_MDL_MIN_PHS //
- /*======================================================================*
- Flux Weakening
- *=======================================================================*/
- #define FW_VDC_MIN_CALC_TM 20 // unit: ms,50Hz=>20ms, period of Vdc fluctuate
- #define FW_VDC_LPF_FRQ 50 // unit: Hz, Frequency of Vdc LPF
- #define FW_PWM_MAX_DUTY_CYLE_IPM 880 // unit: 0.1%,PWM max duty cyle for flux weakening
- #define FW_ID_PI_OUT_MIN 1000 // unit: 0.01A, Min Id of PI outunit: 0.01A, Current Limit
- #define FW_ID_MIN_LIM_RATIO 80 // Q0:1%, Ratio of Min d axis current (Charactoristic current)
- #define FW_ID_KP_PU 10 // Q16, Kp for d axis current
- #define FW_ID_KI_PU 5 // Q16, Ki for d axis current
- #define FW_CHAR_CUR_CROSS_FREQ 2 // Q0,unit: SQRT(1/2piR)
- #define FW_CHAR_CUR_DAMP_RATIO 2 // Q0,unit: SQRT(pi/2R)
- /*======================================================================*
- Constant Voltage Braking Parameter define
- *=======================================================================*/
- #define CVB_CONSTANT_VOL_BRAKE_V (ALM_OVR_VLT_LVL1_VAL - 30) // unit:0.1V,Voltage limit of Constant Voltage Brake
- #define CVB_CONSTANT_SPD_LOW_RPM 4500 // unit:rpm,
- /*======================================================================*
- Power limit
- *=======================================================================*/
- #define PWRLIM_VAL 6500 // unit: 0.1w, Power limit value
- #define PWRLIM_ERR 500 // unit: 0.1w, Start power limit when "VAL - ERR"
- #define PWRLIM_LPF_FRQ 8000 // unit: Hz, Frequency of LPF in input power of motor
- #define PWR_IQ_LIMIT_KP_PU 20 // Q15
- #define PWR_IQ_LIMIT_KI_PU 3000 // Q15
- /*======================================================================*
- Deadband compensation
- *=======================================================================*/
- #define DBC_K_COEF 300 // unit:0.1V/A Deadband compensation slope coefficient
- /*======================================================================*
- Communication type define
- *=======================================================================*/
- #define UART_MONITOR 0 //
- #define UART_HOST 1 //
- #define UART_TYPE UART_HOST //
- /*==============================================================================
- Speed & Acc Constant parameters define
- ==============================================================================*/
- #define USER_MOTOR_45RPM2PU SPD_RPM2PU(45) // 45rpm,Q15
- #define USER_MOTOR_100RPM2PU SPD_RPM2PU(100)
- #define USER_MOTOR_200RPM2PU SPD_RPM2PU(200)
- #define USER_MOTOR_300RPM2PU SPD_RPM2PU(300)
- #define USER_MOTOR_400RPM2PU SPD_RPM2PU(400)
- #define USER_MOTOR_600RPM2PU SPD_RPM2PU(600) // 600rpm,Q15
- #define USER_MOTOR_800RPM2PU SPD_RPM2PU(800) // 800rpm,Q15
- #define USER_MOTOR_1000RPM2PU SPD_RPM2PU(1000) // 1000rpm,Q15
- #define USER_MOTOR_1500RPM2PU SPD_RPM2PU(1500) // 6000rpm,Q15
- #define USER_MOTOR_4000RPM2PU SPD_RPM2PU(4000) // 6000rpm,Q15
- #define USER_MOTOR_5500RPM2PU SPD_RPM2PU(5500)
- #define USER_MOTOR_100RPMPS2PU_Q29 SPD_ACC_RPM2PU(100) // 100rpm/s,(0x40000000/FTBS_Hz/cof_uwVbRpm*100)
- /*=======================================================================
- TBS&TBC Time Cnts Define
- =======================================================================*/
- #define TBCCNT_500us (((ULONG)500 * FTBC_HZ) / 1000000)
- #define TBCCNT_1ms (((ULONG)1 * FTBC_HZ) / 1000)
- #define TBCCNT_5ms (((ULONG)5 * FTBC_HZ) / 1000)
- #define TBCCNT_10ms (((ULONG)10 * FTBC_HZ) / 1000)
- #define TBCCNT_50ms (((ULONG)50 * FTBC_HZ) / 1000)
- #define TBCCNT_32ms (((ULONG)32 * FTBC_HZ) / 1000)
- #define TBCCNT_60ms (((ULONG)60 * FTBC_HZ) / 1000)
- #define TBCCNT_100ms (((ULONG)100 * FTBC_HZ) / 1000)
- #define TBCCNT_150ms (((ULONG)150 * FTBC_HZ) / 1000)
- #define TBCCNT_200ms (((ULONG)200 * FTBC_HZ) / 1000)
- #define TBCCNT_250ms (((ULONG)250 * FTBC_HZ) / 1000)
- #define TBCCNT_300ms (((ULONG)300 * FTBC_HZ) / 1000)
- #define TBCCNT_400ms (((ULONG)400 * FTBC_HZ) / 1000)
- #define TBCCNT_500ms (((ULONG)500 * FTBC_HZ) / 1000)
- #define TBCCNT_100ms (((ULONG)100 * FTBC_HZ) / 1000)
- #define EVE1MSCNT_1ms (((ULONG)1 * EVENT_1MS_HZ) / 1000)
- #define EVE1MSCNT_5ms (((ULONG)5 * EVENT_1MS_HZ) / 1000)
- #define EVE1MSCNT_10ms (((ULONG)10 * EVENT_1MS_HZ) / 1000)
- #define EVE1MSCNT_20ms (((ULONG)20 * EVENT_1MS_HZ) / 1000)
- #define EVE1MSCNT_50ms (((ULONG)50 * EVENT_1MS_HZ) / 1000)
- #define EVE1MSCNT_100ms (((ULONG)100 * EVENT_1MS_HZ) / 1000)
- #define EVE1MSCNT_200ms (((ULONG)200 * EVENT_1MS_HZ) / 1000)
- #define EVE10MSCNT_3s ((ULONG)3 * EVENT_1MS_HZ / 10)
- #define EVE10MSCNT_5s ((ULONG)5 * EVENT_1MS_HZ / 10)
- #define EVE10MSCNT_10s ((ULONG)10 * EVENT_1MS_HZ / 10)
- /************************************************************************
- Comment Table
- *************************************************************************/
- // /*======================================================================*
- // High Frequency Signal Injection
- // *=======================================================================*/
- // #define HFI_FREQ1_HZ 1200 // unit: Hz, Inject signal frequency 1
- // #define HFI_AMP1_VT 600 // unit: 0.1v, Inject signal voltage 1
- // #define HFI_FREQ2_HZ 1400 // unit: Hz, Inject signal frequency 2
- // #define HFI_AMP2_VT 700 // unit: 0.1v, Inject signal voltage 2
- // #define HFI_TM_INIPOS_MS 60 // unit: ms, Initial position detection time
- // #define HFI_WAITTM_INIPOS_MS 6 // unit: ms, Wait time after initial position detection
- // #define HFI_AMP_POR_VT 700 // unit: 0.1v, Polarity detection voltage amplitude
- // #define HFI_TM_POR_PULS_MS 1 // unit: ms, Polarity detection voltage pulse time
- // #define HFI_WAITTM_POR_PULS_MS 12 // Wunit: ms, ait time after voltage pulse
- // #define HFI_DELTA_CUR_MAG_POR_OK_AP 20 // unit: 0.01A, delta current for polarity detection ok
- // #define HFI_CUR_LPF_HZ 500 // unit: Hz, Cut-off frequency of current lpf
- // #define HFI_CUR_HPF_HZ 50 // unit: Hz, Cut-off frequency of current hpf
- // #define HFI_PLL_DAMPING_RATIO 35 // unit: Null, Pll damping ratio
- // #define HFI_PLL_CROSS_FREQ_HZ 20 // unit: Hz, Pll cross frequency
- // #define HFI_SPD_LPF_HZ 8 // unit: Hz, Cut-off frequency of spd lpf
- // #define HFI_MAG_SATR_AP 240 // unit: 0.01A, Magnetic saturation current
- /*==============================================================================
- Deadband Compensation parameters define
- ==============================================================================*/
- /* Api Device Index Definations */
- #define ADC_IA_CH 0
- #define ADC_IB_CH 1
- #define ADC_IC_CH 2
-
- #define ADC_IDC_CH 0
- #define ADC_UDC_CH 0
- #define ADC_TEMP_CH 1
- #define ADC_UAC_CH 2
- #define GPIO_LED_PIN 0
- #define GPIO_CAP_PIN 1
- /************************************************************************
- TypeDefs & Structure defines
- *************************************************************************/
- /************************************************************************
- Exported Variables:
- *************************************************************************/
- /************************************************************************
- RAM ALLOCATION:
- *************************************************************************/
- /************************************************************************
- Exported Function Call Prototypes (N/A)
- *************************************************************************/
- /************************************************************************
- Local Function Call Prototypes (N/A)
- *************************************************************************/
- /************************************************************************
- Head files (N/A)
- *************************************************************************/
- //#include <stdlib.h>
- #include "typedefine.h"
- #include "CodePara.h"
- #include "classB.h"
- #include "hwsetup.h"
- #include "board_config.h"
- #include "mathtool.h"
- #include "main.h"
- #include "spdctrFSM.h"
- #include "glbcof.h"
- #include "crdnt.h"
- #include "tbc.h"
- #include "tbs.h"
- #include "tbt.h"
- #include "alarm.h"
- #include "adc.h"
- #include "spi_master.h"
- #include "i2c_master.h"
- #include "spdctrmode.h"
- #include "acr.h"
- #include "asr.h"
- #include "torqobs.h"
- #include "obs.h"
- #include "dbc.h"
- #include "flxwkn.h"
- #include "pwm.h"
- #include "hfinj.h"
- #include "pwrlim.h"
- #include "bootloader.h"
- #include "brake.h"
- #include "uart_monitor.h"
- #include "macroequ.h"
- #include "alignstartup.h"
- #include "switchhall.h"
- /************************************************************************
- Flag Define (N/A)
- *************************************************************************/
- #ifdef __cplusplus
- }
- #endif // __cplusplus
- #endif
- /*************************************************************************
- Copyright (c) 2019 Welling Motor Technology(Shanghai) Co. Ltd.
- All rights reserved.
- *************************************************************************
- End of this File (EOF)!
- Do not put anything after this part!
- *************************************************************************/
|