71 #define Device_cal (void (*)(void))0x3D7C80
75 #define FP_SCALE 32768
78 #define FP_ROUND FP_SCALE/2
83 #define OSC_POSTRIM 32
84 #define OSC_POSTRIM_OFF FP_SCALE*OSC_POSTRIM
89 #define getOsc1FineTrimSlope() (*(int16_t (*)(void))0x3D7E90)()
92 #define getOsc1FineTrimOffset() (*(int16_t (*)(void))0x3D7E93)()
95 #define getOsc1CoarseTrim() (*(int16_t (*)(void))0x3D7E96)()
99 #define getOsc2FineTrimSlope() (*(int16_t (*)(void))0x3D7E99)()
102 #define getOsc2FineTrimOffset() (*(int16_t (*)(void))0x3D7E9C)()
105 #define getOsc2CoarseTrim() (*(int16_t (*)(void))0x3D7E9F)()
108 #define getRefTempOffset() (*(int16_t (*)(void))0x3D7EA2)()
112 #define HAL_PWM_DBFED_CNT 1
117 #define HAL_PWM_DBRED_CNT 1
122 #define HAL_turnLedOff HAL_setGpioLow
127 #define HAL_turnLedOn HAL_setGpioHigh
132 #define HAL_toggleLed HAL_toggleGpio
169 extern interrupt
void mainISR(
void);
186 ADC_clearIntFlag(obj->
adcHandle,intNumber);
190 PIE_clearInt(obj->
pieHandle,PIE_GroupNumber_10);
206 PWM_clearIntFlag(obj->
pwmHandle[pwmNumber]);
210 PWM_clearSocAFlag(obj->
pwmHandle[pwmNumber]);
214 PIE_clearInt(obj->
pieHandle,PIE_GroupNumber_3);
233 PIE_clearInt(obj->
pieHandle,PIE_GroupNumber_1);
265 PWM_setOneShotTrip(obj->
pwmHandle[PWM_Number_1]);
266 PWM_setOneShotTrip(obj->
pwmHandle[PWM_Number_2]);
267 PWM_setOneShotTrip(obj->
pwmHandle[PWM_Number_3]);
307 PWM_clearOneShotTrip(obj->
pwmHandle[PWM_Number_1]);
308 PWM_clearOneShotTrip(obj->
pwmHandle[PWM_Number_2]);
309 PWM_clearOneShotTrip(obj->
pwmHandle[PWM_Number_3]);
330 const ADC_SocNumber_e socNumber)
334 return(ADC_getSocSampleDelay(obj->
adcHandle,socNumber));
348 uint_least8_t sensorNumber)
414 const uint_least8_t sensorNumber)
418 _iq beta_lp_pu =
_IQ(0.0);
442 const uint_least8_t sensorNumber)
500 PIE_Obj *pie = (PIE_Obj *)obj->
pieHandle;
503 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
507 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
531 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_1);
533 pAdcData->
I.
value[0] = value;
536 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_2);
538 pAdcData->
I.
value[1] = value;
541 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_3);
543 pAdcData->
I.
value[2] = value;
546 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_4);
548 pAdcData->
V.
value[0] = value;
551 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_5);
553 pAdcData->
V.
value[1] = value;
556 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_6);
558 pAdcData->
V.
value[2] = value;
561 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_7);
563 pAdcData->
dcBus = value;
576 uint32_t timerCnt = TIMER_getCount(obj->
timerHandle[timerNumber]);
638 TIMER_setPeriod(obj->
timerHandle[timerNumber], period);
652 uint32_t timerPeriod = TIMER_getPeriod(obj->
timerHandle[timerNumber]);
663 const ADC_SocNumber_e socNumber,
664 const ADC_SocSampleDelay_e sampleDelay)
668 ADC_setSocSampleDelay(obj->
adcHandle,socNumber,sampleDelay);
681 uint_least8_t sensorNumber,
726 return(GPIO_read(obj->
gpioHandle,gpioNumber));
813 const uint_least8_t sensorNumber,
814 const _iq beta_lp_pu)
838 const uint_least8_t sensorNumber,
863 const uint_least8_t sensorNumber,
947 const uint_least16_t numPwmTicksPerIsrTick);
1021 PWMDAC_write_CmpA(obj->
pwmDacHandle[PWMDAC_Number_1],dacValue_1);
1022 PWMDAC_write_CmpB(obj->
pwmDacHandle[PWMDAC_Number_1],dacValue_2);
1023 PWMDAC_write_CmpA(obj->
pwmDacHandle[PWMDAC_Number_2],dacValue_3);
1024 PWMDAC_write_CmpA(obj->
pwmDacHandle[PWMDAC_Number_2],dacValue_4);
1045 for(cnt=0;cnt<3;cnt++)
1048 period = (
_iq)pwm->TBPRD;
1051 pwmData_sat_dc = pwmData_sat +
_IQ(0.5);
1052 value =
_IQmpy(pwmData_sat_dc, period);
1053 value_sat = (uint16_t)
_IQsat(value, period,
_IQ(0.0));
1056 PWM_write_CmpA(obj->
pwmHandle[cnt],value_sat);
1074 pwmValue = PWM_get_CmpA(obj->
pwmHandle[pwmNumber]);
1091 pwmValue = PWM_get_CmpB(obj->
pwmHandle[pwmNumber]);
1106 uint16_t pwmPeriodValue;
1108 pwmPeriodValue = PWM_getPeriod(obj->
pwmHandle[pwmNumber]);
1110 return(pwmPeriodValue);
1117 PWM_Obj *pwm1 = (PWM_Obj *)obj->
pwmHandle[PWM_Number_1];
1118 PWM_Obj *pwm2 = (PWM_Obj *)obj->
pwmHandle[PWM_Number_2];
1119 PWM_Obj *pwm3 = (PWM_Obj *)obj->
pwmHandle[PWM_Number_3];
1121 bool ignorepwm1 =
false;
1122 bool ignorepwm2 =
false;
1123 bool ignorepwm3 =
false;
1125 uint16_t nextPulse1 = (pwm1->CMPA + pwm1->CMPAM) / 2;
1126 uint16_t nextPulse2 = (pwm2->CMPA + pwm2->CMPAM) / 2;
1127 uint16_t nextPulse3 = (pwm3->CMPA + pwm3->CMPAM) / 2;
1128 uint16_t minNextPulse;
1130 if(nextPulse1 < minwidth) ignorepwm1 =
true;
1131 if(nextPulse2 < minwidth) ignorepwm2 =
true;
1132 if(nextPulse3 < minwidth) ignorepwm3 =
true;
1134 if((ignorepwm1 ==
false) && (ignorepwm2 ==
false) && (ignorepwm3 ==
false))
1136 minNextPulse = nextPulse1;
1137 pwm = (PWM_Obj *)obj->
pwmHandle[PWM_Number_1];
1139 if(minNextPulse > nextPulse2)
1141 minNextPulse = nextPulse2;
1142 pwm = (PWM_Obj *)obj->
pwmHandle[PWM_Number_2];
1145 if(minNextPulse > nextPulse3)
1147 minNextPulse = nextPulse3;
1148 pwm = (PWM_Obj *)obj->
pwmHandle[PWM_Number_3];
1151 else if((ignorepwm1 ==
false) && (ignorepwm2 ==
false) && (ignorepwm3 ==
true))
1153 minNextPulse = nextPulse1;
1154 pwm = (PWM_Obj *)obj->
pwmHandle[PWM_Number_1];
1156 if(minNextPulse > nextPulse2)
1158 minNextPulse = nextPulse2;
1159 pwm = (PWM_Obj *)obj->
pwmHandle[PWM_Number_2];
1162 else if((ignorepwm1 ==
false) && (ignorepwm2 ==
true) && (ignorepwm3 ==
false))
1164 minNextPulse = nextPulse1;
1165 pwm = (PWM_Obj *)obj->
pwmHandle[PWM_Number_1];
1167 if(minNextPulse > nextPulse3)
1169 minNextPulse = nextPulse3;
1170 pwm = (PWM_Obj *)obj->
pwmHandle[PWM_Number_3];
1173 else if((ignorepwm1 ==
false) && (ignorepwm2 ==
true) && (ignorepwm3 ==
true))
1175 minNextPulse = nextPulse1;
1176 pwm = (PWM_Obj *)obj->
pwmHandle[PWM_Number_1];
1178 else if((ignorepwm1 ==
true) && (ignorepwm2 ==
false) && (ignorepwm3 ==
false))
1180 minNextPulse = nextPulse2;
1181 pwm = (PWM_Obj *)obj->
pwmHandle[PWM_Number_2];
1183 if(minNextPulse > nextPulse3)
1185 minNextPulse = nextPulse3;
1186 pwm = (PWM_Obj *)obj->
pwmHandle[PWM_Number_3];
1189 else if((ignorepwm1 ==
true) && (ignorepwm2 ==
false) && (ignorepwm3 ==
true))
1191 minNextPulse = nextPulse2;
1192 pwm = (PWM_Obj *)obj->
pwmHandle[PWM_Number_2];
1194 else if((ignorepwm1 ==
true) && (ignorepwm2 ==
true) && (ignorepwm3 ==
false))
1196 minNextPulse = nextPulse3;
1197 pwm = (PWM_Obj *)obj->
pwmHandle[PWM_Number_3];
1201 minNextPulse = nextPulse1;
1202 pwm = (PWM_Obj *)obj->
pwmHandle[PWM_Number_1];
1205 if(pwm->CMPAM >= (pwm->CMPA + pwm->DBFED))
1207 pwm1->CMPB = (pwm->CMPAM - (pwm->CMPA + pwm->DBFED)) / 2 + 1;
1208 PWM_setSocAPulseSrc(obj->
pwmHandle[PWM_Number_1],PWM_SocPulseSrc_CounterEqualCmpBDecr);
1212 pwm1->CMPB = ((pwm->CMPA + pwm->DBFED) - pwm->CMPAM) / 2 + 1;
1213 PWM_setSocAPulseSrc(obj->
pwmHandle[PWM_Number_1],PWM_SocPulseSrc_CounterEqualCmpBIncr);
1280 #endif // extern "C"
1283 #endif // end of _HAL_H_ definition
OFFSET_Handle offsetHandle_I[3]
the handles for the current offset estimators
static void HAL_acqTimer0Int(HAL_Handle handle)
Acknowledges an interrupt from Timer 0 so that another Timer 0 interrupt can happen again...
void HAL_enableGlobalInts(HAL_Handle handle)
Enables global interrupts.
void HAL_enableAdcInts(HAL_Handle handle)
Enables the ADC interrupts.
static bool HAL_readGpio(HAL_Handle handle, const GPIO_Number_e gpioNumber)
Reads the specified GPIO pin.
static uint_least8_t HAL_getNumCurrentSensors(HAL_Handle handle)
Gets the number of current sensors.
void HAL_disableGlobalInts(HAL_Handle handle)
Disables global interrupts.
static _iq HAL_getVoltageScaleFactor(HAL_Handle handle)
Gets the voltage scale factor.
static void HAL_setBias(HAL_Handle handle, const HAL_SensorType_e sensorType, uint_least8_t sensorNumber, const _iq bias)
Sets the ADC bias value.
static void HAL_setNumVoltageSensors(HAL_Handle handle, const uint_least8_t numVoltageSensors)
Sets the number of voltage sensors.
void HAL_OscTempComp(HAL_Handle handle)
Executes the oscillator 1 and 2 calibration functions.
static uint16_t HAL_readPwmCmpB(HAL_Handle handle, const PWM_Number_e pwmNumber)
Reads PWM compare register B.
interrupt void mainISR(void)
void HAL_writeDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
Writes data to the driver.
static void HAL_setTrigger(HAL_Handle handle, const int16_t minwidth)
GPIO pin number for LaunchPad LED D10.
static void HAL_setGpioLow(HAL_Handle handle, const GPIO_Number_e gpioNumber)
Sets the GPIO pin low.
static void HAL_setCurrentScaleFactor(HAL_Handle handle, const _iq current_sf)
Sets the current scale factor in the hardware abstraction layer.
static void HAL_updateAdcBias(HAL_Handle handle)
Updates the ADC bias values.
Defines a structure for the user parameters.
void HAL_AdcCalChanSelect(HAL_Handle handle, const ADC_SocChanNumber_e chanNumber)
Selects the analog channel used for calibration.
_iq current_sf
the current scale factor, amps_pu/cnt
HAL_QepSelect_e
Enumeration for the QEP setup.
void HAL_setupPeripheralClks(HAL_Handle handle)
Sets up the peripheral clocks.
HAL_SensorType_e
Enumeration for the sensor types.
static uint16_t HAL_readPwmCmpA(HAL_Handle handle, const PWM_Number_e pwmNumber)
Reads PWM compare register A.
void HAL_setupTimers(HAL_Handle handle, const float_t systemFreq_MHz)
Sets up the timers.
void HAL_osc2Comp(HAL_Handle handle, const int16_t sensorSample)
Executes the oscillator 2 calibration based on input sample.
void HAL_setupPll(HAL_Handle handle, const PLL_ClkFreq_e clkFreq)
Sets up the PLL (Phase Lock Loop)
HAL_AdcData_t adcBias
the ADC bias
static void HAL_writePwmData(HAL_Handle handle, HAL_PwmData_t *pPwmData)
Writes PWM data to the PWM comparators for motor control.
Enumeration for current sensor.
PWMDAC_Handle pwmDacHandle[3]
void HAL_setupGpios(HAL_Handle handle)
Sets up the GPIO (General Purpose I/O) pins.
static uint32_t HAL_readTimerCnt(HAL_Handle handle, const uint_least8_t timerNumber)
Reads the timer count.
static void HAL_acqPwmInt(HAL_Handle handle, const PWM_Number_e pwmNumber)
Acknowledges an interrupt from the PWM so that another PWM interrupt can happen again.
void HAL_setupFlash(HAL_Handle handle)
Sets up the FLASH.
void OFFSET_setInitCond(OFFSET_Handle handle, const _iq initCond)
Set the initial condition of the integrator or the value of y[n-1].
static void HAL_disablePwm(HAL_Handle handle)
Disables the PWM device.
void HAL_enablePwmInt(HAL_Handle handle)
Enables the PWM interrupt.
void HAL_setupClks(HAL_Handle handle)
Sets up the clocks.
static void HAL_setGpioHigh(HAL_Handle handle, const GPIO_Number_e gpioNumber)
Sets the GPIO pin high.
void HAL_setupFaults(HAL_Handle handle)
Configures the fault protection logic.
MATH_vec3 Tabc
the PWM time-durations for each motor phase
static void HAL_writeDacData(HAL_Handle handle, HAL_DacData_t *pDacData)
Writes DAC data to the PWM comparators for DAC (digital-to-analog conversion) output.
void HAL_enableDrv(HAL_Handle handle)
Enables the 8301 device.
void HAL_osc1Comp(HAL_Handle handle, const int16_t sensorSample)
Executes the oscillator 1 calibration based on input sample.
static _iq HAL_getCurrentScaleFactor(HAL_Handle handle)
Gets the current scale factor.
void OFFSET_setOffset(OFFSET_Handle handle, _iq offsetValue)
Sets the offset value.
uint_least8_t numCurrentSensors
the number of current sensors
void HAL_setupDrvSpi(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
Sets up the SPI interface for the driver.
void HAL_setupPwms(HAL_Handle handle, const float_t systemFreq_MHz, const float_t pwmPeriod_usec, const uint_least16_t numPwmTicksPerIsrTick)
Sets up the PWMs (Pulse Width Modulators)
void HAL_setupPie(HAL_Handle handle)
Sets up the PIE (Peripheral Interrupt Expansion)
void HAL_enableDebugInt(HAL_Handle handle)
Enables the debug interrupt.
static void HAL_setAdcSocSampleDelay(HAL_Handle handle, const ADC_SocNumber_e socNumber, const ADC_SocSampleDelay_e sampleDelay)
Sets the ADC SOC sample delay value.
static void HAL_setVoltageScaleFactor(HAL_Handle handle, const _iq voltage_sf)
Sets the voltage scale factor in the hardware abstraction layer.
static void HAL_setTimerPeriod(HAL_Handle handle, const uint_least8_t timerNumber, const uint32_t period)
Sets the timer period.
static void HAL_stopTimer(HAL_Handle handle, const uint_least8_t timerNumber)
Stops the timer.
static void HAL_initIntVectorTable(HAL_Handle handle)
Initializes the interrupt vector table.
_iq voltage_sf
the voltage scale factor, volts_pu/cnt
static uint_least8_t HAL_getNumVoltageSensors(HAL_Handle handle)
Gets the number of voltage sensors.
static void HAL_setOffsetValue(HAL_Handle handle, const HAL_SensorType_e sensorType, const uint_least8_t sensorNumber, const _iq value)
Sets the initial offset value for offset estimation.
void HAL_setupSpiB(HAL_Handle handle)
Sets up the spiB peripheral.
static void HAL_reloadTimer(HAL_Handle handle, const uint_least8_t timerNumber)
Reloads the timer.
void HAL_AdcOffsetSelfCal(HAL_Handle handle)
Executes the offset calibration of the ADC.
static ADC_SocSampleDelay_e HAL_getAdcSocSampleDelay(HAL_Handle handle, const ADC_SocNumber_e socNumber)
Gets the ADC delay value.
void OFFSET_setBeta(OFFSET_Handle handle, const _iq beta)
Sets the beta offset filter coefficient.
ADC_Handle adcHandle
the ADC handle
HAL_Handle HAL_init(void *pMemory, const size_t numBytes)
Initializes the hardware abstraction layer (HAL) object.
static uint32_t HAL_getTimerPeriod(HAL_Handle handle, const uint_least8_t timerNumber)
Gets the timer period.
static void HAL_toggleGpio(HAL_Handle handle, const GPIO_Number_e gpioNumber)
Toggles the GPIO pin.
static uint16_t HAL_readPwmPeriod(HAL_Handle handle, const PWM_Number_e pwmNumber)
Reads PWM period register.
void HAL_cal(HAL_Handle handle)
Executes calibration routines.
void HAL_setupGate(HAL_Handle handle)
Sets up the GATE object.
static void HAL_acqAdcInt(HAL_Handle handle, const ADC_IntNumber_e intNumber)
Acknowledges an interrupt from the ADC so that another ADC interrupt can happen again.
_iq OFFSET_getBeta(OFFSET_Handle handle)
Gets the beta offset filter coefficient.
static _iq HAL_getOffsetValue(HAL_Handle handle, const HAL_SensorType_e sensorType, const uint_least8_t sensorNumber)
Gets the offset value.
TIMER_Handle timerHandle[3]
Enumeration for voltage sensor.
uint16_t HAL_AdcCalConversion(HAL_Handle handle)
Reads the converted value from the selected calibration channel.
MATH_vec3 V
the voltage values
void HAL_setupPwmDacs(HAL_Handle handle)
Sets up the PWM DACs (Pulse Width Modulator Digital to Analof Converters)
GPIO pin number for LaunchPad LED D9.
MATH_vec3 I
the current values
uint16_t HAL_getOscTrimValue(int16_t coarse, int16_t fine)
Converts coarse and fine oscillator trim values into a single 16bit word value.
#define _IQsat(A, Pos, Neg)
static void HAL_startTimer(HAL_Handle handle, const uint_least8_t timerNumber)
Starts the timer.
static void HAL_setOffsetBeta_lp_pu(HAL_Handle handle, const HAL_SensorType_e sensorType, const uint_least8_t sensorNumber, const _iq beta_lp_pu)
Sets the value used to set the low pass filter pole for offset estimation.
void HAL_setupSpiA(HAL_Handle handle)
Sets up the spiA peripheral.
void HAL_setParams(HAL_Handle handle, const USER_Params *pUserParams)
Sets the hardware abstraction layer parameters.
void HAL_readDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
Reads data from the driver.
static void HAL_enablePwm(HAL_Handle handle)
Enables the PWM devices.
static void HAL_setNumCurrentSensors(HAL_Handle handle, const uint_least8_t numCurrentSensors)
Sets the number of current sensors.
static _iq HAL_getBias(HAL_Handle handle, const HAL_SensorType_e sensorType, uint_least8_t sensorNumber)
Gets the ADC bias value.
void HAL_setupAdcs(HAL_Handle handle)
Sets up the ADCs (Analog to Digital Converters)
uint_least8_t numVoltageSensors
the number of voltage sensors
void HAL_enableTimer0Int(HAL_Handle handle)
Enables the Timer 0 interrupt.
HAL_LedNumber_e
Enumeration for the LED numbers.
void HAL_disableWdog(HAL_Handle halHandle)
Disables the watch dog.
OFFSET_Handle offsetHandle_V[3]
the handles for the voltage offset estimators
static _iq OFFSET_getOffset(OFFSET_Handle handle)
Gets the offset value.
static void HAL_readAdcData(HAL_Handle handle, HAL_AdcData_t *pAdcData)
Reads the ADC data.
static _iq HAL_getOffsetBeta_lp_pu(HAL_Handle handle, const HAL_SensorType_e sensorType, const uint_least8_t sensorNumber)
Gets the value used to set the low pass filter pole for offset estimation.
float float_t
Defines the portable data type for 32 bit, signed floating-point data.
Defines the hardware abstraction layer (HAL) data.
static void HAL_setOffsetInitCond(HAL_Handle handle, const HAL_SensorType_e sensorType, const uint_least8_t sensorNumber, const _iq initCond)
Sets the offset initial condition value for offset estimation.
GPIO_Handle gpioHandle
the GPIO handle