64 #define Device_cal (void (*)(void))0x3D7C80
69 #define FP_SCALE 32768
72 #define FP_ROUND FP_SCALE/2
77 #define OSC_POSTRIM 32
78 #define OSC_POSTRIM_OFF FP_SCALE*OSC_POSTRIM
84 #define getOsc1FineTrimSlope() (*(int16_t (*)(void))0x3D7E90)()
87 #define getOsc1FineTrimOffset() (*(int16_t (*)(void))0x3D7E93)()
90 #define getOsc1CoarseTrim() (*(int16_t (*)(void))0x3D7E96)()
94 #define getOsc2FineTrimSlope() (*(int16_t (*)(void))0x3D7E99)()
97 #define getOsc2FineTrimOffset() (*(int16_t (*)(void))0x3D7E9C)()
100 #define getOsc2CoarseTrim() (*(int16_t (*)(void))0x3D7E9F)()
103 #define getRefTempOffset() (*(int16_t (*)(void))0x3D7EA2)()
108 #define HAL_PWM_DBFED_CNT (uint16_t)(2.0 * (float_t)USER_SYSTEM_FREQ_MHz) // 2 usec
113 #define HAL_PWM_DBRED_CNT (uint16_t)(2.0 * (float_t)USER_SYSTEM_FREQ_MHz) // 2 usec
118 #define HAL_readSW HAL_readGpio
123 #define HAL_turnLedOff HAL_setGpioLow
128 #define HAL_turnLedOn HAL_setGpioHigh
133 #define HAL_toggleLed HAL_toggleGpio
194 extern interrupt
void led2ISR(
void);
197 extern interrupt
void mainISR(
void);
223 ADC_clearIntFlag(obj->
adcHandle,intNumber);
227 PIE_clearInt(obj->
pieHandle,PIE_GroupNumber_10);
243 PWM_clearIntFlag(obj->
pwmHandle[pwmNumber]);
247 PWM_clearSocAFlag(obj->
pwmHandle[pwmNumber]);
251 PIE_clearInt(obj->
pieHandle,PIE_GroupNumber_3);
278 PWM_setOneShotTrip(obj->
pwmHandle[PWM_Number_1]);
279 PWM_setOneShotTrip(obj->
pwmHandle[PWM_Number_2]);
280 PWM_setOneShotTrip(obj->
pwmHandle[PWM_Number_3]);
326 PWM_clearOneShotTrip(obj->
pwmHandle[PWM_Number_1]);
327 PWM_clearOneShotTrip(obj->
pwmHandle[PWM_Number_2]);
328 PWM_clearOneShotTrip(obj->
pwmHandle[PWM_Number_3]);
356 const ADC_SocNumber_e socNumber)
360 return(ADC_getSocSampleDelay(obj->
adcHandle,socNumber));
374 uint_least8_t sensorNumber)
410 pDutyCycles[0] = PWM_get_CmpA(obj->
pwmHandle[PWM_Number_1]);
411 pDutyCycles[1] = PWM_get_CmpA(obj->
pwmHandle[PWM_Number_2]);
412 pDutyCycles[2] = PWM_get_CmpA(obj->
pwmHandle[PWM_Number_3]);
489 PIE_Obj *pie = (PIE_Obj *)obj->
pieHandle;
492 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
499 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
554 value = value * voltage_sf;
573 pAdcData->
I_A.
value[0] = value * current_sf;
577 pAdcData->
I_A.
value[1] = value * current_sf;
581 pAdcData->
I_A.
value[2] = value * current_sf;
585 pAdcData->
V_V.
value[0] = value * voltage_sf;
589 pAdcData->
V_V.
value[1] = value * voltage_sf;
593 pAdcData->
V_V.
value[2] = value * voltage_sf;
597 pAdcData->
dcBus_V = value * voltage_sf;
610 uint32_t timerCnt = TIMER_getCount(obj->
timerHandle[timerNumber]);
620 PWM_Number_e pwmNumber)
624 PWM_setCount(obj->
pwmHandle[pwmNumber],0);
635 const ADC_SocNumber_e socNumber,
636 const ADC_SocSampleDelay_e sampleDelay)
640 ADC_setSocSampleDelay(obj->
adcHandle,socNumber,sampleDelay);
653 uint_least8_t sensorNumber,
749 PWM_Number_e pwmNumber,
754 PWM_setPeriod(obj->
pwmHandle[pwmNumber],pwmFreq_kHz);
831 const uint_least16_t numPwmTicksPerIsrTick);
906 uint_least8_t pwmCnt;
907 uint_least8_t dataCnt=0;
909 for(pwmCnt=0;pwmCnt<3;pwmCnt++)
917 float_t V_sat_dc_pu = V_sat_pu + 0.5;
918 int16_t pwmValue = (int16_t)(V_sat_dc_pu * period);
930 float_t V_sat_dc_pu = V_sat_pu + 0.5;
931 int16_t pwmValue = (int16_t)(V_sat_dc_pu * period);
951 uint_least8_t pwmCnt;
953 for(pwmCnt=0;pwmCnt<3;pwmCnt++)
955 PWM_Obj *pwm = (PWM_Obj *)obj->
pwmHandle[pwmCnt];
961 float_t V_sat_dc_pu = V_sat_pu + 0.5;
962 int16_t pwmValue = (int16_t)(V_sat_dc_pu * period);
965 PWM_write_CmpA(obj->
pwmHandle[pwmCnt],pwmValue);
980 uint16_t pwmPeriodValue;
982 pwmPeriodValue = PWM_getPeriod(obj->
pwmHandle[pwmNumber]);
984 return(pwmPeriodValue);
995 #endif // end of _HAL_H_ definition
static void HAL_getDutyCycles(HAL_Handle handle, uint16_t *pDutyCycles)
Gets the PWM duty cycle times.
static void HAL_enablePwm(HAL_Handle handle)
Enables the PWM devices.
void HAL_enableGlobalInts(HAL_Handle handle)
Enables global interrupts.
void HAL_enableAdcInts(HAL_Handle handle)
Enables the ADC interrupts.
static void HAL_readAdcDataWithOffsets(HAL_Handle handle, HAL_AdcData_t *pAdcData)
static void HAL_toggleGpio(HAL_Handle handle, const GPIO_Number_e gpioNumber)
Toggles the GPIO pin.
void HAL_disableGlobalInts(HAL_Handle handle)
Disables global interrupts.
MATH_vec3 Vabc_pu
the PWM time-durations for each motor phase
static uint_least8_t HAL_getNumVoltageSensors(HAL_Handle handle)
Gets the number of voltage sensors.
static void HAL_writePwmData(HAL_Handle handle, const HAL_PwmData_t *pPwmData)
Writes PWM data to the PWM comparators for motor control.
HAL_PwmFreq_e
Enumeration for the PWM frequencies.
static void HAL_readAdcData(HAL_Handle handle, HAL_AdcData_t *pAdcData)
Reads the ADC data.
void HAL_OscTempComp(HAL_Handle handle)
Executes the oscillator 1 and 2 calibration functions.
interrupt void mainISR(void)
CLK_Handle clkHandle
the clock handle
static float_t HAL_getVoltageScaleFactor(HAL_Handle handle)
Gets the voltage scale factor.
GPIO pin number for ControlCARD LED 3.
static void HAL_setGpioLow(HAL_Handle handle, const GPIO_Number_e gpioNumber)
Sets the GPIO pin low.
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.
HAL_SensorType_e
Enumeration for the sensor types.
static void HAL_disableTbClockSync(HAL_Handle handle)
Disables the ePWM module time base clock sync signal.
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.
PWMDAC_Handle pwmDacHandle[3]
static float_t HAL_getCurrentScaleFactor(HAL_Handle handle)
Gets the current scale factor.
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.
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.
void HAL_setupFaults(HAL_Handle handle)
Configures the fault protection logic.
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.
void HAL_osc1Comp(HAL_Handle handle, const int16_t sensorSample)
Executes the oscillator 1 calibration based on input sample.
static void HAL_setGpioHigh(HAL_Handle handle, const GPIO_Number_e gpioNumber)
Sets the GPIO pin high.
float_t dcBus_V
the dcBus value
uint_least8_t numCurrentSensors
the number of current sensors
static void HAL_enableTbClockSync(HAL_Handle handle)
Enables the ePWM module time base clock sync signal.
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)
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.
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 uint16_t HAL_readPwmPeriod(HAL_Handle handle, const PWM_Number_e pwmNumber)
Reads PWM period register.
MATH_vec3 I_A
the current values
uint16_t HAL_computeOscTrimValue(int16_t coarse, int16_t fine)
static void HAL_resetPwmCount(HAL_Handle handle, PWM_Number_e pwmNumber)
Resets the PWM count.
_iq voltage_sf
the voltage scale factor, volts_pu/cnt
static uint32_t HAL_readTimerCnt(HAL_Handle handle, const uint_least8_t timerNumber)
Reads the timer count.
MATH_vec3 V_V
the voltage values
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.
static void HAL_setPwmFreq_kHz(HAL_Handle handle, PWM_Number_e pwmNumber, HAL_PwmFreq_e pwmFreq_kHz)
Sets the PWM frequency.
static void HAL_setAdcSocSampleDelay(HAL_Handle handle, const ADC_SocNumber_e socNumber, const ADC_SocSampleDelay_e sampleDelay)
Sets the ADC SOC sample delay value.
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_updateAdcBias(HAL_Handle handle, OFFSET_Handle *pOffsetHandle_I, OFFSET_Handle *pOffsetHandle_V)
Updates the ADC bias values.
static float_t 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.
void HAL_cal(HAL_Handle handle)
Executes calibration routines.
static uint_least8_t HAL_getNumCurrentSensors(HAL_Handle handle)
Gets the number of current sensors.
TIMER_Handle timerHandle[3]
Enumeration for voltage sensor.
uint16_t HAL_AdcCalConversion(HAL_Handle handle)
Reads the converted value from the selected calibration channel.
void HAL_setupPwmDacs(HAL_Handle handle)
Sets up the PWM DACs (Pulse Width Modulator Digital to Analof Converters)
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.
GPIO pin number for ControlCARD LED 2.
interrupt void led2ISR(void)
static void HAL_initIntVectorTable(HAL_Handle handle)
Initializes the interrupt vector table.
void HAL_setParams(HAL_Handle handle, const USER_Params *pUserParams)
Sets the hardware abstraction layer parameters.
static void HAL_setNumCurrentSensors(HAL_Handle handle, const uint_least8_t numCurrentSensors)
Sets the number of current sensors.
static void HAL_setVoltageScaleFactor(HAL_Handle handle, const float_t voltage_sf)
Sets the voltage scale factor in the hal.
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_setBias(HAL_Handle handle, const HAL_SensorType_e sensorType, uint_least8_t sensorNumber, const float_t bias)
Sets the ADC bias value.
HAL_LedNumber_e
Enumeration for the LED numbers.
static _iq OFFSET_getOffset(OFFSET_Handle handle)
Gets the offset value.
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_setCurrentScaleFactor(HAL_Handle handle, const float_t current_sf)
Sets the current scale factor in the hal.