65 #define Device_cal (void (*)(void))0x3D7C80
70 #define FP_SCALE 32768
73 #define FP_ROUND FP_SCALE/2
78 #define OSC_POSTRIM 32
79 #define OSC_POSTRIM_OFF FP_SCALE*OSC_POSTRIM
85 #define getOsc1FineTrimSlope() (*(int16_t (*)(void))0x3D7E90)()
88 #define getOsc1FineTrimOffset() (*(int16_t (*)(void))0x3D7E93)()
91 #define getOsc1CoarseTrim() (*(int16_t (*)(void))0x3D7E96)()
95 #define getOsc2FineTrimSlope() (*(int16_t (*)(void))0x3D7E99)()
98 #define getOsc2FineTrimOffset() (*(int16_t (*)(void))0x3D7E9C)()
101 #define getOsc2CoarseTrim() (*(int16_t (*)(void))0x3D7E9F)()
104 #define getRefTempOffset() (*(int16_t (*)(void))0x3D7EA2)()
109 #define HAL_PWM_DBFED_CNT 1
114 #define HAL_PWM_DBRED_CNT 1
119 #define HAL_turnLedOff HAL_setGpioLow
124 #define HAL_turnLedOn HAL_setGpioHigh
129 #define HAL_toggleLed HAL_toggleGpio
190 extern interrupt
void led2ISR(
void);
193 extern interrupt
void mainISR(
void);
219 ADC_clearIntFlag(obj->
adcHandle,intNumber);
223 PIE_clearInt(obj->
pieHandle,PIE_GroupNumber_10);
239 PWM_clearIntFlag(obj->
pwmHandle[pwmNumber]);
243 PWM_clearSocAFlag(obj->
pwmHandle[pwmNumber]);
247 PIE_clearInt(obj->
pieHandle,PIE_GroupNumber_3);
274 PWM_setOneShotTrip(obj->
pwmHandle[PWM_Number_1]);
275 PWM_setOneShotTrip(obj->
pwmHandle[PWM_Number_2]);
276 PWM_setOneShotTrip(obj->
pwmHandle[PWM_Number_3]);
322 PWM_clearOneShotTrip(obj->
pwmHandle[PWM_Number_1]);
323 PWM_clearOneShotTrip(obj->
pwmHandle[PWM_Number_2]);
324 PWM_clearOneShotTrip(obj->
pwmHandle[PWM_Number_3]);
352 const ADC_SocNumber_e socNumber)
356 return(ADC_getSocSampleDelay(obj->
adcHandle,socNumber));
370 uint_least8_t sensorNumber)
406 pDutyCycles[0] = PWM_get_CmpA(obj->
pwmHandle[PWM_Number_1]);
407 pDutyCycles[1] = PWM_get_CmpA(obj->
pwmHandle[PWM_Number_2]);
408 pDutyCycles[2] = PWM_get_CmpA(obj->
pwmHandle[PWM_Number_3]);
485 PIE_Obj *pie = (PIE_Obj *)obj->
pieHandle;
488 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
495 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
550 value = value * voltage_sf;
569 pAdcData->
I_A.
value[0] = value * current_sf;
573 pAdcData->
I_A.
value[1] = value * current_sf;
577 pAdcData->
I_A.
value[2] = value * current_sf;
581 pAdcData->
V_V.
value[0] = value * voltage_sf;
585 pAdcData->
V_V.
value[1] = value * voltage_sf;
589 pAdcData->
V_V.
value[2] = value * voltage_sf;
593 pAdcData->
dcBus_V = value * voltage_sf;
606 uint32_t timerCnt = TIMER_getCount(obj->
timerHandle[timerNumber]);
616 PWM_Number_e pwmNumber)
620 PWM_setCount(obj->
pwmHandle[pwmNumber],0);
631 const ADC_SocNumber_e socNumber,
632 const ADC_SocSampleDelay_e sampleDelay)
636 ADC_setSocSampleDelay(obj->
adcHandle,socNumber,sampleDelay);
649 uint_least8_t sensorNumber,
745 PWM_Number_e pwmNumber,
750 PWM_setPeriod(obj->
pwmHandle[pwmNumber],pwmFreq_kHz);
827 const uint_least16_t numPwmTicksPerIsrTick);
918 uint_least8_t pwmCnt;
919 uint_least8_t dataCnt=0;
921 for(pwmCnt=0;pwmCnt<3;pwmCnt++)
929 float_t V_sat_dc_pu = V_sat_pu + 0.5;
930 int16_t pwmValue = (int16_t)(V_sat_dc_pu * period);
942 float_t V_sat_dc_pu = V_sat_pu + 0.5;
943 int16_t pwmValue = (int16_t)(V_sat_dc_pu * period);
963 uint_least8_t pwmCnt;
965 for(pwmCnt=0;pwmCnt<3;pwmCnt++)
967 PWM_Obj *pwm = (PWM_Obj *)obj->
pwmHandle[pwmCnt];
973 float_t V_sat_dc_pu = V_sat_pu + 0.5;
974 int16_t pwmValue = (int16_t)(V_sat_dc_pu * period);
977 PWM_write_CmpA(obj->
pwmHandle[pwmCnt],pwmValue);
992 uint16_t pwmPeriodValue;
994 pwmPeriodValue = PWM_getPeriod(obj->
pwmHandle[pwmNumber]);
996 return(pwmPeriodValue);
1002 #endif // extern "C"
1007 #endif // end of _HAL_H_ definition
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_toggleGpio(HAL_Handle handle, const GPIO_Number_e gpioNumber)
Toggles the GPIO pin.
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 float_t HAL_getVoltageScaleFactor(HAL_Handle handle)
Gets the voltage scale factor.
void HAL_disableGlobalInts(HAL_Handle handle)
Disables global interrupts.
MATH_vec3 Vabc_pu
the PWM time-durations for each motor phase
HAL_PwmFreq_e
Enumeration for the PWM frequencies.
static void HAL_setVoltageScaleFactor(HAL_Handle handle, const float_t voltage_sf)
Sets the voltage scale factor in the hal.
void HAL_OscTempComp(HAL_Handle handle)
Executes the oscillator 1 and 2 calibration functions.
Contains the public interface to the math (MATH) module routines.
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.
interrupt void mainISR(void)
CLK_Handle clkHandle
the clock handle
GPIO pin number for ControlCARD LED 3.
static float_t HAL_getBias(HAL_Handle handle, const HAL_SensorType_e sensorType, uint_least8_t sensorNumber)
Gets the ADC bias value.
static float_t HAL_getCurrentScaleFactor(HAL_Handle handle)
Gets the current scale factor.
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
void HAL_setupPeripheralClks(HAL_Handle handle)
Sets up the peripheral clocks.
static void HAL_readAdcDataWithOffsets(HAL_Handle handle, HAL_AdcData_t *pAdcData)
HAL_SensorType_e
Enumeration for the sensor types.
void HAL_setupTimers(HAL_Handle handle, const float_t systemFreq_MHz)
Sets up the timers.
interrupt void led3OffISR(void)
interrupt void led3OnISR(void)
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_readAdcData(HAL_Handle handle, HAL_AdcData_t *pAdcData)
Reads the ADC data.
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.
void HAL_setupFlash(HAL_Handle handle)
Sets up the FLASH.
static float_t MATH_sat(const float_t in, const float_t max, const float_t min)
Saturates the input value between the minimum and maximum values.
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.
void HAL_osc1Comp(HAL_Handle handle, const int16_t sensorSample)
Executes the oscillator 1 calibration based on input sample.
static void HAL_enableTbClockSync(HAL_Handle handle)
Enables the ePWM module time base clock sync signal.
float_t dcBus_V
the dcBus value
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.
struct _OFFSET_Obj_ * OFFSET_Handle
Defines the OFFSET handle.
static void HAL_disablePwm(HAL_Handle handle)
Disables the PWM device.
static void HAL_writeDacData(HAL_Handle handle, const HAL_DacData_t *pDacData)
Writes DAC data to the PWM comparators for DAC (digital-to-analog conversion) output.
static void HAL_updateAdcBias(HAL_Handle handle, OFFSET_Handle *pOffsetHandle_I, OFFSET_Handle *pOffsetHandle_V)
Updates the ADC bias values.
MATH_vec3 I_A
the current values
uint16_t HAL_computeOscTrimValue(int16_t coarse, int16_t fine)
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_setBias(HAL_Handle handle, const HAL_SensorType_e sensorType, uint_least8_t sensorNumber, const float_t bias)
Sets the ADC bias value.
static void HAL_initIntVectorTable(HAL_Handle handle)
Initializes the interrupt vector table.
void HAL_setupSpiB(HAL_Handle handle)
Sets up the spiB peripheral.
MATH_vec3 V_V
the voltage values
void HAL_AdcOffsetSelfCal(HAL_Handle handle)
Executes the offset calibration of the ADC.
static void HAL_writePwmData(HAL_Handle handle, const HAL_PwmData_t *pPwmData)
Writes PWM data to the PWM comparators for motor control.
ADC_Handle adcHandle
the ADC handle
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.
HAL_Handle HAL_init(void *pMemory, const size_t numBytes)
Initializes the hardware abstraction layer (HAL) object.
static void HAL_disableTbClockSync(HAL_Handle handle)
Disables the ePWM module time base clock sync signal.
void HAL_cal(HAL_Handle handle)
Executes calibration routines.
static void HAL_setNumVoltageSensors(HAL_Handle handle, const uint_least8_t numVoltageSensors)
Sets the number of voltage sensors.
static void HAL_setCurrentScaleFactor(HAL_Handle handle, const float_t current_sf)
Sets the current scale factor in the hal.
TIMER_Handle timerHandle[3]
static uint16_t HAL_readPwmPeriod(HAL_Handle handle, const PWM_Number_e pwmNumber)
Reads PWM period register.
Enumeration for voltage sensor.
uint16_t HAL_AdcCalConversion(HAL_Handle handle)
Reads the converted value from the selected calibration channel.
static uint_least8_t HAL_getNumVoltageSensors(HAL_Handle handle)
Gets the number of voltage sensors.
static void HAL_enablePwm(HAL_Handle handle)
Enables the PWM devices.
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 ControlCARD LED 2.
interrupt void led2ISR(void)
static void HAL_setPwmFreq_kHz(HAL_Handle handle, PWM_Number_e pwmNumber, HAL_PwmFreq_e pwmFreq_kHz)
Sets the PWM frequency.
static void HAL_setGpioLow(HAL_Handle handle, const GPIO_Number_e gpioNumber)
Sets the GPIO pin low.
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.
static uint_least8_t HAL_getNumCurrentSensors(HAL_Handle handle)
Gets the number of current sensors.
void HAL_setupAdcs(HAL_Handle handle)
Sets up the ADCs (Analog to Digital Converters)
static uint32_t HAL_readTimerCnt(HAL_Handle handle, const uint_least8_t timerNumber)
Reads the timer count.
uint_least8_t numVoltageSensors
the number of voltage sensors
static void HAL_getDutyCycles(HAL_Handle handle, uint16_t *pDutyCycles)
Gets the PWM duty cycle times.
HAL_LedNumber_e
Enumeration for the LED numbers.
static _iq OFFSET_getOffset(OFFSET_Handle handle)
Gets the offset value.
static void HAL_resetPwmCount(HAL_Handle handle, PWM_Number_e pwmNumber)
Resets the PWM count.
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