initial branch commit
This commit is contained in:
parent
e533db6ce8
commit
db49ec9cf3
|
@ -0,0 +1,23 @@
|
|||
|
||||
## Ignore Atmel Studio temporary files and build results
|
||||
# https://www.microchip.com/mplab/avr-support/atmel-studio-7
|
||||
|
||||
# Atmel Studio is powered by an older version of Visual Studio,
|
||||
# so most of the project and solution files are the same as VS files,
|
||||
# only prefixed by an `at`.
|
||||
|
||||
#Build Directories
|
||||
[Dd]ebug/
|
||||
[Rr]elease/
|
||||
|
||||
#Build Results
|
||||
*.o
|
||||
*.d
|
||||
*.eep
|
||||
*.elf
|
||||
*.hex
|
||||
*.map
|
||||
*.srec
|
||||
|
||||
#User Specific Files
|
||||
*.atsuo
|
Binary file not shown.
|
@ -1011,6 +1011,9 @@
|
|||
<Compile Include="main.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="motor_params.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="pins.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
|
|
|
@ -79,7 +79,7 @@ void BLDC_init(BLDCMotor_t *motor)
|
|||
|
||||
motor->VdcBus_pu = DEVICE_DC_VOLTAGE_V;
|
||||
motor->VoneByDcBus_pu = 1.0f/DEVICE_DC_VOLTAGE_V;
|
||||
motor->motor_commutation_Pattern = COMMUTATION_PATTERN;
|
||||
motor->motor_commutation_Pattern = COMMUTATION_PATTERN_M1;
|
||||
|
||||
motor->desired_torque = 0.0;
|
||||
motor->desired_speed = 0;
|
||||
|
@ -225,7 +225,7 @@ void exec_commutation(void)
|
|||
//}
|
||||
|
||||
|
||||
TCC1->PATTBUF.reg = COMMUTATION_PATTERN[(Motor1.currentHallPattern + Motor1.directionOffset)];
|
||||
TCC1->PATTBUF.reg = COMMUTATION_PATTERN_M1[(Motor1.currentHallPattern + Motor1.directionOffset)];
|
||||
TCC1->CCBUF->reg = (uint16_t)Motor1.duty_cycle;
|
||||
//hri_tcc_write_PATTBUF_reg(TCC1, (COMMUTATION_PATTERN[(Motor1.currentHallPattern + Motor1.directionOffset)]));
|
||||
|
||||
|
|
|
@ -14,31 +14,7 @@
|
|||
#include "arm_math.h"
|
||||
#include "atmel_start.h"
|
||||
#include "control.h"
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Current Sensor
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
#define DRV_ISEN_A_CH ADC_INPUTCTRL_MUXPOS_AIN2_Val
|
||||
#define DRV_ISEN_B_CH ADC_INPUTCTRL_MUXPOS_AIN1_Val
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Hall Parameters
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
#define HALL_A_PIN GPIO(GPIO_PORTA, 6)
#define HALL_A_PORT PORT_PA06
#define HALL_A_MASK ~(1<<2)
#define HALL_A_LSR HALL_A_PIN - HALL_A_GROUP*32 -2
|
||||
#define HALL_A_GROUP HALL_A_PIN/32
#define HALL_B_PIN GPIO(GPIO_PORTA, 5)
|
||||
#define HALL_B_PORT PORT_PA05
|
||||
#define HALL_B_MASK ~(1<<1)
|
||||
#define HALL_B_LSR HALL_B_PIN - HALL_B_GROUP*32 -1
|
||||
#define HALL_B_GROUP HALL_B_PIN/32
|
||||
|
||||
#define HALL_C_PIN GPIO(GPIO_PORTA, 4)
|
||||
#define HALL_C_PORT PORT_PA04
|
||||
#define HALL_C_MASK ~(1<<0)
|
||||
#define HALL_C_LSR HALL_C_PIN - HALL_C_GROUP*32 -0
|
||||
#define HALL_C_GROUP HALL_C_PIN/32
|
||||
#include "motor_params.h"
|
||||
|
||||
/* if the Hall sensor reads 0x0 or 0x7 that means either one of the hall sensor is damaged or disconnected*/
|
||||
#define INVALID_HALL_0 (0U)
|
||||
|
@ -51,37 +27,6 @@
|
|||
#define ADC_RESOLUTION (12)
|
||||
#define ADC_MAX_COUNTS (1<<ADC_RESOLUTION)
|
||||
#define ADC_LSB_SIZE (ADC_VOLTAGE_REFERENCE/ADC_MAX_COUNTS)
|
||||
// ----------------------------------------------------------------------
|
||||
// Motor Parameters
|
||||
// ----------------------------------------------------------------------
|
||||
// these values fit for an Faulhaber 3216W024BXTR motor
|
||||
#define MOTOR_POLES (14U)
|
||||
#define MOTOR_POLEPAIRS (MOTOR_POLES/2)
|
||||
#define MOTOR_COMUTATION_STATES (MOTOR_POLEPAIRS*6)
|
||||
#define MOTOR_RS_OHM (3.37f)
|
||||
#define MOTOR_LD_H (0.001290f)
|
||||
#define MOTOR_LQ_H (0.001290f)
|
||||
#define MOTOR_FLUX_WB (0.0063879968f)
|
||||
#define MOTOR_MAX_SPD_RPM (4200.0f)
|
||||
#define MOTOR_MAX_SPD_ELEC ((MOTOR_MAX_SPD_RPM/60)*MOTOR_POLEPAIRS)
|
||||
#define MOTOR_MEASURINGRANGE_RPM (1.2f * MOTOR_MAX_SPD_RPM)f // give 20% headroom
|
||||
#define MOTOR_MAX_CURRENT_IDC_A (1.2f)
|
||||
|
||||
#define PWM_TOP 1000
|
||||
#define MAX_PWM 700
|
||||
#define MAX_VEL 3800
|
||||
|
||||
#define CW 0 //CBA
|
||||
#define DIRECTION_CW_OFFSET 0 //CBA
|
||||
#define CCW 1 //ABC
|
||||
#define DIRECTION_CCW_OFFSET 8 //CBA
|
||||
|
||||
#define AVERAGE_SPEED_MEASURE
|
||||
#define COUNTEQUIVTO25RPM 892857142
|
||||
#define n_SAMPLE 8
|
||||
static uint32_t speed_average = 0;
|
||||
static uint8_t count = 1;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Define the control and PWM frequencies:
|
||||
|
@ -137,8 +82,8 @@ volatile typedef struct
|
|||
volatile typedef struct BLDCmotor
|
||||
{
|
||||
/* Hardware */
|
||||
const Tcc * hw;
|
||||
uint16_t * motor_commutation_Pattern;
|
||||
const Tcc *hw;
|
||||
uint16_t *motor_commutation_Pattern;
|
||||
/* Status */
|
||||
volatile uint8_t actualDirection; //! The actual direction of rotation.
|
||||
volatile uint8_t desiredDirection; //! The desired direction of rotation.
|
||||
|
@ -182,34 +127,12 @@ volatile typedef struct BLDCmotor
|
|||
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] = {20,1,3,2,5,6,4,20};
|
||||
|
||||
static const uint16_t COMMUTATION_PATTERN[] = {
|
||||
0x00FC, // invalid state (0)
|
||||
0x30F8, // CB_CW (1)
|
||||
0x50F4, // CA_CW (2)
|
||||
0x60F8, // BA_CW (3)
|
||||
0x607C, // AB_CW (4)
|
||||
0x507C, // BC_CW (5)
|
||||
0x30F4, // AC_CW (6)
|
||||
0x00FC, // invalid state
|
||||
0x00FC, // invalid state
|
||||
0x30F4, // BC_CCW (9)
|
||||
0x507C, // AB_CCW (10)
|
||||
0x607C, // AC_CCW (11)
|
||||
0x60F8, // CA_CCW (12)
|
||||
0x50F4, // BA_CCW (13)
|
||||
0x30F8, // CB_CCW (14)
|
||||
0x00FC
|
||||
};//Based on Hall State Dir_A_B_C
|
||||
|
||||
|
||||
volatile BLDCMotor_t Motor1;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// all controller objects, variables and helpers:
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
//volatile PI_t Pi_Idc;
|
||||
//volatile PI_t Pi_Speed;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// functions
|
||||
|
|
|
@ -0,0 +1,126 @@
|
|||
/*
|
||||
* motor_params.h
|
||||
*
|
||||
* Created: 28/04/2021 09:13:40
|
||||
* Author: Nick-XMG
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MOTOR_PARAMS_H_
|
||||
#define MOTOR_PARAMS_H_
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Current Sensor
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
#define DRV_ISEN_A_CH ADC_INPUTCTRL_MUXPOS_AIN2_Val
|
||||
#define DRV_ISEN_B_CH ADC_INPUTCTRL_MUXPOS_AIN1_Val
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Hall Parameters
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
#define HALL_A_PIN GPIO(GPIO_PORTA, 6)
#define HALL_A_PORT PORT_PA06
#define HALL_A_MASK ~(1<<2)
#define HALL_A_LSR HALL_A_PIN - HALL_A_GROUP*32 -2
|
||||
#define HALL_A_GROUP HALL_A_PIN/32
#define HALL_B_PIN GPIO(GPIO_PORTA, 5)
|
||||
#define HALL_B_PORT PORT_PA05
|
||||
#define HALL_B_MASK ~(1<<1)
|
||||
#define HALL_B_LSR HALL_B_PIN - HALL_B_GROUP*32 -1
|
||||
#define HALL_B_GROUP HALL_B_PIN/32
|
||||
|
||||
#define HALL_C_PIN GPIO(GPIO_PORTA, 4)
|
||||
#define HALL_C_PORT PORT_PA04
|
||||
#define HALL_C_MASK ~(1<<0)
|
||||
#define HALL_C_LSR HALL_C_PIN - HALL_C_GROUP*32 -0
|
||||
#define HALL_C_GROUP HALL_C_PIN/32
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Motor Parameters
|
||||
// ----------------------------------------------------------------------
|
||||
// these values fit for an Faulhaber 3216W024BXTR motor
|
||||
#define MOTOR_POLES (14U)
|
||||
#define MOTOR_POLEPAIRS (MOTOR_POLES/2)
|
||||
#define MOTOR_COMUTATION_STATES (MOTOR_POLEPAIRS*6)
|
||||
#define MOTOR_RS_OHM (3.37f)
|
||||
#define MOTOR_LD_H (0.001290f)
|
||||
#define MOTOR_LQ_H (0.001290f)
|
||||
#define MOTOR_FLUX_WB (0.0063879968f)
|
||||
#define MOTOR_MAX_SPD_RPM (4200.0f)
|
||||
#define MOTOR_MAX_SPD_ELEC ((MOTOR_MAX_SPD_RPM/60)*MOTOR_POLEPAIRS)
|
||||
#define MOTOR_MEASURINGRANGE_RPM (1.2f * MOTOR_MAX_SPD_RPM)f // give 20% headroom
|
||||
#define MOTOR_MAX_CURRENT_IDC_A (1.2f)
|
||||
|
||||
#define PWM_TOP 1000
|
||||
#define MAX_PWM 700
|
||||
#define MAX_VEL 3800
|
||||
|
||||
#define CW 0 //CBA
|
||||
#define DIRECTION_CW_OFFSET 0 //CBA
|
||||
#define CCW 1 //ABC
|
||||
#define DIRECTION_CCW_OFFSET 8 //CBA
|
||||
|
||||
#define AVERAGE_SPEED_MEASURE
|
||||
#define COUNTEQUIVTO25RPM 892857142
|
||||
#define n_SAMPLE 8
|
||||
static uint32_t speed_average = 0;
|
||||
static uint8_t count = 1;
|
||||
|
||||
|
||||
|
||||
static const uint16_t COMMUTATION_PATTERN_M1[] = {
|
||||
0x00FC, // invalid state (0)
|
||||
0x30F8, // CB_CW (1)
|
||||
0x50F4, // CA_CW (2)
|
||||
0x60F8, // BA_CW (3)
|
||||
0x607C, // AB_CW (4)
|
||||
0x507C, // BC_CW (5)
|
||||
0x30F4, // AC_CW (6)
|
||||
0x00FC, // invalid state
|
||||
0x00FC, // invalid state
|
||||
0x30F4, // BC_CCW (9)
|
||||
0x507C, // AB_CCW (10)
|
||||
0x607C, // AC_CCW (11)
|
||||
0x60F8, // CA_CCW (12)
|
||||
0x50F4, // BA_CCW (13)
|
||||
0x30F8, // CB_CCW (14)
|
||||
0x00FC
|
||||
};
|
||||
|
||||
static const uint16_t COMMUTATION_PATTERN_M2[] = {
|
||||
0x00FC, // invalid state (0)
|
||||
0x30F8, // CB_CW (1)
|
||||
0x50F4, // CA_CW (2)
|
||||
0x60F8, // BA_CW (3)
|
||||
0x607C, // AB_CW (4)
|
||||
0x507C, // BC_CW (5)
|
||||
0x30F4, // AC_CW (6)
|
||||
0x00FC, // invalid state
|
||||
0x00FC, // invalid state
|
||||
0x30F4, // BC_CCW (9)
|
||||
0x507C, // AB_CCW (10)
|
||||
0x607C, // AC_CCW (11)
|
||||
0x60F8, // CA_CCW (12)
|
||||
0x50F4, // BA_CCW (13)
|
||||
0x30F8, // CB_CCW (14)
|
||||
0x00FC
|
||||
};
|
||||
|
||||
static const uint16_t COMMUTATION_PATTERN_M3[] = {
|
||||
0x00FC, // invalid state (0)
|
||||
0x30F8, // CB_CW (1)
|
||||
0x50F4, // CA_CW (2)
|
||||
0x60F8, // BA_CW (3)
|
||||
0x607C, // AB_CW (4)
|
||||
0x507C, // BC_CW (5)
|
||||
0x30F4, // AC_CW (6)
|
||||
0x00FC, // invalid state
|
||||
0x00FC, // invalid state
|
||||
0x30F4, // BC_CCW (9)
|
||||
0x507C, // AB_CCW (10)
|
||||
0x607C, // AC_CCW (11)
|
||||
0x60F8, // CA_CCW (12)
|
||||
0x50F4, // BA_CCW (13)
|
||||
0x30F8, // CB_CCW (14)
|
||||
0x00FC
|
||||
};
|
||||
|
||||
#endif /* MOTOR_PARAMS_H_ */
|
Loading…
Reference in New Issue