72 #define Device_cal (void (*)(void))0x3D7C80
76 #define FP_SCALE 32768
79 #define FP_ROUND FP_SCALE/2
84 #define OSC_POSTRIM 32
85 #define OSC_POSTRIM_OFF FP_SCALE*OSC_POSTRIM
90 #define getOsc1FineTrimSlope() (*(int16_t (*)(void))0x3D7E90)()
93 #define getOsc1FineTrimOffset() (*(int16_t (*)(void))0x3D7E93)()
96 #define getOsc1CoarseTrim() (*(int16_t (*)(void))0x3D7E96)()
100 #define getOsc2FineTrimSlope() (*(int16_t (*)(void))0x3D7E99)()
103 #define getOsc2FineTrimOffset() (*(int16_t (*)(void))0x3D7E9C)()
106 #define getOsc2CoarseTrim() (*(int16_t (*)(void))0x3D7E9F)()
109 #define getRefTempOffset() (*(int16_t (*)(void))0x3D7EA2)()
113 #define HAL_PWM_DBFED_CNT 1
118 #define HAL_PWM_DBRED_CNT 1
123 #define HAL_turnLedOff HAL_setGpioLow
128 #define HAL_turnLedOn HAL_setGpioHigh
133 #define HAL_toggleLed HAL_toggleGpio
170 extern interrupt
void mainISR(
void);
187 ADC_clearIntFlag(obj->
adcHandle,intNumber);
191 PIE_clearInt(obj->
pieHandle,PIE_GroupNumber_10);
207 PWM_clearIntFlag(obj->
pwmHandle[pwmNumber]);
211 PWM_clearSocAFlag(obj->
pwmHandle[pwmNumber]);
215 PIE_clearInt(obj->
pieHandle,PIE_GroupNumber_3);
234 PIE_clearInt(obj->
pieHandle,PIE_GroupNumber_1);
266 PWM_setOneShotTrip(obj->
pwmHandle[PWM_Number_1]);
267 PWM_setOneShotTrip(obj->
pwmHandle[PWM_Number_2]);
268 PWM_setOneShotTrip(obj->
pwmHandle[PWM_Number_3]);
308 PWM_clearOneShotTrip(obj->
pwmHandle[PWM_Number_1]);
309 PWM_clearOneShotTrip(obj->
pwmHandle[PWM_Number_2]);
310 PWM_clearOneShotTrip(obj->
pwmHandle[PWM_Number_3]);
331 const ADC_SocNumber_e socNumber)
335 return(ADC_getSocSampleDelay(obj->
adcHandle,socNumber));
349 uint_least8_t sensorNumber)
415 const uint_least8_t sensorNumber)
419 _iq beta_lp_pu =
_IQ(0.0);
443 const uint_least8_t sensorNumber)
501 PIE_Obj *pie = (PIE_Obj *)obj->
pieHandle;
504 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
508 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
532 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_1);
534 pAdcData->
I.
value[0] = value;
537 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_2);
539 pAdcData->
I.
value[1] = value;
542 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_3);
544 pAdcData->
I.
value[2] = value;
547 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_4);
549 pAdcData->
V.
value[0] = value;
552 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_5);
554 pAdcData->
V.
value[1] = value;
557 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_6);
559 pAdcData->
V.
value[2] = value;
562 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_7);
564 pAdcData->
dcBus = value;
588 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_1);
590 pAdcData->
I.
value[0] = value;
593 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_2);
595 pAdcData->
I.
value[1] = value;
598 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_3);
600 pAdcData->
I.
value[2] = value;
603 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_4);
605 pAdcData->
V.
value[0] = value;
608 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_5);
610 pAdcData->
V.
value[1] = value;
613 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_6);
615 pAdcData->
V.
value[2] = value;
618 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_7);
620 pAdcData->
dcBus = value;
633 uint32_t timerCnt = TIMER_getCount(obj->
timerHandle[timerNumber]);
695 TIMER_setPeriod(obj->
timerHandle[timerNumber], period);
709 uint32_t timerPeriod = TIMER_getPeriod(obj->
timerHandle[timerNumber]);
720 const ADC_SocNumber_e socNumber,
721 const ADC_SocSampleDelay_e sampleDelay)
725 ADC_setSocSampleDelay(obj->
adcHandle,socNumber,sampleDelay);
738 uint_least8_t sensorNumber,
783 return(GPIO_read(obj->
gpioHandle,gpioNumber));
870 const uint_least8_t sensorNumber,
871 const _iq beta_lp_pu)
895 const uint_least8_t sensorNumber,
920 const uint_least8_t sensorNumber,
1005 const uint_least16_t numPwmTicksPerIsrTick);
1084 PWMDAC_write_CmpA(obj->
pwmDacHandle[PWMDAC_Number_1],dacValue_1);
1085 PWMDAC_write_CmpB(obj->
pwmDacHandle[PWMDAC_Number_1],dacValue_2);
1086 PWMDAC_write_CmpA(obj->
pwmDacHandle[PWMDAC_Number_2],dacValue_3);
1087 PWMDAC_write_CmpB(obj->
pwmDacHandle[PWMDAC_Number_2],dacValue_4);
1108 for(cnt=0;cnt<3;cnt++)
1111 period = (
_iq)pwm->TBPRD;
1114 pwmData_sat_dc = pwmData_sat +
_IQ(0.5);
1115 value =
_IQmpy(pwmData_sat_dc, period);
1116 value_sat = (uint16_t)
_IQsat(value, period,
_IQ(0.0));
1119 PWM_write_CmpA(obj->
pwmHandle[cnt],value_sat);
1137 pwmValue = PWM_get_CmpA(obj->
pwmHandle[pwmNumber]);
1154 pwmValue = PWM_get_CmpAM(obj->
pwmHandle[pwmNumber]);
1171 pwmValue = PWM_get_CmpB(obj->
pwmHandle[pwmNumber]);
1186 uint16_t pwmPeriodValue;
1188 pwmPeriodValue = PWM_getPeriod(obj->
pwmHandle[pwmNumber]);
1190 return(pwmPeriodValue);
1198 PWM_Obj *pwm1 = (PWM_Obj *)obj->
pwmHandle[PWM_Number_1];
1199 PWM_Obj *pwm2 = (PWM_Obj *)obj->
pwmHandle[PWM_Number_2];
1200 PWM_Obj *pwm3 = (PWM_Obj *)obj->
pwmHandle[PWM_Number_3];
1203 uint16_t nextPulse1 = (pwm1->CMPA + pwm1->CMPAM) / 2;
1204 uint16_t nextPulse2 = (pwm2->CMPA + pwm2->CMPAM) / 2;
1205 uint16_t nextPulse3 = (pwm3->CMPA + pwm3->CMPAM) / 2;
1206 uint16_t pwmCMPA1 = pwm1->CMPA;
1207 uint16_t pwmCMPA2 = pwm2->CMPA;
1208 uint16_t pwmCMPA3 = pwm3->CMPA;
1214 if((nextPulse1 <= nextPulse2) && (nextPulse1 <= nextPulse3))
1218 else if((nextPulse2 <= nextPulse1) && (nextPulse2 <= nextPulse3))
1229 offset = pwmCMPA1 + cmpOffset;
1233 offset = pwmCMPA2 + cmpOffset;
1237 offset = pwmCMPA3 + cmpOffset;
1241 if(pwmCMPA1 > pwmCMPA2)
1243 offset = pwmCMPA1 + cmpOffset;
1247 offset = pwmCMPA2 + cmpOffset;
1252 if(pwmCMPA1 > pwmCMPA3)
1254 offset = pwmCMPA1 + cmpOffset;
1258 offset = pwmCMPA3 + cmpOffset;
1263 if(pwmCMPA2 > pwmCMPA3)
1265 offset = pwmCMPA2 + cmpOffset;
1269 offset = pwmCMPA3 + cmpOffset;
1276 if(pwm->CMPAM >= (pwm->CMPA + pwm->DBFED))
1278 pwm1->CMPB = (pwm->CMPAM - (pwm->CMPA + pwm->DBFED)) / 2 + 1;
1279 PWM_setSocAPulseSrc(obj->
pwmHandle[PWM_Number_1],PWM_SocPulseSrc_CounterEqualCmpBDecr);
1283 pwm1->CMPB = ((pwm->CMPA + pwm->DBFED) - pwm->CMPAM ) / 2 + 1;
1284 PWM_setSocAPulseSrc(obj->
pwmHandle[PWM_Number_1],PWM_SocPulseSrc_CounterEqualCmpBIncr);
1289 pwm1->CMPB = offset;
1290 PWM_setSocAPulseSrc(obj->
pwmHandle[PWM_Number_1],PWM_SocPulseSrc_CounterEqualCmpBIncr);
1297 static inline uint32_t HAL_getQepPosnCounts(
HAL_Handle handle)
1304 QEP_Obj *qep = (QEP_Obj *)obj->qepHandle[1];
1306 QEP_Obj *qep = (QEP_Obj *)obj->qepHandle[0];
1309 return qep->QPOSCNT;
1316 static inline uint32_t HAL_getQepPosnMaximum(
HAL_Handle handle)
1320 QEP_Obj *qep = (QEP_Obj *)obj->qepHandle[1];
1322 QEP_Obj *qep = (QEP_Obj *)obj->qepHandle[0];
1325 return qep->QPOSMAX;
1389 #endif // extern "C"
1392 #endif // end of _HAL_H_ definition
static ADC_SocSampleDelay_e HAL_getAdcSocSampleDelay(HAL_Handle handle, const ADC_SocNumber_e socNumber)
Gets the ADC delay value.
static void HAL_setNumVoltageSensors(HAL_Handle handle, const uint_least8_t numVoltageSensors)
Sets the number of voltage sensors.
static _iq HAL_getOffsetValue(HAL_Handle handle, const HAL_SensorType_e sensorType, const uint_least8_t sensorNumber)
Gets the offset value.
OFFSET_Handle offsetHandle_I[3]
the handles for the current offset estimators
void HAL_setupQEP(HAL_Handle handle, HAL_QepSelect_e qep)
Sets up the QEP peripheral.
void HAL_enableGlobalInts(HAL_Handle handle)
Enables global interrupts.
void HAL_enableAdcInts(HAL_Handle handle)
Enables the ADC interrupts.
static void HAL_setTimerPeriod(HAL_Handle handle, const uint_least8_t timerNumber, const uint32_t period)
Sets the timer period.
void HAL_disableGlobalInts(HAL_Handle handle)
Disables global interrupts.
static void HAL_setCurrentScaleFactor(HAL_Handle handle, const _iq current_sf)
Sets the current scale factor in the hardware abstraction layer.
static void HAL_reloadTimer(HAL_Handle handle, const uint_least8_t timerNumber)
Reloads the timer.
static void HAL_readAdcDataWithOffsets(HAL_Handle handle, HAL_AdcData_t *pAdcData)
Reads the ADC data.
static uint16_t HAL_readPwmCmpAM(HAL_Handle handle, const PWM_Number_e pwmNumber)
Reads PWM compare mirror register A.
static uint32_t HAL_getTimerPeriod(HAL_Handle handle, const uint_least8_t timerNumber)
Gets the timer period.
void HAL_OscTempComp(HAL_Handle handle)
Executes the oscillator 1 and 2 calibration functions.
Ignore the B phase shunt measurement.
static void HAL_writePwmData(HAL_Handle handle, HAL_PwmData_t *pPwmData)
Writes PWM data to the PWM comparators for motor control.
interrupt void mainISR(void)
Ignore the AC phase shunt measurement.
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_writeDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
Writes data to the driver.
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 pin number for LaunchPad LED D10.
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.
Defines a structure for the user parameters.
Ignore the A phase shunt measurement.
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.
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_setAdcSocSampleDelay(HAL_Handle handle, const ADC_SocNumber_e socNumber, const ADC_SocSampleDelay_e sampleDelay)
Sets the ADC SOC sample delay value.
Enumeration for current sensor.
static void HAL_setGpioLow(HAL_Handle handle, const GPIO_Number_e gpioNumber)
Sets the GPIO pin low.
PWMDAC_Handle pwmDacHandle[3]
void HAL_setupGpios(HAL_Handle handle)
Sets up the GPIO (General Purpose I/O) pins.
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_setupFlash(HAL_Handle handle)
Sets up the FLASH.
Ignore the AB phase shunt measurement.
void OFFSET_setInitCond(OFFSET_Handle handle, const _iq initCond)
Set the initial condition of the integrator or the value of y[n-1].
void HAL_enablePwmInt(HAL_Handle handle)
Enables the PWM interrupt.
void HAL_setupClks(HAL_Handle handle)
Sets up the clocks.
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_enablePwm(HAL_Handle handle)
Enables the PWM devices.
static void HAL_startTimer(HAL_Handle handle, const uint_least8_t timerNumber)
Starts the timer.
static void HAL_stopTimer(HAL_Handle handle, const uint_least8_t timerNumber)
Stops the timer.
static void HAL_setVoltageScaleFactor(HAL_Handle handle, const _iq voltage_sf)
Sets the voltage scale factor in the hardware abstraction layer.
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_getVoltageScaleFactor(HAL_Handle handle)
Gets the voltage scale factor.
void OFFSET_setOffset(OFFSET_Handle handle, _iq offsetValue)
Sets the offset value.
Contains the public interface to the Svgen Current module routines.
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.
SVGENCURRENT_IgnoreShunt_e
static bool HAL_readGpio(HAL_Handle handle, const GPIO_Number_e gpioNumber)
Reads the specified GPIO pin.
static void HAL_setNumCurrentSensors(HAL_Handle handle, const uint_least8_t numCurrentSensors)
Sets the number of current sensors.
_iq voltage_sf
the voltage scale factor, volts_pu/cnt
static void HAL_acqTimer0Int(HAL_Handle handle)
Acknowledges an interrupt from Timer 0 so that another Timer 0 interrupt can happen again...
static uint_least8_t HAL_getNumVoltageSensors(HAL_Handle handle)
Gets the number of voltage sensors.
static uint_least8_t HAL_getNumCurrentSensors(HAL_Handle handle)
Gets the number of current sensors.
void HAL_setupSpiB(HAL_Handle handle)
Sets up the spiB peripheral.
static uint32_t HAL_readTimerCnt(HAL_Handle handle, const uint_least8_t timerNumber)
Reads the timer count.
Use all shunt measurements.
void HAL_AdcOffsetSelfCal(HAL_Handle handle)
Executes the offset calibration of the ADC.
static void HAL_disablePwm(HAL_Handle handle)
Disables the PWM device.
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 uint16_t HAL_readPwmCmpA(HAL_Handle handle, const PWM_Number_e pwmNumber)
Reads PWM compare register A.
void HAL_cal(HAL_Handle handle)
Executes calibration routines.
void HAL_setupGate(HAL_Handle handle)
Sets up the GATE object.
static void HAL_readAdcData(HAL_Handle handle, HAL_AdcData_t *pAdcData)
Reads the ADC data.
static void HAL_setTrigger(HAL_Handle handle, const SVGENCURRENT_IgnoreShunt_e ignoreShunt, const int16_t minwidth, const int16_t cmpOffset)
_iq OFFSET_getBeta(OFFSET_Handle handle)
Gets the beta offset filter coefficient.
TIMER_Handle timerHandle[3]
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.
Enumeration for voltage sensor.
static void HAL_toggleGpio(HAL_Handle handle, const GPIO_Number_e gpioNumber)
Toggles the GPIO pin.
uint16_t HAL_AdcCalConversion(HAL_Handle handle)
Reads the converted value from the selected calibration channel.
static _iq HAL_getBias(HAL_Handle handle, const HAL_SensorType_e sensorType, uint_least8_t sensorNumber)
Gets the ADC bias value.
MATH_vec3 V
the voltage values
static _iq HAL_getCurrentScaleFactor(HAL_Handle handle)
Gets the current scale factor.
void HAL_setupPwmDacs(HAL_Handle handle)
Sets up the PWM DACs (Pulse Width Modulator Digital to Analof Converters)
static void HAL_setGpioHigh(HAL_Handle handle, const GPIO_Number_e gpioNumber)
Sets the GPIO pin high.
GPIO pin number for LaunchPad LED D9.
MATH_vec3 I
the current values
static void HAL_initIntVectorTable(HAL_Handle handle)
Initializes the interrupt vector table.
static void HAL_setBias(HAL_Handle handle, const HAL_SensorType_e sensorType, uint_least8_t sensorNumber, const _iq bias)
Sets the ADC bias value.
uint16_t HAL_getOscTrimValue(int16_t coarse, int16_t fine)
Converts coarse and fine oscillator trim values into a single 16bit word value.
static void HAL_updateAdcBias(HAL_Handle handle)
Updates the ADC bias values.
static uint16_t HAL_readPwmPeriod(HAL_Handle handle, const PWM_Number_e pwmNumber)
Reads PWM period register.
#define _IQsat(A, Pos, Neg)
void HAL_setupSpiA(HAL_Handle handle)
Sets up the spiA peripheral.
static uint16_t HAL_readPwmCmpB(HAL_Handle handle, const PWM_Number_e pwmNumber)
Reads PWM compare register B.
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.
void HAL_setupAdcs(HAL_Handle handle)
Sets up the ADCs (Analog to Digital Converters)
uint_least8_t numVoltageSensors
the number of voltage sensors
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_enableTimer0Int(HAL_Handle handle)
Enables the Timer 0 interrupt.
HAL_LedNumber_e
Enumeration for the LED numbers.
void HAL_disableWdog(HAL_Handle handle)
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.
Ignore the C phase shunt measurement.
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.
float float_t
Defines the portable data type for 32 bit, signed floating-point data.
Defines the hardware abstraction layer (HAL) data.
GPIO_Handle gpioHandle
the GPIO handle