69 #define Device_cal (void (*)(void))0x3D7C80
73 #define FP_SCALE 32768
76 #define FP_ROUND FP_SCALE/2
81 #define OSC_POSTRIM 32
82 #define OSC_POSTRIM_OFF FP_SCALE*OSC_POSTRIM
87 #define getOsc1FineTrimSlope() (*(int16_t (*)(void))0x3D7E90)()
90 #define getOsc1FineTrimOffset() (*(int16_t (*)(void))0x3D7E93)()
93 #define getOsc1CoarseTrim() (*(int16_t (*)(void))0x3D7E96)()
97 #define getOsc2FineTrimSlope() (*(int16_t (*)(void))0x3D7E99)()
100 #define getOsc2FineTrimOffset() (*(int16_t (*)(void))0x3D7E9C)()
103 #define getOsc2CoarseTrim() (*(int16_t (*)(void))0x3D7E9F)()
106 #define getRefTempOffset() (*(int16_t (*)(void))0x3D7EA2)()
110 #define HAL_PWM_DBFED_CNT 1
115 #define HAL_PWM_DBRED_CNT 1
120 #define HAL_turnLedOff HAL_setGpioLow
125 #define HAL_turnLedOn HAL_setGpioHigh
130 #define HAL_toggleLed HAL_toggleGpio
166 extern interrupt
void mainISR(
void);
183 ADC_clearIntFlag(obj->
adcHandle,intNumber);
187 PIE_clearInt(obj->
pieHandle,PIE_GroupNumber_10);
203 PWM_clearIntFlag(obj->
pwmHandle[pwmNumber]);
207 PWM_clearSocAFlag(obj->
pwmHandle[pwmNumber]);
211 PIE_clearInt(obj->
pieHandle,PIE_GroupNumber_3);
243 PWM_setOneShotTrip(obj->
pwmHandle[PWM_Number_1]);
244 PWM_setOneShotTrip(obj->
pwmHandle[PWM_Number_2]);
245 PWM_setOneShotTrip(obj->
pwmHandle[PWM_Number_3]);
279 PWM_clearOneShotTrip(obj->
pwmHandle[PWM_Number_1]);
280 PWM_clearOneShotTrip(obj->
pwmHandle[PWM_Number_2]);
281 PWM_clearOneShotTrip(obj->
pwmHandle[PWM_Number_3]);
297 const ADC_SocNumber_e socNumber)
301 return(ADC_getSocSampleDelay(obj->
adcHandle,socNumber));
315 uint_least8_t sensorNumber)
381 const uint_least8_t sensorNumber)
385 _iq beta_lp_pu =
_IQ(0.0);
409 const uint_least8_t sensorNumber)
467 PIE_Obj *pie = (PIE_Obj *)obj->
pieHandle;
470 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
474 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
498 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_1);
500 pAdcData->
I.
value[0] = value;
503 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_2);
505 pAdcData->
I.
value[1] = value;
508 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_3);
510 pAdcData->
I.
value[2] = value;
513 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_4);
515 pAdcData->
V.
value[0] = value;
518 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_5);
520 pAdcData->
V.
value[1] = value;
523 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_6);
525 pAdcData->
V.
value[2] = value;
528 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_7);
530 pAdcData->
dcBus = value;
554 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_1);
556 pAdcData->
I.
value[0] = value;
559 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_2);
561 pAdcData->
I.
value[1] = value;
564 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_3);
566 pAdcData->
I.
value[2] = value;
569 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_4);
571 pAdcData->
V.
value[0] = value;
574 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_5);
576 pAdcData->
V.
value[1] = value;
579 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_6);
581 pAdcData->
V.
value[2] = value;
584 value = (
_iq)ADC_readResult(obj->
adcHandle,ADC_ResultNumber_7);
586 pAdcData->
dcBus = value;
599 uint32_t timerCnt = TIMER_getCount(obj->
timerHandle[timerNumber]);
656 TIMER_setPeriod(obj->
timerHandle[timerNumber], period);
670 uint32_t timerPeriod = TIMER_getPeriod(obj->
timerHandle[timerNumber]);
681 const ADC_SocNumber_e socNumber,
682 const ADC_SocSampleDelay_e sampleDelay)
686 ADC_setSocSampleDelay(obj->
adcHandle,socNumber,sampleDelay);
699 uint_least8_t sensorNumber,
744 return(GPIO_read(obj->
gpioHandle,gpioNumber));
831 const uint_least8_t sensorNumber,
832 const _iq beta_lp_pu)
856 const uint_least8_t sensorNumber,
881 const uint_least8_t sensorNumber,
966 const uint_least16_t numPwmTicksPerIsrTick);
1040 PWMDAC_write_CmpA(obj->
pwmDacHandle[PWMDAC_Number_1],dacValue_1);
1041 PWMDAC_write_CmpB(obj->
pwmDacHandle[PWMDAC_Number_1],dacValue_2);
1042 PWMDAC_write_CmpA(obj->
pwmDacHandle[PWMDAC_Number_2],dacValue_3);
1043 PWMDAC_write_CmpA(obj->
pwmDacHandle[PWMDAC_Number_3],dacValue_4);
1064 for(cnt=0;cnt<3;cnt++)
1067 period = (
_iq)pwm->TBPRD;
1070 pwmData_sat_dc = pwmData_sat +
_IQ(0.5);
1071 value =
_IQmpy(pwmData_sat_dc, period);
1072 value_sat = (uint16_t)
_IQsat(value, period,
_IQ(0.0));
1075 PWM_write_CmpA(obj->
pwmHandle[cnt],value_sat);
1093 pwmValue = PWM_get_CmpA(obj->
pwmHandle[pwmNumber]);
1110 pwmValue = PWM_get_CmpAM(obj->
pwmHandle[pwmNumber]);
1127 pwmValue = PWM_get_CmpB(obj->
pwmHandle[pwmNumber]);
1142 uint16_t pwmPeriodValue;
1144 pwmPeriodValue = PWM_getPeriod(obj->
pwmHandle[pwmNumber]);
1146 return(pwmPeriodValue);
1154 PWM_Obj *pwm1 = (PWM_Obj *)obj->
pwmHandle[PWM_Number_1];
1155 PWM_Obj *pwm2 = (PWM_Obj *)obj->
pwmHandle[PWM_Number_2];
1156 PWM_Obj *pwm3 = (PWM_Obj *)obj->
pwmHandle[PWM_Number_3];
1159 uint16_t nextPulse1 = (pwm1->CMPA + pwm1->CMPAM) / 2;
1160 uint16_t nextPulse2 = (pwm2->CMPA + pwm2->CMPAM) / 2;
1161 uint16_t nextPulse3 = (pwm3->CMPA + pwm3->CMPAM) / 2;
1162 uint16_t pwmCMPA1 = pwm1->CMPA;
1163 uint16_t pwmCMPA2 = pwm2->CMPA;
1164 uint16_t pwmCMPA3 = pwm3->CMPA;
1170 if((nextPulse1 <= nextPulse2) && (nextPulse1 <= nextPulse3))
1174 else if((nextPulse2 <= nextPulse1) && (nextPulse2 <= nextPulse3))
1185 offset = pwmCMPA1 + cmpOffset;
1189 offset = pwmCMPA2 + cmpOffset;
1193 offset = pwmCMPA3 + cmpOffset;
1197 if(pwmCMPA1 > pwmCMPA2)
1199 offset = pwmCMPA1 + cmpOffset;
1203 offset = pwmCMPA2 + cmpOffset;
1208 if(pwmCMPA1 > pwmCMPA3)
1210 offset = pwmCMPA1 + cmpOffset;
1214 offset = pwmCMPA3 + cmpOffset;
1219 if(pwmCMPA2 > pwmCMPA3)
1221 offset = pwmCMPA2 + cmpOffset;
1225 offset = pwmCMPA3 + cmpOffset;
1232 if(pwm->CMPAM >= (pwm->CMPA + pwm->DBFED))
1234 pwm1->CMPB = (pwm->CMPAM - (pwm->CMPA + pwm->DBFED)) / 2 + 1;
1235 PWM_setSocAPulseSrc(obj->
pwmHandle[PWM_Number_1],PWM_SocPulseSrc_CounterEqualCmpBDecr);
1239 pwm1->CMPB = ((pwm->CMPA + pwm->DBFED) - pwm->CMPAM ) / 2 + 1;
1240 PWM_setSocAPulseSrc(obj->
pwmHandle[PWM_Number_1],PWM_SocPulseSrc_CounterEqualCmpBIncr);
1245 pwm1->CMPB = offset;
1246 PWM_setSocAPulseSrc(obj->
pwmHandle[PWM_Number_1],PWM_SocPulseSrc_CounterEqualCmpBIncr);
1253 static inline uint32_t HAL_getQepPosnCounts(
HAL_Handle handle)
1259 QEP_Obj *qep = (QEP_Obj *)obj->qepHandle[0];
1261 return qep->QPOSCNT;
1268 static inline uint32_t HAL_getQepPosnMaximum(
HAL_Handle handle)
1271 QEP_Obj *qep = (QEP_Obj *)obj->qepHandle[0];
1273 return qep->QPOSMAX;
1319 #endif // extern "C"
1322 #endif // end of _HAL_H_ definition
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.
static void HAL_readAdcData(HAL_Handle handle, HAL_AdcData_t *pAdcData)
Reads the ADC data.
static void HAL_setBias(HAL_Handle handle, const HAL_SensorType_e sensorType, uint_least8_t sensorNumber, const _iq bias)
Sets the ADC bias value.
void HAL_enableGlobalInts(HAL_Handle handle)
Enables global interrupts.
void HAL_enableAdcInts(HAL_Handle handle)
Enables the ADC interrupts.
static void HAL_initIntVectorTable(HAL_Handle handle)
Initializes the interrupt vector table.
void HAL_disableGlobalInts(HAL_Handle handle)
Disables global interrupts.
static _iq HAL_getBias(HAL_Handle handle, const HAL_SensorType_e sensorType, uint_least8_t sensorNumber)
Gets the ADC bias value.
static void HAL_setNumVoltageSensors(HAL_Handle handle, const uint_least8_t numVoltageSensors)
Sets the number of voltage sensors.
static _iq HAL_getVoltageScaleFactor(HAL_Handle handle)
Gets the voltage scale factor.
static bool HAL_readGpio(HAL_Handle handle, const GPIO_Number_e gpioNumber)
Reads the specified GPIO pin.
void HAL_OscTempComp(HAL_Handle handle)
Executes the oscillator 1 and 2 calibration functions.
Ignore the B phase shunt measurement.
static void HAL_toggleGpio(HAL_Handle handle, const GPIO_Number_e gpioNumber)
Toggles the GPIO pin.
interrupt void mainISR(void)
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.
Ignore the AC phase shunt measurement.
static void HAL_enablePwm(HAL_Handle handle)
Enables the PWM devices.
GPIO pin number for ControlCARD LED 3.
static _iq HAL_getCurrentScaleFactor(HAL_Handle handle)
Gets the current scale factor.
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.
static void HAL_setTrigger(HAL_Handle handle, const SVGENCURRENT_IgnoreShunt_e ignoreShunt, const int16_t minwidth, const int16_t cmpOffset)
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
Enumeration for current sensor.
static void HAL_setTimerPeriod(HAL_Handle handle, const uint_least8_t timerNumber, const uint32_t period)
Sets the timer period.
static uint16_t HAL_readPwmCmpA(HAL_Handle handle, const PWM_Number_e pwmNumber)
Reads PWM compare register A.
PWMDAC_Handle pwmDacHandle[3]
static ADC_SocSampleDelay_e HAL_getAdcSocSampleDelay(HAL_Handle handle, const ADC_SocNumber_e socNumber)
Gets the ADC delay value.
void HAL_setupGpios(HAL_Handle handle)
Sets up the GPIO (General Purpose I/O) pins.
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.
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].
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_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.
static void HAL_setNumCurrentSensors(HAL_Handle handle, const uint_least8_t numCurrentSensors)
Sets the number of current sensors.
static void HAL_disablePwm(HAL_Handle handle)
Disables the PWM device.
MATH_vec3 Tabc
the PWM time-durations for each motor phase
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.
static void HAL_stopTimer(HAL_Handle handle, const uint_least8_t timerNumber)
Stops the timer.
static void HAL_setCurrentScaleFactor(HAL_Handle handle, const _iq current_sf)
Sets the current scale factor in the hardware abstraction layer.
static void HAL_setGpioHigh(HAL_Handle handle, const GPIO_Number_e gpioNumber)
Sets the GPIO pin high.
static uint_least8_t HAL_getNumCurrentSensors(HAL_Handle handle)
Gets the number of current sensors.
void HAL_osc1Comp(HAL_Handle handle, const int16_t sensorSample)
Executes the oscillator 1 calibration based on input sample.
static void HAL_updateAdcBias(HAL_Handle handle)
Updates the ADC bias values.
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.
static _iq HAL_getOffsetValue(HAL_Handle handle, const HAL_SensorType_e sensorType, const uint_least8_t sensorNumber)
Gets the offset value.
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_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 void HAL_startTimer(HAL_Handle handle, const uint_least8_t timerNumber)
Starts the timer.
_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_setGpioLow(HAL_Handle handle, const GPIO_Number_e gpioNumber)
Sets the GPIO pin low.
Use all shunt measurements.
void HAL_AdcOffsetSelfCal(HAL_Handle handle)
Executes the offset calibration of the ADC.
static uint16_t HAL_readPwmCmpAM(HAL_Handle handle, const PWM_Number_e pwmNumber)
Reads PWM compare mirror register A.
void OFFSET_setBeta(OFFSET_Handle handle, const _iq beta)
Sets the beta offset filter coefficient.
static uint16_t HAL_readPwmPeriod(HAL_Handle handle, const PWM_Number_e pwmNumber)
Reads PWM period register.
ADC_Handle adcHandle
the ADC handle
HAL_Handle HAL_init(void *pMemory, const size_t numBytes)
Initializes the hardware abstraction layer (HAL) object.
static void HAL_setVoltageScaleFactor(HAL_Handle handle, const _iq voltage_sf)
Sets the voltage 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_writePwmData(HAL_Handle handle, HAL_PwmData_t *pPwmData)
Writes PWM data to the PWM comparators for motor control.
static void HAL_readAdcDataWithOffsets(HAL_Handle handle, HAL_AdcData_t *pAdcData)
Reads the ADC data.
void HAL_cal(HAL_Handle handle)
Executes calibration routines.
_iq OFFSET_getBeta(OFFSET_Handle handle)
Gets the beta offset filter coefficient.
TIMER_Handle timerHandle[3]
Enumeration for voltage sensor.
uint16_t HAL_AdcCalConversion(HAL_Handle handle)
Reads the converted value from the selected calibration channel.
static uint16_t HAL_readPwmCmpB(HAL_Handle handle, const PWM_Number_e pwmNumber)
Reads PWM compare register B.
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 ControlCARD LED 2.
MATH_vec3 I
the current values
static uint32_t HAL_readTimerCnt(HAL_Handle handle, const uint_least8_t timerNumber)
Reads the timer count.
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)
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_setupAdcs(HAL_Handle handle)
Sets up the ADCs (Analog to Digital Converters)
uint_least8_t numVoltageSensors
the number of voltage sensors
HAL_LedNumber_e
Enumeration for the LED numbers.
void HAL_disableWdog(HAL_Handle halHandle)
Disables the watch dog.
static uint32_t HAL_getTimerPeriod(HAL_Handle handle, const uint_least8_t timerNumber)
Gets the timer period.
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_acqPwmInt(HAL_Handle handle, const PWM_Number_e pwmNumber)
Acknowledges an interrupt from the PWM so that another PWM interrupt can happen again.
static void HAL_setAdcSocSampleDelay(HAL_Handle handle, const ADC_SocNumber_e socNumber, const ADC_SocSampleDelay_e sampleDelay)
Sets the ADC SOC sample delay value.
Ignore the C phase shunt measurement.
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
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.