![]() |
![]() |
|
MSPM0G3507SensorlessFOCMotorControlLibrary
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_SetPhaseVoltageChannels (HAL_MEASURE_MOTOR_INPUTS_T *pMotorInputs) |
| Set Phase voltage channels in ADC. More... | |
| void | HAL_ReadPhaseVoltages (HAL_MEASURE_MOTOR_INPUTS_T *pMotorInputs) |
| Read Phase voltages from ADCs. 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_enterIPDMode () |
| Configures the peripherals for IPD. | |
| void | HAL_exitIPDMode () |
| Sets the peripheral configuration when IPD completes. | |
| 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... | |
| _Bool | HAL_GetPhasesFloatingStatus (const HAL_MEASURE_VOLTAGE_T *pVoltage) |
| Get phase floating status. 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... | |
| _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. | |
| void | HAL_IPDEnableISR (void) |
| Enables the IPD capture timer. | |
| void | HAL_IPDDisableISR (void) |
| Disabled the IPD capture timer. | |
| uint16_t | HAL_IPDGetTime (void) |
| Returns the time captured. More... | |
| uint16_t | HAL_IPDGetLoadVal (void) |
| Returns the IPD load value. More... | |
| uint16_t | HAL_Is_SingleShunt (void) |
| Returns Shunt Config. More... | |
| void | HAL_IPDCOMPDACSetZero (void) |
| Set Comparator DAC to zero. | |
| void | HAL_setIPDPulseConfig (VOLTAGE_VECTOR vector, uint8_t CompVal, CURRENT_OFFSET_T *pOffset) |
| Set IPD Pulse configuration. More... | |
| __STATIC_INLINE void | HAL_ADCDisConv (ADC12_Regs *adc12) |
| Disable forcing the PWM out and complement out. More... | |
| __STATIC_INLINE void | HAL_ADCEnConv (ADC12_Regs *adc12) |
| Disable forcing the PWM out and complement out. More... | |
| __STATIC_INLINE void | HAL_ADCEnWCOMP (ADC12_Regs *adc12, DL_ADC12_MEM_IDX idx) |
| Disable forcing the PWM out and complement out. More... | |
| __STATIC_INLINE void | HAL_ADCDisWCOMP (ADC12_Regs *adc12, DL_ADC12_MEM_IDX idx) |
| Disable forcing the PWM out and complement out. More... | |
| __STATIC_INLINE void | HAL_enableTriggerFault (GPTIMER_Regs *gptimer) |
| Enable trigger fault for a timer. More... | |
| __STATIC_INLINE void | HAL_disableTriggerFault (GPTIMER_Regs *gptimer) |
| Disable trigger fault for a timer. More... | |
| __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_ReadPhaseVoltages(), MEASURE_PHASE_CURRENT, MEASURE_PHASE_VOLTAGE, HAL_MEASURE_MOTOR_INPUTS_T::measureQuantity, 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, HAL_GD_ConfigureCurrentChannels(), MEASURE_PHASE_CURRENT, and HAL_MEASURE_MOTOR_INPUTS_T::measureQuantity.
Referenced by HAL_SelectShuntMeasure(), 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_SetPhaseVoltageChannels | ( | HAL_MEASURE_MOTOR_INPUTS_T * | pMotorInputs | ) |
Set Phase voltage channels in ADC.
| [in] | pMotorInputs | Pointer to motor input |
References HAL_MEASURE_MOTOR_INPUTS_T::adcSamplingRatio, FOC_ADC0_INST, FOC_ADC1_INST, HAL_GD_ConfigureVoltageChannels(), HAL_SetADCSamplingFrequency(), MEASURE_PHASE_VOLTAGE, and HAL_MEASURE_MOTOR_INPUTS_T::measureQuantity.
| void HAL_ReadPhaseVoltages | ( | HAL_MEASURE_MOTOR_INPUTS_T * | pMotorInputs | ) |
Read Phase voltages from ADCs.
| [in] | pMotorInputs | Pointer to motor input |
References _IQmpy_mathacl, MC_ABC_T::a, MC_ABC_T::b, MC_ABC_T::c, HAL_GD_ReadVoltages(), HAL_MEASURE_VOLTAGE_T::vabc, HAL_MEASURE_VOLTAGE_T::vabcRaw, and HAL_MEASURE_MOTOR_INPUTS_T::voltage.
Referenced by HAL_ReadMotorInputs().
| 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().
| 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, and FOC_TIMA1_INST.
Referenced by HAL_enterIPDMode(), and HAL_SetPhaseVoltageChannels().
| void HAL_SetSystemFrequency | ( | const int32_t | systemPeriod | ) |
| _Bool HAL_GetPhasesFloatingStatus | ( | const HAL_MEASURE_VOLTAGE_T * | pVoltage | ) |
Get phase floating status.
| [in] | pVoltage | pointer to voltage structure |
| true | Phases floating |
| false | Phases not floating |
References _IQmpy_mathacl, MC_ABC_T::a, MC_ABC_T::b, MC_ABC_T::c, FALSE, MAX_FLOAT_VOLTAGE, MIN_FLOAT_VOLTAGE, TRUE, HAL_MEASURE_VOLTAGE_T::vabcRaw, and HAL_MEASURE_VOLTAGE_T::vdc.
| uint32_t HAL_getRawHVdieFaultStatus | ( | void | ) |
| uint32_t HAL_getRawFaultStatus | ( | void | ) |
| void HAL_delayMicroSeconds | ( | uint32_t | num_us | ) |
Blocks for the specified delay time.
| [in] | num_us | Delay in us |
References HAL_CYCLES_TO_1_US_DELAY.
| _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().
| _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, FOC_PWMA0_INST, HAL_ADCDisConv(), HAL_clearFaultStatus(), HAL_enableTriggerFault(), HAL_GPIO_HIGH, HAL_GPIO_LOW, HAL_IPDEnableISR(), HAL_PWMForceDisable(), HAL_PWMForceHigh(), HAL_PWMForceLow(), CURRENT_OFFSET_T::i2Offset, CURRENT_OFFSET_T::iaOffset, CURRENT_OFFSET_T::ibADC0Offset, CURRENT_OFFSET_T::icOffset, VOLTAGE_VECTOR_AB, VOLTAGE_VECTOR_AC, VOLTAGE_VECTOR_BA, VOLTAGE_VECTOR_BC, VOLTAGE_VECTOR_CA, and VOLTAGE_VECTOR_CB.
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().
Referenced by HAL_getBrakePinStatus().
| __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(), HAL_getBrakePinStatus(), 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(), HAL_getBrakePinStatus(), and HAL_PWMAllForceDisable().
| uint16_t HAL_IPDGetTime | ( | void | ) |
Returns the time captured.
Referenced by HAL_PWMAllForceLow().
| uint16_t HAL_IPDGetLoadVal | ( | void | ) |
| uint16_t HAL_Is_SingleShunt | ( | void | ) |
Returns Shunt Config.
Referenced by HAL_PWMAllForceLow().
| void HAL_setIPDPulseConfig | ( | VOLTAGE_VECTOR | vector, |
| uint8_t | CompVal, | ||
| CURRENT_OFFSET_T * | pOffset | ||
| ) |
Set IPD Pulse configuration.
| [in] | vector | voltage vector to set |
| [in] | CompVal | Comparator threshold value |
| [in] | pOffset | ADC offset pointer |
Referenced by HAL_PWMAllForceLow().
| __STATIC_INLINE void HAL_ADCDisConv | ( | ADC12_Regs * | adc12 | ) |
Disable forcing the PWM out and complement out.
| [in] | adc12 | Pointer to adc instance. |
Referenced by HAL_getBrakePinStatus().
| __STATIC_INLINE void HAL_ADCEnConv | ( | ADC12_Regs * | adc12 | ) |
Disable forcing the PWM out and complement out.
| [in] | adc12 | Pointer to adc instance. |
| __STATIC_INLINE void HAL_ADCEnWCOMP | ( | ADC12_Regs * | adc12, |
| DL_ADC12_MEM_IDX | idx | ||
| ) |
Disable forcing the PWM out and complement out.
| [in] | adc12 | Pointer to adc instance. |
| [in] | idx | Adc mem index. |
| __STATIC_INLINE void HAL_ADCDisWCOMP | ( | ADC12_Regs * | adc12, |
| DL_ADC12_MEM_IDX | idx | ||
| ) |
Disable forcing the PWM out and complement out.
| [in] | adc12 | Pointer to adc instance. |
| [in] | idx | Adc mem index. |
| __STATIC_INLINE void HAL_enableTriggerFault | ( | GPTIMER_Regs * | gptimer | ) |
Enable trigger fault for a timer.
| [in] | gptimer | Pointer to timer instance. |
Referenced by HAL_getBrakePinStatus().
| __STATIC_INLINE void HAL_disableTriggerFault | ( | GPTIMER_Regs * | gptimer | ) |
Disable trigger fault for a timer.
| [in] | gptimer | Pointer to timer instance. |
Referenced by HAL_exitIPDMode().
| __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_exitIPDMode(), HAL_pwmCountZero(), and HAL_SetPWMFrequency().