24#include "stm32f4xx_hal.h"
29#define pi 3.14159265359f
30#define SQRT_3 1.7320508f
115 float T1,T2,Tx,Ty,Tz;
118 uint16_t ADC_DMA_RAW[3];
119 uint16_t DC_offset[2];
120 int16_t ADC_Filtered[3];
122 int16_t Current_lastValue[5];
139void MotorInit(
Motor* mHandle,ADC_HandleTypeDef hadc,TIM_HandleTypeDef hDriver, TIM_HandleTypeDef hEncoder, I2C_HandleTypeDef hIICEncoder,
ControlMode mode);
203void SetMotorParam(
Motor* mHandle,uint8_t DC_supply, uint8_t phase, uint8_t polePairs,
float MaxCurrent,
float MaxSpeed);
void AnglePID(Motor *mHandle)
: Angle loop PID calculation, calculate target speed with integral limiter
void ADCSample(Motor *mHandle)
: Current sampling function, once called, retrieve one set of sampled data from DMA Data stored in mH...
void MotorInit(Motor *mHandle, ADC_HandleTypeDef hadc, TIM_HandleTypeDef hDriver, TIM_HandleTypeDef hEncoder, I2C_HandleTypeDef hIICEncoder, ControlMode mode)
: Motor initialization function
void getEangle(Motor *mHandle)
: Calculate electric angle from mechanical angle, store in mHandle->E_angle
int calcAngle(Motor *mHandle)
: [Auxiliary Debug Function] calculate electric angle from Valpha and Vbeta
void SetMotorParam(Motor *mHandle, uint8_t DC_supply, uint8_t phase, uint8_t polePairs, float MaxCurrent, float MaxSpeed)
: Set motor parameters
void IqPID(Motor *mHandle)
: Current loop Iq PID calculation, calculate target Vq from Iq with current kalman filter,...
void ClarkeTransform(Coordinates *pComponents)
: Clarke Transformation function, convert abc to alpha beta
void FOC(Motor *mHandle)
: FOC loop funtion, including electric angle conversion, phase current filtering, Clarke/Park transfo...
void ModulationLimit(Motor *mHandle)
: Overmodulation limiting function, prevent overmodulation
void getSpeed(Motor *mHandle)
: Calculate the motor speed in rpm, store in mHandle->speed
void IdPID(Motor *mHandle)
: Current loop Id PID calculation, calculate target Vd from Id with current kalman filter,...
DRV_GAIN
DRV8302 amplification gain enumerator.
void UserAPPSelection(Motor *mHandle, UserAPP app)
: user application selection function
void dq2SVPWM(Motor *mHandle)
: Generate SVPWM directly from dq voltage
struct Components Coordinates
Coordinates components structure.
void CurrentReconstruction(Motor *mHandle)
: Reconstruct the sampled current from 2 phases to three phases
void EnableGate(void)
: Pull up the ENGATE pin of the DRV8302 to activate the gate
void InvPark(Coordinates *pComponents, int theta)
: Inverse Park Transformation function, convert d, q to alpha, beta Original park: q leads d axis by ...
void ParkTransform(Coordinates *pComponents, int theta)
: Park Transformation function, convert alpha, beta to d, q Original park: q leads d axis by 90 deg M...
void SpeedPID(Motor *mHandle)
: Speed loop PID calculation, set target Id = 0, calculate target Iq from speed with integral limiter...
void DC_Calibration(Motor *mHandle)
: Calibrate the DC offset of the current shunt amplifier should be called after EnableGate()
void SetCurrentPID(Motor *mHandle, float kp, float ki, float kd)
: Set PID parameters of both d,q current loop
void MotorOpenLoop(Motor *mHandle)
: openloop drag control
void SetAnglePID(Motor *mHandle, float kp, float ki, float kd)
: Set angle loop PID parameters
void ADCFilter(Motor *mHandle)
: Filter the sampled current
void FOCcheck(Motor *mHandle)
: [Auxiliary Debug Function] call to print FOC PID parameters
void SetIncrementAngle(Motor *mHandle, float Target)
: Set increment target angle, the incremental angle is also restricted in (0-360 deg)
void GetSector(Motor *mHandle)
: Calculate the sector of the target space voltage vector
void SetSpeedPID(Motor *mHandle, float kp, float ki, float kd, float outMax)
: Set speed loop PID parameters and the speed limit
void ModeSelection(Motor *mHandle, ControlMode mode)
: Mode selection function
void MotorCalibration(Motor *mHandle)
: Calibrate motor when power on Measure the angle offset between encoder 0 deg and motor electrical 0...
void SetSpeedTarget(Motor *mHandle, float Target)
: Set target motor speed, with over speed limit
UserAPP
UserAPP enumerator.
void SetCurrentTarget(Motor *mHandle, float idTarget, float iqTarget)
: Set target id, iq
void SetAngleTarget(Motor *mHandle, float Target)
: Set absolute target angle, only single-turn (0-360 deg)
void GainSelection(DRV_GAIN gain)
: Select the gain of the buit-in amplifier of DRV8302 If GAIN = LOW, the internal current shunt ampli...
void SetSVPWM(Motor *mHandle)
: MOSFET dwelling time calculation function, to generate SVPWM
void GetSVPWM(Motor *mHandle)
: Original SVPWM calculation function using complex numbers, slow
ControlMode
ControlMode enumerator.
Coordinates components structure.
Motor parameter structure.
I2C_HandleTypeDef hI2CEncoder
TIM_HandleTypeDef hTimEncoder
ADC_HandleTypeDef hMotorADC
TIM_HandleTypeDef hTimDriver