25int32_t Vdc_Ad_Forced_Value[2];
26int32_t Iu_Ad_Forced_Value[2];
27int32_t Iv_Ad_Forced_Value[2];
28int32_t Iw_Ad_Forced_Value[2];
29int32_t Vu_Ad_Forced_Value[2];
30int32_t Vv_Ad_Forced_Value[2];
31int32_t Vw_Ad_Forced_Value[2];
35#define POLE_UP DutyPwm.UP
36#define POLE_UN DutyPwm.UN
37#define POLE_VP DutyPwm.VP
38#define POLE_VN DutyPwm.VN
39#define POLE_WP DutyPwm.WP
40#define POLE_WN DutyPwm.WN
44#define PATTERN_BEMF_U_MASK (0x04)
45#define PATTERN_BEMF_V_MASK (0x02)
46#define PATTERN_BEMF_W_MASK (0x01)
141const uint8_t
TrapSlessBemfSeqCW[][2] = {{5,4},{4,6},{6,2},{2,3},{3,1},{1,5}};
143const uint8_t
TrapSlessBemfSeqCCW[][2] = {{4,5},{5,1},{1,3},{3,2},{2,6},{6,4}};
171static uint16_t surgeCounter = 1000;
206 ParamSpdCalcNum = GET_PARAM_FXP(((int64_t)K2_SPEED_CALC_BASE),K2_SPD_RAD_BASE);
223 uint8_t pattern_after_zc, pattern_before_zc, idx;
231 if(idx == 0) idx = 5;
262 else if(dir == ROT_CCW) {
349 else if (dir == ROT_CCW) {
427 if (CmtNum > 5) CmtNum = 5;
438 static uint8_t nextCmtPattern;
442 uint8_t BemfPattterAfterZc;
443 int32_t tmp32, factor_sub;
444 uint32_t TimeCntBemf;
447 Feedbacks__Handler();
586 if(tmp_s8 < 0) tmp_s8 = 6 - (256 - tmp_s8);
633 if(factor_sub < 1) factor_sub = 1;
696 int32_t save_speedRad;
698 static uint32_t TimeoutBootStrap;
706 case STATE_TRAP_IDLE:
715 TimeoutBootStrap = 500*0;
728 if(surgeCounter) surgeCounter--;
740 case STATE_TRAP_BOOT:
751 if(TimeoutBootStrap) TimeoutBootStrap--;
770 case STATE_TRAP_CLOSEDLOOP:
851 else response = response & ~PATTERN_BEMF_U_MASK;
853 else response = response & ~PATTERN_BEMF_V_MASK;
855 else response = response & ~PATTERN_BEMF_W_MASK;
944 if(tmp32 == 0) tmp32 = 1;
972 SRMCPWM_LOADPWM[0]((K2_TRAP_PWM_MAX_MINUS_DT_CNTS-
TrapSlessData.
dutyOut),K2_TRAP_PWM_HALF_MAX_CNTS, K2_TRAP_PWM_HALF_MAX_CNTS);
975 SRMCPWM_LOADPWM[0](K2_TRAP_PWM_HALF_MAX_CNTS,
TrapSlessData.
dutyOut, K2_TRAP_PWM_HALF_MAX_CNTS);
977 SRMCPWM_LOADPWM[0](K2_TRAP_PWM_HALF_MAX_CNTS, (K2_TRAP_PWM_MAX_MINUS_DT_CNTS-
TrapSlessData.
dutyOut), K2_TRAP_PWM_HALF_MAX_CNTS);
980 SRMCPWM_LOADPWM[0](K2_TRAP_PWM_HALF_MAX_CNTS, K2_TRAP_PWM_HALF_MAX_CNTS,
TrapSlessData.
dutyOut);
982 SRMCPWM_LOADPWM[0](K2_TRAP_PWM_HALF_MAX_CNTS, K2_TRAP_PWM_HALF_MAX_CNTS, (K2_TRAP_PWM_MAX_MINUS_DT_CNTS-
TrapSlessData.
dutyOut));
1005 if(tmp <= 0) tmp = 1;
1031 if(propsum > limit) propsum = limit;
1042 if(propsum < 0) propsum = 0;
1053 int32_t curr_a, curr_b, curr_c, curr_bus;
1056 #define K_BUS_CURRENT_SCALING (20.0f/4095.0f)
1058 TrapSlessData.
bus_curr = (int32_t)(Iu_Ad_Forced_Value[0] * (K_BUS_CURRENT_SCALING * 32768 / K2_CURR_BASE));
1069 if (curr_a < 0) curr_a = -curr_a;
1070 if (curr_b < 0) curr_b = -curr_b;
1071 if (curr_c < 0) curr_c = -curr_c;
1073 if(curr_a > curr_bus) {
1076 if(curr_c > curr_bus) {
1089 TrapSlessData.
va = (int32_t)( ((float32_t)Vu_Ad_Forced_Value[0] * ( (int32_t)(FACTOR_AD_COUNT_TO_DC_BUS_0 * 32768.0f))) / K2_VOLT_BASE);
1090 TrapSlessData.
vb = (int32_t)( ((float32_t)Vv_Ad_Forced_Value[0] * ( (int32_t)(FACTOR_AD_COUNT_TO_DC_BUS_0 * 32768.0f))) / K2_VOLT_BASE);
1091 TrapSlessData.
vc = (int32_t)( ((float32_t)Vw_Ad_Forced_Value[0] * ( (int32_t)(FACTOR_AD_COUNT_TO_DC_BUS_0 * 32768.0f))) / K2_VOLT_BASE);
1105 static uint32_t CntLast;
1124 uint8_t nextCmtPattern;
1213 XBAR->PR_CFG = PR_CFG_UVW_STATE_HI_DL_FL;
1214 GPIO_UVW_STATE_HI_DL_FL();
1217 XBAR->PR_CFG = PR_CFG_UVW_STATE_DH_LO_FL;
1218 GPIO_UVW_STATE_DH_LO_FL();
1221 XBAR->PR_CFG = PR_CFG_UVW_STATE_DH_FL_LO;
1222 GPIO_UVW_STATE_DH_FL_LO();
1225 XBAR->PR_CFG = PR_CFG_UVW_STATE_HI_FL_DL;
1226 GPIO_UVW_STATE_HI_FL_DL();
1229 XBAR->PR_CFG = PR_CFG_UVW_STATE_FL_HI_DL;
1230 GPIO_UVW_STATE_FL_HI_DL();
1233 XBAR->PR_CFG = PR_CFG_UVW_STATE_FL_DH_LO;
1234 GPIO_UVW_STATE_FL_DH_LO();
1237 XBAR->PR_CFG = PR_CFG_UVW_STATE_LO_DH_FL;
1238 GPIO_UVW_STATE_LO_DH_FL();
1241 XBAR->PR_CFG = PR_CFG_UVW_STATE_DL_HI_FL;
1242 GPIO_UVW_STATE_DL_HI_FL();
1245 XBAR->PR_CFG = PR_CFG_UVW_STATE_DL_FL_HI;
1246 GPIO_UVW_STATE_DL_FL_HI();
1249 XBAR->PR_CFG = PR_CFG_UVW_STATE_LO_FL_DH;
1250 GPIO_UVW_STATE_LO_FL_DH();
1253 XBAR->PR_CFG = PR_CFG_UVW_STATE_FL_LO_DH;
1254 GPIO_UVW_STATE_FL_LO_DH();
1257 XBAR->PR_CFG = PR_CFG_UVW_STATE_FL_DL_HI;
1258 GPIO_UVW_STATE_FL_DL_HI();
1261 XBAR->PR_CFG = PR_CFG_UVW_STATE_FL_FL_FL;
1262 GPIO_UVW_STATE_FL_FL_FL();
1265 XBAR->PR_CFG = PR_CFG_UVW_STATE_LO_LO_LO;
1266 GPIO_UVW_STATE_LO_LO_LO();
1306 tmp2 -= (tmp1 >> 16);
1318 tmp2 -= (tmp1 >> 16);
1331 tmp2 -= (tmp1 >> 16);
uint16_t ADC_Samples[NUM_ADC_SAMPLES]
void LSI__Load_On(LOAD_NAME_TYPE load)
It turns on the select load.
void LSI__Load_Off(LOAD_NAME_TYPE load)
It turns off the select load.
void TrapSless__SlowHandler()
Handler for Trapezoidal control - 1KHz call rate.
mc_t ParamMaxPreCarrierCnt
const uint8_t PortStateCCW[8][2]
const uint8_t TrapSlessBemfSeqCW[][2]
#define PATTERN_BEMF_U_MASK
void TrapSless__SetSpd(int32_t spd_rpm, int32_t ramp_rpm)
BLDC motor rotation command.
uint8_t TrapSless__GetBemfFromCmt(uint8_t dir, uint8_t CmtNum, uint8_t after_zc)
Returns the bemf pattern given a commutation index.
mc_t ParamMinPreCarrierCnt
void TrapSless__ResetVars()
Resetting of trapezoidal key variables.
int32_t TrapSless__CalcSpeed()
Speed computation based on Bemf Zcross events.
volatile uint8_t AUTO_COMM_CNTER
const uint8_t TrapSlessBemfSeqCCW[][2]
uint8_t TrapSless__GetBemfToNum(uint8_t bemf, uint8_t after_zc, uint8_t dir)
Returns the index of the given bemf pattern.
TRAPSLESS_PATTERN_TYPE * TrapSless__GetVars(void)
Obtaine the trapezoidal variables.
void TrapSless__Init(void)
Initialization of TrapSless module.
uint8_t TrapSless__GetBemfSignal(int32_t va, int32_t vb, int32_t vc)
Returns the bemf pattern based on pole voltage reading [a,b,c].
uint32_t ParamOpenLoopSpdBemfCntVar
void TrapSless__BemfCnterUpdate(void)
Accumulate the counter for bemf.
const uint8_t TrapSlessNxtCmtSeqCCW[]
void TrapSless__SetPatternAndPwm(uint8_t after_zc)
Set pwm duty cycle and output pattern.
uint32_t PwmMaxMinusDtCnts
uint8_t TrapSless__GetCmtToNum(uint8_t cmt, uint8_t dir)
Returns the index of the given commutation pattern For CW rotation the index matches the commutation ...
uint8_t TrapSless__GetCmtFromBemf(uint8_t dir, uint8_t bemf, uint8_t after_zc)
Returns the commutation pattern given a bemf pattern.
uint32_t ParamMaxSpdBemfCnt
const uint8_t TrapSlessNxtCmtSeqCW[]
volatile uint8_t AUTO_COMM_CNTER_BREAK
void TrapSless__SetVbusIbus(void)
Read ADC and Set Vbus and Ibus variables.
void outputPwmExec()
Update the pwm outputs.
TRAPSLESS_PATTERN_TYPE TrapSlessData
void decodeOutput(UVW_STATE_TYPE state)
Set the outputs according to the pole voltage state.
#define PATTERN_BEMF_W_MASK
const uint8_t TrapSlessCmtSeqCCW[]
void TrapSless__Handler()
Handler for Trapezoidal control - 16KHz call rate.
void TrapSless__ExecuteCmt(void)
Execution of commutation.
const uint8_t TrapSlessCmtSeqCW[]
#define PATTERN_BEMF_V_MASK
uint32_t ParamOpenLoopSpdBemfCnt
void TrapSless__SetPwm(void)
Set pwm duty cycle.
const uint8_t PortStateCW[8][2]
uint8_t TrapSless__GetTooEarly(void)
Too early detection mechanism For every commutation there is an expected zcross at a given phase....
void TrapSless__PiCalc(int32_t curr_clamp)
Pi regulator If curr_clamp is different than zero, then only runs the clamp algorithm If curr_clamp i...
void TrapSless__SetVabc(void)
Read ADC and set pole voltage variables.
uint32_t openLoopPatternTimeCnt
uint8_t actual_bemf_pattern
uint32_t blankTimeDownCnter
uint32_t TimeoutToolateForCmt
uint32_t openLoopTimeThld
uint32_t TimeoutForCmtSaved