commutation in one direction works ok
This commit is contained in:
parent
639b562d2b
commit
9be08d33f1
|
@ -36,7 +36,7 @@
|
|||
<documentation help="" />
|
||||
<offline-documentation help="" />
|
||||
<dependencies>
|
||||
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.42.0" />
|
||||
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.43.0" />
|
||||
</dependencies>
|
||||
</framework-data>
|
||||
</AsfFrameworkConfig>
|
||||
|
|
|
@ -18,7 +18,7 @@ void BldcInitStruct(BLDCMotor_t *motor, BLDCMotor_param_t *motor_param)
|
|||
motor->motor_param = motor_param;
|
||||
motor->motor_status.actualDirection = 0;
|
||||
motor->motor_setpoints.desiredDirection = 0;
|
||||
motor->motor_status.duty_cycle = 150;
|
||||
motor->motor_status.duty_cycle = 100;
|
||||
motor->motor_status.calc_rpm = 0;
|
||||
motor->motor_status.Num_Steps = 0;
|
||||
motor->motor_status.cur_comm_step = 0;
|
||||
|
@ -103,6 +103,12 @@ void exec_commutation(BLDCMotor_t *motor)
|
|||
//tic_port(DEBUG_2_PORT);
|
||||
//motor->motor_status.currentHallPattern = readM1Hall();
|
||||
motor->motor_status.currentHallPattern = motor->readHall();
|
||||
if(motor->motor_status.currentHallPattern == INVALID_HALL_0 ||
|
||||
motor->motor_status.currentHallPattern == INVALID_HALL_7 ) {
|
||||
applicationStatus.fault = HALLSENSORINVALID;
|
||||
applicationStatus.currentstate = FAULT;
|
||||
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Multi Motor Register Masking
|
||||
|
@ -110,12 +116,14 @@ void exec_commutation(BLDCMotor_t *motor)
|
|||
//tic_port(DEBUG_2_PORT);
|
||||
//volatile uint16_t temp_M1 = COMMUTATION_PATTERN_M1[Motor1.motor_status.currentHallPattern + Motor1.motor_setpoints.directionOffset];
|
||||
//volatile uint16_t temp_M2 = COMMUTATION_PATTERN_M2[Motor2.motor_status.currentHallPattern + oh ];
|
||||
volatile uint16_t temp_M1 = COMMUTATION_PATTERN[motor->motor_status.currentHallPattern +
|
||||
motor->motor_setpoints.directionOffset];
|
||||
//volatile uint16_t temp_M1 = COMMUTATION_PATTERN[motor->motor_status.currentHallPattern +
|
||||
//motor->motor_setpoints.directionOffset];
|
||||
|
||||
volatile uint16_t temp_M1 = COMMUTATION_PATTERN[motor->motor_status.currentHallPattern + motor->motor_setpoints.directionOffset];
|
||||
// ----------------------------------------------------------------------
|
||||
// Set Pattern Buffers
|
||||
// ----------------------------------------------------------------------
|
||||
hri_tcc_write_PATTBUF_reg(motor->motor_param->pwm_desc->device.hw, (hri_tcc_pattbuf_reg_t)temp_M1);
|
||||
hri_tcc_write_PATTBUF_reg(motor->motor_param->pwm_desc->device.hw, temp_M1);
|
||||
//(Tcc *)(motor->motor_param.pwm_desc->device.hw)->PATTBUF.reg = temp_M1;
|
||||
//TCC0->PATTBUF.reg = (uint16_t)temp_M2;
|
||||
//TCC1->PATTBUF.reg = (uint16_t)temp_M1;
|
||||
|
@ -132,12 +140,12 @@ void exec_commutation(BLDCMotor_t *motor)
|
|||
|
||||
switch(step_change1)
|
||||
{
|
||||
case 1: case -5:
|
||||
case -1: case 5:
|
||||
motor->motor_status.Num_Steps = motor->motor_status.Num_Steps+1;
|
||||
motor->motor_status.actualDirection = CW;
|
||||
//Motor1.motor_setpoints.directionOffset = DIRECTION_CW_OFFSET;
|
||||
break;
|
||||
case -1: case 5:
|
||||
case 1: case -5:
|
||||
motor->motor_status.Num_Steps = motor->motor_status.Num_Steps-1;
|
||||
motor->motor_status.actualDirection = CCW;
|
||||
//Motor1.motor_setpoints.directionOffset = DIRECTION_CCW_OFFSET;
|
||||
|
@ -327,9 +335,9 @@ uint8_t readHallSensorM1(void)
|
|||
volatile uint8_t b = gpio_get_pin_level(M1_HALL_B_PIN);
|
||||
volatile uint8_t c = gpio_get_pin_level(M1_HALL_C_PIN);
|
||||
|
||||
return ((a << 2) |
|
||||
return ((c << 2) |
|
||||
(b << 1) |
|
||||
(c << 0));
|
||||
(a << 0));
|
||||
|
||||
}
|
||||
|
||||
|
@ -339,7 +347,7 @@ uint8_t readHallSensorM2(void)
|
|||
volatile uint8_t b = gpio_get_pin_level(M2_HALL_B_PIN);
|
||||
volatile uint8_t c = gpio_get_pin_level(M2_HALL_C_PIN);
|
||||
|
||||
return ((a << 2) |
|
||||
return ((c << 2) |
|
||||
(b << 1) |
|
||||
(c << 0));
|
||||
(a << 0));
|
||||
}
|
|
@ -62,8 +62,9 @@
|
|||
// global variables
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
static const uint8_t HALL_PATTERN_ARRAY[16] = {0, 5, 3, 1, 6, 4, 2, 0, 0, 3, 6, 2, 5, 1, 4, 0 };
|
||||
//static const uint8_t HALL_PATTERN_ARRAY[16] = {0, 5, 3, 1, 6, 4, 2, 0, 0, 3, 6, 2, 5, 1, 4, 0 };
|
||||
static const uint8_t MOTOR_COMMUTATION_STEPS[8] = {9, 1, 3, 2, 5, 6, 4, 9};
|
||||
//static const uint8_t MOTOR_COMMUTATION_STEPS[8] = {9, 1, 3, 2, 6, 4, 5, 9};
|
||||
|
||||
volatile BLDCMotor_t Motor1;
|
||||
volatile BLDCMotor_t Motor2;
|
||||
|
@ -90,67 +91,4 @@ static void SetDutyCycle(const uint16_t duty);
|
|||
uint8_t readHallSensorM1(void);
|
||||
uint8_t readHallSensorM2(void);
|
||||
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Inline Functions, hoping for in lining and faster execution
|
||||
// ----------------------------------------------------------------------
|
||||
static inline uint8_t readM1Hall(void)
|
||||
{
|
||||
//volatile uint8_t motor_read = 0;
|
||||
//motor_read = (motor_read & M1_HALL_A_MASK) | (uint8_t)((PORT->Group[M1_HALL_A_GROUP].IN.reg & M1_HALL_A_PORT)>>(M1_HALL_A_LSR));
|
||||
//motor_read = (motor_read & M1_HALL_B_MASK) | (uint8_t)((PORT->Group[M1_HALL_B_GROUP].IN.reg & M1_HALL_B_PORT)>>(M1_HALL_B_LSR));
|
||||
//motor_read = (motor_read & M1_HALL_C_MASK) | (uint8_t)((PORT->Group[M1_HALL_C_GROUP].IN.reg & M1_HALL_C_PORT)>>(M1_HALL_C_LSR));
|
||||
//
|
||||
//return motor_read;
|
||||
volatile uint8_t a = gpio_get_pin_level(M1_HALL_A_PIN);
|
||||
volatile uint8_t b = gpio_get_pin_level(M1_HALL_B_PIN);
|
||||
volatile uint8_t c = gpio_get_pin_level(M1_HALL_C_PIN);
|
||||
|
||||
return ((a << 2) |
|
||||
(b << 1) |
|
||||
(c << 0));
|
||||
|
||||
}
|
||||
|
||||
static inline uint8_t readM2Hall(void)
|
||||
{
|
||||
//volatile uint8_t motor_read = 0;
|
||||
//motor_read = (motor_read & M2_HALL_A_MASK) | (uint8_t)((PORT->Group[M2_HALL_A_GROUP].IN.reg & M2_HALL_A_PORT)>>(M2_HALL_A_LSR));
|
||||
//motor_read = (motor_read & M2_HALL_B_MASK) | (uint8_t)((PORT->Group[M2_HALL_B_GROUP].IN.reg & M2_HALL_B_PORT)>>(M2_HALL_B_LSR));
|
||||
//motor_read = (motor_read & M2_HALL_C_MASK) | (uint8_t)((PORT->Group[M2_HALL_C_GROUP].IN.reg & M2_HALL_C_PORT)>>(M2_HALL_C_LSR));
|
||||
//
|
||||
//return motor_read;
|
||||
|
||||
|
||||
volatile uint8_t a = gpio_get_pin_level(M2_HALL_A_PIN);
|
||||
volatile uint8_t b = gpio_get_pin_level(M2_HALL_B_PIN);
|
||||
volatile uint8_t c = gpio_get_pin_level(M2_HALL_C_PIN);
|
||||
|
||||
return ((a << 2) |
|
||||
(b << 1) |
|
||||
(c << 0));
|
||||
}
|
||||
|
||||
//static inline uint8_t read_hall_pattern(BLDCMotor_t *motor)
|
||||
//{
|
||||
////volatile uint8_t motor_read = 0;
|
||||
////motor_read = (motor_read & M2_HALL_A_MASK) | (uint8_t)((PORT->Group[M2_HALL_A_GROUP].IN.reg & M2_HALL_A_PORT)>>(M2_HALL_A_LSR));
|
||||
////motor_read = (motor_read & M2_HALL_B_MASK) | (uint8_t)((PORT->Group[M2_HALL_B_GROUP].IN.reg & M2_HALL_B_PORT)>>(M2_HALL_B_LSR));
|
||||
////motor_read = (motor_read & M2_HALL_C_MASK) | (uint8_t)((PORT->Group[M2_HALL_C_GROUP].IN.reg & M2_HALL_C_PORT)>>(M2_HALL_C_LSR));
|
||||
////
|
||||
////return motor_read;
|
||||
//
|
||||
//Motor1.
|
||||
//
|
||||
//volatile uint8_t a = gpio_get_pin_level(motor->motor_param->hallPins.hallA);
|
||||
////volatile uint8_t b = gpio_get_pin_level(motor->motor_param->hallsensors[1]);
|
||||
////volatile uint8_t c = gpio_get_pin_level(motor->motor_param->hallsensors[2]);
|
||||
////
|
||||
////return ((a << 2) |
|
||||
////(b << 1) |
|
||||
////(c << 0));
|
||||
//}
|
||||
|
||||
#endif /* BLDC_H_ */
|
|
@ -68,7 +68,7 @@ volatile typedef struct
|
|||
volatile uint8_t actualDirection; //! The actual direction of rotation.
|
||||
volatile uint16_t duty_cycle;
|
||||
volatile float32_t calc_rpm;
|
||||
volatile int32_t* Num_Steps;
|
||||
volatile int32_t Num_Steps;
|
||||
/* Hall States */
|
||||
volatile uint8_t prevHallPattern;
|
||||
volatile uint8_t currentHallPattern;
|
||||
|
|
|
@ -14,20 +14,20 @@
|
|||
// M1 Hall Parameters
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
#define M1_HALL_A_PIN GPIO(GPIO_PORTA, 22)
|
||||
#define M1_HALL_A_PORT PORT_PA22
|
||||
#define M1_HALL_A_PIN GPIO(GPIO_PORTA, 4)
|
||||
#define M1_HALL_A_PORT PORT_PA04
|
||||
#define M1_HALL_A_MASK ~(1<<0)
|
||||
#define M1_HALL_A_LSR M1_HALL_A_PIN - M1_HALL_A_GROUP*32 -0
|
||||
#define M1_HALL_A_GROUP M1_HALL_A_PIN/32
|
||||
|
||||
#define M1_HALL_B_PIN GPIO(GPIO_PORTA, 23)
|
||||
#define M1_HALL_B_PORT PORT_PA23
|
||||
#define M1_HALL_B_PIN GPIO(GPIO_PORTA, 5)
|
||||
#define M1_HALL_B_PORT PORT_PA05
|
||||
#define M1_HALL_B_MASK ~(1<<1)
|
||||
#define M1_HALL_B_LSR M1_HALL_B_PIN - M1_HALL_B_GROUP*32 -1
|
||||
#define M1_HALL_B_GROUP M1_HALL_B_PIN/32
|
||||
|
||||
#define M1_HALL_C_PIN GPIO(GPIO_PORTA, 24)
|
||||
#define M1_HALL_C_PORT PORT_PA24
|
||||
#define M1_HALL_C_PIN GPIO(GPIO_PORTA, 6)
|
||||
#define M1_HALL_C_PORT PORT_PA06
|
||||
#define M1_HALL_C_MASK ~(1<<2)
|
||||
#define M1_HALL_C_LSR M1_HALL_C_PIN - M1_HALL_C_GROUP*32 -2
|
||||
#define M1_HALL_C_GROUP M1_HALL_C_PIN/32
|
||||
|
@ -36,24 +36,26 @@
|
|||
// M2 Hall Parameters
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
#define M2_HALL_A_PIN GPIO(GPIO_PORTA, 4)
|
||||
#define M2_HALL_A_PORT PORT_PA04
|
||||
#define M2_HALL_A_PIN GPIO(GPIO_PORTA, 22)
|
||||
#define M2_HALL_A_PORT PORT_PA22
|
||||
#define M2_HALL_A_MASK ~(1<<0)
|
||||
#define M2_HALL_A_LSR M2_HALL_A_PIN - M2_HALL_A_GROUP*32 -0
|
||||
#define M2_HALL_A_GROUP M2_HALL_A_PIN/32
|
||||
|
||||
#define M2_HALL_B_PIN GPIO(GPIO_PORTA, 5)
|
||||
#define M2_HALL_B_PORT PORT_PA05
|
||||
#define M2_HALL_B_PIN GPIO(GPIO_PORTA, 23)
|
||||
#define M2_HALL_B_PORT PORT_PA23
|
||||
#define M2_HALL_B_MASK ~(1<<1)
|
||||
#define M2_HALL_B_LSR M2_HALL_B_PIN - M2_HALL_B_GROUP*32 -1
|
||||
#define M2_HALL_B_GROUP M2_HALL_B_PIN/32
|
||||
|
||||
#define M2_HALL_C_PIN GPIO(GPIO_PORTA, 6)
|
||||
#define M2_HALL_C_PORT PORT_PA06
|
||||
#define M2_HALL_C_PIN GPIO(GPIO_PORTA, 24)
|
||||
#define M2_HALL_C_PORT PORT_PA24
|
||||
#define M2_HALL_C_MASK ~(1<<2)
|
||||
#define M2_HALL_C_LSR M2_HALL_C_PIN - M2_HALL_C_GROUP*32 -2
|
||||
#define M2_HALL_C_GROUP M2_HALL_C_PIN/32
|
||||
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
// Commutation Patterns
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -69,25 +71,67 @@
|
|||
** W7 | M1_0 | CC0 || M2_0 | CC0 |
|
||||
*/
|
||||
|
||||
static const uint16_t COMMUTATION_PATTERN[16] = {
|
||||
0x00FF, // (0) invalid state
|
||||
0x303B, // (1)
|
||||
0x183D, // (2)
|
||||
0x283B, // (3)
|
||||
0x283E, // (4)
|
||||
0x183E, // (5)
|
||||
0x303D, // (6)
|
||||
0x00FF, // (7) invalid state
|
||||
0x00FF, // (8) invalid state
|
||||
0x303D, // (9)
|
||||
0x183E, // (10)
|
||||
0x283E, // (11)
|
||||
0x283B, // (12)
|
||||
0x183D, // (13)
|
||||
0x303B, // (14)
|
||||
0x00FF // (15) invalid state
|
||||
/* CCW from Back - works best in forward diraction*/
|
||||
static const uint16_t COMMUTATION_PATTERN[] = {
|
||||
0x003F, // (0) invalid state
|
||||
0x053D, // (1)
|
||||
0x1437, // (2)
|
||||
0x113D, // (3)
|
||||
0x111F, // (4)
|
||||
0x141F, // (5)
|
||||
0x0537, // (6)
|
||||
0x003F, // (7) invalid state
|
||||
0x003F, // (8) invalid state
|
||||
0x0537, // (9)
|
||||
0x141F, // (10)
|
||||
0x111F, // (11)
|
||||
0x113D, // (12)
|
||||
0x1437, // (13)
|
||||
0x053D, // (14)
|
||||
0x003F // (15) invalid state
|
||||
};
|
||||
|
||||
////* CW From Back */
|
||||
//static const uint16_t COMMUTATION_PATTERN[16] = {
|
||||
//0x003F, // (0) invalid state
|
||||
//0x0537, // (1)
|
||||
//0x141F, // (2)
|
||||
//0x111F, // (3)
|
||||
//0x113D, // (4)
|
||||
//0x1437, // (5)
|
||||
//0x053D, // (6)
|
||||
//0x003F, // (7) invalid state
|
||||
//0x003F, // (8) invalid state
|
||||
//0x053D, // (9)
|
||||
//0x1437, // (10)
|
||||
//0x113D, // (11)
|
||||
//0x111F, // (12)
|
||||
//0x141F, // (13)
|
||||
//0x0537, // (14)
|
||||
//0x003F // (15) invalid state
|
||||
//};
|
||||
|
||||
////* CW From Back */
|
||||
//static const uint16_t COMMUTATION_PATTERN[16] = {
|
||||
//0x003F, // (0) invalid state
|
||||
//0x0537, // (1)
|
||||
//0x141F, // (2)
|
||||
//0x111F, // (3)
|
||||
//0x113D, // (4)
|
||||
//0x1437, // (5)
|
||||
//0x053D, // (6)
|
||||
//0x003F, // (7) invalid state
|
||||
//0x003F, // (8) invalid state
|
||||
//0x0537, // (9)
|
||||
//0x053D, // (10)
|
||||
//0x1437, // (11)
|
||||
//0x113D, // (12)
|
||||
//0x111F, // (13)
|
||||
//0x141F, // (14)
|
||||
//0x003F // (15) invalid state
|
||||
//};
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t hallA;
|
||||
|
|
Loading…
Reference in New Issue