position control added
This commit is contained in:
parent
ce627e4963
commit
797226616e
|
@ -35,7 +35,7 @@ void motor_StateMachine(BLDCMotor_t* const motor)
|
||||||
case MOTOR_IDLE:
|
case MOTOR_IDLE:
|
||||||
//hri_tcc_write_PATTBUF_reg(motor->motor_param->pwm_desc->device.hw, DISABLE_PATTERN);
|
//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.previousstate = motor->motor_state.currentstate;
|
||||||
motor->motor_state.currentstate = MOTOR_VI_CTRL_STATE;
|
motor->motor_state.currentstate = MOTOR_PVI_CTRL_STATE;
|
||||||
break;
|
break;
|
||||||
case MOTOR_OPEN_LOOP_STATE:
|
case MOTOR_OPEN_LOOP_STATE:
|
||||||
BLDC_runOpenLoop(motor, *M1_Desired_dc);
|
BLDC_runOpenLoop(motor, *M1_Desired_dc);
|
||||||
|
@ -51,42 +51,31 @@ void motor_StateMachine(BLDCMotor_t* const motor)
|
||||||
switch (motor->regulation_loop_count) {
|
switch (motor->regulation_loop_count) {
|
||||||
case 0: /* PWM FREQ / 25 - 1kHz */
|
case 0: /* PWM FREQ / 25 - 1kHz */
|
||||||
case 5: case 10: case 15: case 20:/* PWM FREQ / 5 - 5kHz */
|
case 5: case 10: case 15: case 20:/* PWM FREQ / 5 - 5kHz */
|
||||||
calculate_motor_speed(motor);
|
calculate_motor_speed(motor);
|
||||||
BLDC_runSpeedCntl(motor, (float32_t)motor->motor_status.calc_rpm, (float32_t)motor->motor_setpoints.desired_speed);
|
BLDC_runSpeedCntl(motor, (float32_t)motor->motor_status.calc_rpm, (float32_t)motor->motor_setpoints.desired_speed);
|
||||||
default: /* PWM FREQ - 25kHz */
|
default: /* PWM FREQ - 25kHz */
|
||||||
select_active_phase(motor);
|
select_active_phase(motor);
|
||||||
BLDC_runCurrentCntl(motor,(float32_t)motor->Iphase_pu.Bus, (float32_t)motor->controllers.Pi_Idc.Ref_pu);
|
BLDC_runCurrentCntl(motor,(float32_t)motor->Iphase_pu.Bus, (float32_t)motor->controllers.Pi_Idc.Ref_pu);
|
||||||
break;
|
break;
|
||||||
} // end switch(regulation_loop_count)
|
} // end switch(regulation_loop_count)
|
||||||
if(motor->regulation_loop_count > 23) motor->regulation_loop_count = 0;
|
if(motor->regulation_loop_count > 23) motor->regulation_loop_count = 0;
|
||||||
else motor->regulation_loop_count++;
|
else motor->regulation_loop_count++;
|
||||||
break;
|
break;
|
||||||
case MOTOR_PVI_CTRL_STATE:
|
case MOTOR_PVI_CTRL_STATE:
|
||||||
switch (Motor1.regulation_loop_count) {
|
switch (motor->regulation_loop_count) {
|
||||||
case 0: /* PWM FREQ / 25 - 1kHz */
|
case 0: /* PWM FREQ / 25 - 1kHz */
|
||||||
Motor1.timerflags.motor_telemetry_flag = true; // Update telemetry flag
|
BLDC_runPosCntl(motor, motor->motor_status.Num_Steps, motor->motor_setpoints.desired_position);
|
||||||
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);
|
|
||||||
|
|
||||||
case 5: case 10: case 15: case 20:/* PWM FREQ / 5 - 5kHz */
|
case 5: case 10: case 15: case 20:/* PWM FREQ / 5 - 5kHz */
|
||||||
|
calculate_motor_speed(motor);
|
||||||
//calculate_motor_speed(motor);
|
BLDC_runSpeedCntl(motor, (float32_t)motor->motor_status.calc_rpm, (float32_t)motor->controllers.Pid_Speed.Ref_pu);
|
||||||
//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);
|
|
||||||
|
|
||||||
default: /* PWM FREQ - 25kHz */
|
default: /* PWM FREQ - 25kHz */
|
||||||
select_active_phase(motor);
|
select_active_phase(motor);
|
||||||
//select_active_phase(&Motor2, Motor2.motor_status.currentHallPattern);
|
//select_active_phase(&Motor2, Motor2.motor_status.currentHallPattern);
|
||||||
|
BLDC_runCurrentCntl(motor, motor->Iphase_pu.Bus, motor->controllers.Pi_Idc.Ref_pu);
|
||||||
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);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
} // end switch(regulation_loop_count)
|
} // end switch(regulation_loop_count)
|
||||||
if(Motor1.regulation_loop_count > 23) Motor1.regulation_loop_count = 0;
|
if(motor->regulation_loop_count > 23) motor->regulation_loop_count = 0;
|
||||||
else Motor1.regulation_loop_count++;
|
else motor->regulation_loop_count++;
|
||||||
break;
|
break;
|
||||||
} //end switch (motor->motor_state.currentstate)
|
} //end switch (motor->motor_state.currentstate)
|
||||||
|
|
||||||
|
@ -220,13 +209,13 @@ void exec_commutation(BLDCMotor_t* const motor)
|
||||||
volatile uint8_t currentHall = motor->readHall();
|
volatile uint8_t currentHall = motor->readHall();
|
||||||
motor->motor_status.currentHallPattern = currentHall;
|
motor->motor_status.currentHallPattern = currentHall;
|
||||||
|
|
||||||
if ((currentHall == INVALID_HALL_0)||(currentHall == INVALID_HALL_7))
|
//if ((currentHall == INVALID_HALL_0)||(currentHall == INVALID_HALL_7))
|
||||||
{
|
//{
|
||||||
hri_tcc_write_PATTBUF_reg(motor->motor_param->pwm_desc->device.hw, DISABLE_PATTERN);
|
//hri_tcc_write_PATTBUF_reg(motor->motor_param->pwm_desc->device.hw, DISABLE_PATTERN);
|
||||||
motor->motor_state.currentstate == MOTOR_FAULT;
|
//motor->motor_state.currentstate == MOTOR_FAULT;
|
||||||
motor->motor_state.fault == MOTOR_HALLSENSORINVALID;
|
//motor->motor_state.fault == MOTOR_HALLSENSORINVALID;
|
||||||
return;
|
//return;
|
||||||
}
|
//}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// Set Pattern Buffers
|
// Set Pattern Buffers
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#include "statemachine.h"
|
#include "statemachine.h"
|
||||||
|
|
||||||
#define PWM_TOP (1000)
|
#define PWM_TOP (1000)
|
||||||
#define MAX_PWM (400)
|
#define MAX_PWM (300)
|
||||||
//#define MAX_VEL 3800
|
//#define MAX_VEL 3800
|
||||||
|
|
||||||
#define CW (0) //CBA
|
#define CW (0) //CBA
|
||||||
|
|
|
@ -181,17 +181,14 @@ int main(void)
|
||||||
|
|
||||||
/* Replace with your application code */
|
/* Replace with your application code */
|
||||||
while (1) {
|
while (1) {
|
||||||
//delay_ms(100);
|
|
||||||
//*M1_Motor__hallState = readM1Hall();
|
|
||||||
//*M2_Motor__hallState = readM2Hall();
|
|
||||||
//x += 1;
|
|
||||||
//comms_check();
|
|
||||||
//update_setpoints();
|
|
||||||
if (Motor1.timerflags.adc_readings_ready_tic) {process_currents();}
|
if (Motor1.timerflags.adc_readings_ready_tic) {process_currents();}
|
||||||
if (Motor1.timerflags.current_loop_tic) {APPLICATION_StateMachine();}
|
if (Motor1.timerflags.current_loop_tic) {
|
||||||
|
APPLICATION_StateMachine();
|
||||||
|
exec_commutation(&Motor1);
|
||||||
|
exec_commutation(&Motor2);
|
||||||
|
}
|
||||||
if (run_ECAT) {ECAT_STATE_MACHINE();}
|
if (run_ECAT) {ECAT_STATE_MACHINE();}
|
||||||
exec_commutation(&Motor1);
|
|
||||||
exec_commutation(&Motor2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -167,7 +167,7 @@ const static BLDCMotor_param_t FH_32mm24BXTR = {
|
||||||
.motor_Max_Spd_RPM = 3000,
|
.motor_Max_Spd_RPM = 3000,
|
||||||
.motor_MeasureRange_RPM = 3200, //(1.2f * MOTOR_MAX_SPD_RPM)f // give 20% headroom
|
.motor_MeasureRange_RPM = 3200, //(1.2f * MOTOR_MAX_SPD_RPM)f // give 20% headroom
|
||||||
.motor_Max_Spd_ELEC = 12000, //(MOTOR_MAX_SPD_RPM/60)*MOTOR_POLEPAIRS
|
.motor_Max_Spd_ELEC = 12000, //(MOTOR_MAX_SPD_RPM/60)*MOTOR_POLEPAIRS
|
||||||
.motor_Max_Current_IDC_A = 1.2,
|
.motor_Max_Current_IDC_A = 1.0,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* MOTORPARAMETERS_H_ */
|
#endif /* MOTORPARAMETERS_H_ */
|
Binary file not shown.
Loading…
Reference in New Issue