|
|
|
|
@@ -35,7 +35,7 @@ void motor_StateMachine(BLDCMotor_t* const motor)
|
|
|
|
|
case MOTOR_IDLE:
|
|
|
|
|
//hri_tcc_write_PATTBUF_reg(motor->motor_param->pwm_desc->device.hw, DISABLE_PATTERN);
|
|
|
|
|
motor->motor_state.previousstate = motor->motor_state.currentstate;
|
|
|
|
|
motor->motor_state.currentstate = MOTOR_VI_CTRL_STATE;
|
|
|
|
|
motor->motor_state.currentstate = MOTOR_PVI_CTRL_STATE;
|
|
|
|
|
break;
|
|
|
|
|
case MOTOR_OPEN_LOOP_STATE:
|
|
|
|
|
BLDC_runOpenLoop(motor, *M1_Desired_dc);
|
|
|
|
|
@@ -51,42 +51,31 @@ void motor_StateMachine(BLDCMotor_t* const motor)
|
|
|
|
|
switch (motor->regulation_loop_count) {
|
|
|
|
|
case 0: /* PWM FREQ / 25 - 1kHz */
|
|
|
|
|
case 5: case 10: case 15: case 20:/* PWM FREQ / 5 - 5kHz */
|
|
|
|
|
calculate_motor_speed(motor);
|
|
|
|
|
BLDC_runSpeedCntl(motor, (float32_t)motor->motor_status.calc_rpm, (float32_t)motor->motor_setpoints.desired_speed);
|
|
|
|
|
calculate_motor_speed(motor);
|
|
|
|
|
BLDC_runSpeedCntl(motor, (float32_t)motor->motor_status.calc_rpm, (float32_t)motor->motor_setpoints.desired_speed);
|
|
|
|
|
default: /* PWM FREQ - 25kHz */
|
|
|
|
|
select_active_phase(motor);
|
|
|
|
|
BLDC_runCurrentCntl(motor,(float32_t)motor->Iphase_pu.Bus, (float32_t)motor->controllers.Pi_Idc.Ref_pu);
|
|
|
|
|
select_active_phase(motor);
|
|
|
|
|
BLDC_runCurrentCntl(motor,(float32_t)motor->Iphase_pu.Bus, (float32_t)motor->controllers.Pi_Idc.Ref_pu);
|
|
|
|
|
break;
|
|
|
|
|
} // end switch(regulation_loop_count)
|
|
|
|
|
if(motor->regulation_loop_count > 23) motor->regulation_loop_count = 0;
|
|
|
|
|
else motor->regulation_loop_count++;
|
|
|
|
|
break;
|
|
|
|
|
case MOTOR_PVI_CTRL_STATE:
|
|
|
|
|
switch (Motor1.regulation_loop_count) {
|
|
|
|
|
switch (motor->regulation_loop_count) {
|
|
|
|
|
case 0: /* PWM FREQ / 25 - 1kHz */
|
|
|
|
|
Motor1.timerflags.motor_telemetry_flag = true; // Update telemetry flag
|
|
|
|
|
BLDC_runPosCntl(&Motor1, Motor1.motor_status.Num_Steps, Motor1.motor_setpoints.desired_position);
|
|
|
|
|
BLDC_runPosCntl(&Motor2, Motor1.motor_status.Num_Steps, Motor1.motor_setpoints.desired_position);
|
|
|
|
|
|
|
|
|
|
BLDC_runPosCntl(motor, motor->motor_status.Num_Steps, motor->motor_setpoints.desired_position);
|
|
|
|
|
case 5: case 10: case 15: case 20:/* PWM FREQ / 5 - 5kHz */
|
|
|
|
|
|
|
|
|
|
//calculate_motor_speed(motor);
|
|
|
|
|
//calculate_motor_speed();
|
|
|
|
|
|
|
|
|
|
BLDC_runSpeedCntl(&Motor1, Motor1.motor_status.calc_rpm, Motor1.controllers.Pid_Speed.Ref_pu);
|
|
|
|
|
BLDC_runSpeedCntl(&Motor2, Motor1.motor_status.calc_rpm, Motor1.controllers.Pid_Speed.Ref_pu);
|
|
|
|
|
|
|
|
|
|
calculate_motor_speed(motor);
|
|
|
|
|
BLDC_runSpeedCntl(motor, (float32_t)motor->motor_status.calc_rpm, (float32_t)motor->controllers.Pid_Speed.Ref_pu);
|
|
|
|
|
default: /* PWM FREQ - 25kHz */
|
|
|
|
|
select_active_phase(motor);
|
|
|
|
|
//select_active_phase(&Motor2, Motor2.motor_status.currentHallPattern);
|
|
|
|
|
|
|
|
|
|
BLDC_runCurrentCntl(&Motor1, Motor1.Iphase_pu.Bus, Motor1.controllers.Pi_Idc.Ref_pu);
|
|
|
|
|
BLDC_runCurrentCntl(&Motor2, Motor1.Iphase_pu.Bus, Motor1.controllers.Pi_Idc.Ref_pu);
|
|
|
|
|
|
|
|
|
|
select_active_phase(motor);
|
|
|
|
|
//select_active_phase(&Motor2, Motor2.motor_status.currentHallPattern);
|
|
|
|
|
BLDC_runCurrentCntl(motor, motor->Iphase_pu.Bus, motor->controllers.Pi_Idc.Ref_pu);
|
|
|
|
|
break;
|
|
|
|
|
} // end switch(regulation_loop_count)
|
|
|
|
|
if(Motor1.regulation_loop_count > 23) Motor1.regulation_loop_count = 0;
|
|
|
|
|
else Motor1.regulation_loop_count++;
|
|
|
|
|
if(motor->regulation_loop_count > 23) motor->regulation_loop_count = 0;
|
|
|
|
|
else motor->regulation_loop_count++;
|
|
|
|
|
break;
|
|
|
|
|
} //end switch (motor->motor_state.currentstate)
|
|
|
|
|
|
|
|
|
|
@@ -220,13 +209,13 @@ void exec_commutation(BLDCMotor_t* const motor)
|
|
|
|
|
volatile uint8_t currentHall = motor->readHall();
|
|
|
|
|
motor->motor_status.currentHallPattern = currentHall;
|
|
|
|
|
|
|
|
|
|
if ((currentHall == INVALID_HALL_0)||(currentHall == INVALID_HALL_7))
|
|
|
|
|
{
|
|
|
|
|
hri_tcc_write_PATTBUF_reg(motor->motor_param->pwm_desc->device.hw, DISABLE_PATTERN);
|
|
|
|
|
motor->motor_state.currentstate == MOTOR_FAULT;
|
|
|
|
|
motor->motor_state.fault == MOTOR_HALLSENSORINVALID;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//if ((currentHall == INVALID_HALL_0)||(currentHall == INVALID_HALL_7))
|
|
|
|
|
//{
|
|
|
|
|
//hri_tcc_write_PATTBUF_reg(motor->motor_param->pwm_desc->device.hw, DISABLE_PATTERN);
|
|
|
|
|
//motor->motor_state.currentstate == MOTOR_FAULT;
|
|
|
|
|
//motor->motor_state.fault == MOTOR_HALLSENSORINVALID;
|
|
|
|
|
//return;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
// Set Pattern Buffers
|
|
|
|
|
|