![]() |
![]() |
MSPM0G3519SensoredFOCMotorControlLibrary
1.0
|
#include "ti_msp_dl_config.h"
#include <ti/iqmath/include/IQmathLib.h>
#include "IQmath_mathacl.h"
#include "focPeriphInit.h"
#include "gateDriver.h"
#include "stdint.h"
#include "measure.h"
#include "mcLib.h"
#include "main.h"
#include "iqNum.h"
#include "appInterface.h"
Go to the source code of this file.
Macros | |
#define | MIN_FLOAT_VOLTAGE (0.1) |
Minimum floating voltage for phase in per unit. | |
#define | MAX_FLOAT_VOLTAGE (0.9) |
Maximum floating voltage for phase in per unit. | |
#define | HAL_MCU_CLK_SPEED_HZ (80000000) |
MCU clock frequency. | |
#define | HAL_CYCLES_TO_1_US_DELAY (HAL_MCU_CLK_SPEED_HZ/1000000) |
Cycles for 1 us delay. | |
#define | HAL_GPIO_HIGH (1) |
Gpio high state. | |
#define | HAL_GPIO_LOW (0) |
Gpio low state. | |
Enumerations | |
enum | VOLTAGE_VECTOR { VOLTAGE_VECTOR_AC = 0, VOLTAGE_VECTOR_CA, VOLTAGE_VECTOR_BC, VOLTAGE_VECTOR_CB, VOLTAGE_VECTOR_BA, VOLTAGE_VECTOR_AB, VOLTAGE_VECTOR_MAX } |
VOLTAGE_VECTOR. More... | |
Functions | |
void | HAL_ReadMotorInputs (HAL_MEASURE_MOTOR_INPUTS_T *pMotorInputs) |
Read Motor inputs. More... | |
void | HAL_SetPhaseCurrentChannels (HAL_MEASURE_MOTOR_INPUTS_T *pMotorInputs) |
Set Phase current channels. More... | |
void | HAL_setADCIdxChannel (ADC12_Regs *adc12, DL_ADC12_MEM_IDX idx, uint32_t chansel) |
Set ADC channel to index. More... | |
void | HAL_ReadCurrents (HAL_MEASURE_MOTOR_INPUTS_T *pMotorInputs) |
Read phase currents. More... | |
void | HAL_SelectShuntMeasure (HAL_MEASURE_MOTOR_INPUTS_T *pMotorInputs) |
Select two shunt if duty saturates in any phases. More... | |
void | HAL_EnablePWM (void) |
Enable PWMs. | |
void | HAL_DisablePWM (void) |
Disable PWMs and all outputs are forced low. | |
void | HAL_EnableLowSideBrake (void) |
Turns all low side PWM outputs high. | |
void | HAL_UpdateDuty (const MC_ABC_T *pABC, const int32_t FullDuty, MC_SECTOR_TYPES voltageSector, int32_t minDelta, int32_t blankingTime) |
Set PWM dutycycles. More... | |
void | HAL_SetPWMFrequency (const int32_t pwmPeriod, const int32_t propagationDelay) |
Set PWM Frequency. More... | |
void | HAL_SetADCSamplingFrequency (const ADC_SAMPLING_RATIO_TYPES samplingRatio) |
Set ADC sampling frequency. More... | |
void | HAL_SetSystemFrequency (const int32_t systemPeriod) |
Set System timer frequency. More... | |
void | HAL_ClearNFault (void) |
Sets Nfault pin low. | |
void | HAL_SetNFault (void) |
Sets Nfault pin high. | |
uint32_t | HAL_getRawHVdieFaultStatus (void) |
Gets the latched fault status. More... | |
uint32_t | HAL_getRawFaultStatus (void) |
Gets the fault status. More... | |
void | HAL_clearFaultStatus (void) |
Clears the fault status in pwm. | |
void | HAL_setGateDriveOffsetCalib (void) |
Starts gate driver offset calibration. | |
void | HAL_resetGateDriveOffsetCalib (void) |
Stops gate driver offset calibration. | |
void | HAL_pwmCountZero (void) |
Set PWMs to zero. | |
void | HAL_delayMicroSeconds (uint32_t num_us) |
Blocks for the specified delay time. More... | |
void | HAL_DisableINT (void) |
Disables all the interrupts. | |
void | HAL_resetPOR (void) |
Triggers a POR reset. | |
_Bool | HAL_getDirPinStatus (void) |
Get the status of the Direction pin. More... | |
uint16_t | HAL_Is_SingleShunt (void) |
Returns Shunt Config. More... | |
_Bool | HAL_getBrakePinStatus (void) |
Get the status of the brake pin. More... | |
__STATIC_INLINE void | HAL_TimerOverRideCCPOut (GPTIMER_Regs *gptimer, DL_TIMER_FORCE_OUT out, DL_TIMER_FORCE_CMPL_OUT outComp, DL_TIMER_CC_INDEX ccIndex) |
Overrides the timer CCP output. More... | |
__STATIC_INLINE void | HAL_FGToggle (void) |
Toggle the GPIO to high and low for every sector change. | |
__STATIC_INLINE void | HAL_PWMForceHigh (DL_TIMER_CC_INDEX CCIdx) |
Force the PWM out to high and complement out to low. More... | |
__STATIC_INLINE void | HAL_PWMForceLow (DL_TIMER_CC_INDEX CCIdx) |
Force the PWM out to low and complement out to high. More... | |
__STATIC_INLINE void | HAL_PWMForceDisable (DL_TIMER_CC_INDEX CCIdx) |
Disable forcing the PWM out and complement out. More... | |
__STATIC_INLINE void | HAL_PWMAllForceDisable () |
Disable forcing All PWM out and complement out. | |
__STATIC_INLINE void | HAL_PWMAllForceLow () |
Forcing low All PWM out and complement out. | |
__STATIC_INLINE void | HAL_setCaptureCompareValue (GPTIMER_Regs *gptimer, uint32_t value, DL_TIMER_CC_INDEX ccIndex) |
Set the Capture Compare Value for Timer. More... | |
enum VOLTAGE_VECTOR |
void HAL_ReadMotorInputs | ( | HAL_MEASURE_MOTOR_INPUTS_T * | pMotorInputs | ) |
Read Motor inputs.
[in] | pMotorInputs | Pointer to motor input |
References HAL_MEASURE_MOTOR_INPUTS_T::current, HAL_GD_ReadDCVBusVoltage(), HAL_ReadCurrents(), HAL_MEASURE_CURRENT_T::pMaxDutyPhase, HAL_MEASURE_CURRENT_T::prevMaxDutyPhase, and HAL_MEASURE_MOTOR_INPUTS_T::voltage.
void HAL_SetPhaseCurrentChannels | ( | HAL_MEASURE_MOTOR_INPUTS_T * | pMotorInputs | ) |
Set Phase current channels.
[in] | pMotorInputs | Pointer to motor input |
References HAL_MEASURE_MOTOR_INPUTS_T::current, HAL_MEASURE_CURRENT_T::currentShunt, FOC_ADC0_INST, FOC_ADC1_INST, and HAL_GD_ConfigureCurrentChannels().
Referenced by HAL_SelectShuntMeasure(), loadRun(), and measureCurrentOffset().
void HAL_setADCIdxChannel | ( | ADC12_Regs * | adc12, |
DL_ADC12_MEM_IDX | idx, | ||
uint32_t | chansel | ||
) |
Set ADC channel to index.
[in] | adc12 | Pointer to ADC instance |
[in] | idx | ADC index |
[in] | chansel | channel to set in index |
void HAL_ReadCurrents | ( | HAL_MEASURE_MOTOR_INPUTS_T * | pMotorInputs | ) |
Read phase currents.
[in] | pMotorInputs | Pointer to motor input |
References _IQmpy_mathacl, MC_ABC_T::a, MC_ABC_T::b, MC_ABC_T::c, HAL_MEASURE_MOTOR_INPUTS_T::current, CURRENT_THREE_SHUNT_A_BC, CURRENT_TWO_SHUNT_A_B, CURRENT_TWO_SHUNT_A_C, CURRENT_TWO_SHUNT_B_C, HAL_MEASURE_CURRENT_T::currentShunt, getMeasureOffsetStatus(), HAL_currentReconstruction(), HAL_GD_ReadCurrents(), HAL_MEASURE_CURRENT_T::iabc, HAL_MEASURE_CURRENT_T::iabcRaw, CURRENT_OFFSET_T::iaOffset, CURRENT_OFFSET_T::ibADC0Offset, CURRENT_OFFSET_T::ibADC1Offset, CURRENT_OFFSET_T::icOffset, HAL_MEASURE_CURRENT_T::iMagSqr, HAL_MEASURE_CURRENT_T::pOffset, HAL_MEASURE_CURRENT_T::pPrevPrevSector, and TWO_BY_THREE.
Referenced by HAL_ReadMotorInputs().
void HAL_SelectShuntMeasure | ( | HAL_MEASURE_MOTOR_INPUTS_T * | pMotorInputs | ) |
Select two shunt if duty saturates in any phases.
[in] | pMotorInputs | Pointer to motor input |
References MEASURE_CURRENT_FLAGS_T::b, HAL_MEASURE_MOTOR_INPUTS_T::current, CURRENT_TWO_SHUNT_A_B, CURRENT_TWO_SHUNT_A_C, CURRENT_TWO_SHUNT_B_C, HAL_MEASURE_CURRENT_T::currentShunt, HAL_MEASURE_CURRENT_T::currentShuntSet, HAL_MEASURE_CURRENT_T::flags, HAL_SetPhaseCurrentChannels(), PHASE_A, PHASE_B, PHASE_C, PHASE_INVALID, HAL_MEASURE_CURRENT_T::pMaxDutyPhase, HAL_MEASURE_CURRENT_T::prevMaxDutyPhase, and measureCurrentFlags::threeShuntDynamic.
void HAL_UpdateDuty | ( | const MC_ABC_T * | pABC, |
const int32_t | FullDuty, | ||
MC_SECTOR_TYPES | voltageSector, | ||
int32_t | minDelta, | ||
int32_t | blankingTime | ||
) |
Set PWM dutycycles.
[in] | pABC | Pointer to dutycycle |
[in] | FullDuty | Full dutycycle |
[in] | voltageSector | Voltage sector |
[in] | minDelta | minimum PWM delta |
[in] | blankingTime | Blanking time |
void HAL_SetPWMFrequency | ( | const int32_t | pwmPeriod, |
const int32_t | propagationDelay | ||
) |
Set PWM Frequency.
[in] | pwmPeriod | PWM period to set |
[in] | propagationDelay | Propagation delay |
References ADC_PWM_TRIG_CH, FOC_PWMA0_ADC_TRIG_LOAD_EVENT, FOC_PWMA0_INST, FOC_TIMA1_INST, and HAL_setCaptureCompareValue().
Referenced by updateConfigurationParameters().
void HAL_SetADCSamplingFrequency | ( | const ADC_SAMPLING_RATIO_TYPES | samplingRatio | ) |
Set ADC sampling frequency.
[in] | samplingRatio | ADC sampling ratio |
References ADC_PWM_TRIG_CH, FOC_ADC0_INST, FOC_ADC1_INST, FOC_PWMA0_INST, FOC_TIMA1_INST, and HAL_setCaptureCompareValue().
Referenced by updateConfigurationParameters().
void HAL_SetSystemFrequency | ( | const int32_t | systemPeriod | ) |
Set System timer frequency.
[in] | systemPeriod | Timer period |
References FOC_TIMER_INST.
Referenced by updateConfigurationParameters().
uint32_t HAL_getRawHVdieFaultStatus | ( | void | ) |
uint32_t HAL_getRawFaultStatus | ( | void | ) |
Gets the fault status.
References FOC_PWMA0_INST.
Referenced by FOC_fault_Recovery().
_Bool HAL_getDirPinStatus | ( | void | ) |
Get the status of the Direction pin.
true | Direction pin is high |
false | Direction pin is low |
References FOC_GPIO_DIR_PIN, FOC_GPIO_DIR_PORT, HAL_GPIO_HIGH, and HAL_GPIO_LOW.
Referenced by update_DirectionStatus().
uint16_t HAL_Is_SingleShunt | ( | void | ) |
_Bool HAL_getBrakePinStatus | ( | void | ) |
Get the status of the brake pin.
true | brake pin is high |
false | brake pin is low |
References FOC_GPIO_BRAKE_PIN, FOC_GPIO_BRAKE_PORT, HAL_GPIO_HIGH, and HAL_GPIO_LOW.
Referenced by update_BrakeStatus().
__STATIC_INLINE void HAL_TimerOverRideCCPOut | ( | GPTIMER_Regs * | gptimer, |
DL_TIMER_FORCE_OUT | out, | ||
DL_TIMER_FORCE_CMPL_OUT | outComp, | ||
DL_TIMER_CC_INDEX | ccIndex | ||
) |
Overrides the timer CCP output.
[in] | gptimer | Pointer to timer instance. |
[in] | out | Specifies the CCP output state. |
[in] | outComp | Specifies the complementary output state. |
[in] | ccIndex | Capture Compare Index. |
Referenced by HAL_DisablePWM(), HAL_EnableLowSideBrake(), HAL_EnablePWM(), HAL_PWMForceDisable(), HAL_PWMForceHigh(), and HAL_PWMForceLow().
__STATIC_INLINE void HAL_PWMForceHigh | ( | DL_TIMER_CC_INDEX | CCIdx | ) |
Force the PWM out to high and complement out to low.
[in] | CCIdx | A PWM CC index. |
References FOC_PWMA0_INST, and HAL_TimerOverRideCCPOut().
__STATIC_INLINE void HAL_PWMForceLow | ( | DL_TIMER_CC_INDEX | CCIdx | ) |
Force the PWM out to low and complement out to high.
[in] | CCIdx | A PWM CC index. |
References FOC_PWMA0_INST, and HAL_TimerOverRideCCPOut().
Referenced by HAL_EnableLowSideBrake(), and HAL_PWMAllForceLow().
__STATIC_INLINE void HAL_PWMForceDisable | ( | DL_TIMER_CC_INDEX | CCIdx | ) |
Disable forcing the PWM out and complement out.
[in] | CCIdx | A PWM CC index. |
References FOC_PWMA0_INST, and HAL_TimerOverRideCCPOut().
Referenced by HAL_EnableLowSideBrake(), and HAL_PWMAllForceDisable().
__STATIC_INLINE void HAL_setCaptureCompareValue | ( | GPTIMER_Regs * | gptimer, |
uint32_t | value, | ||
DL_TIMER_CC_INDEX | ccIndex | ||
) |
Set the Capture Compare Value for Timer.
[in] | gptimer | Pointer to timer instance. |
[in] | value | Compare Value. |
[in] | ccIndex | Capture Compare Index. |
Referenced by HAL_DisablePWM(), HAL_EnableLowSideBrake(), HAL_pwmCountZero(), HAL_SetADCSamplingFrequency(), and HAL_SetPWMFrequency().