68 #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
88 #define getOsc1FineTrimSlope() (*(int16_t (*)(void))0x3D7E90)()
91 #define getOsc1FineTrimOffset() (*(int16_t (*)(void))0x3D7E93)()
94 #define getOsc1CoarseTrim() (*(int16_t (*)(void))0x3D7E96)()
98 #define getOsc2FineTrimSlope() (*(int16_t (*)(void))0x3D7E99)()
101 #define getOsc2FineTrimOffset() (*(int16_t (*)(void))0x3D7E9C)()
104 #define getOsc2CoarseTrim() (*(int16_t (*)(void))0x3D7E9F)()
107 #define getRefTempOffset() (*(int16_t (*)(void))0x3D7EA2)()
112 #define HAL_PWM_DBFED_CNT (uint16_t)(0.050 * (float_t)USER_SYSTEM_FREQ_MHz) // 50 ns
117 #define HAL_PWM_DBRED_CNT (uint16_t)(0.050 * (float_t)USER_SYSTEM_FREQ_MHz) // 50 ns
122 #define HAL_readSW HAL_readGpio
127 #define HAL_turnLedOff HAL_setGpioLow
132 #define HAL_turnLedOn HAL_setGpioHigh
137 #define HAL_toggleLed HAL_toggleGpio
207 extern interrupt
void led2ISR(
void);
210 extern interrupt
void mainISR(
void);
236 ADC_clearIntFlag(obj->
adcHandle,intNumber);
240 PIE_clearInt(obj->
pieHandle,PIE_GroupNumber_10);
256 PWM_clearIntFlag(obj->
pwmHandle[pwmNumber]);
260 PWM_clearSocAFlag(obj->
pwmHandle[pwmNumber]);
264 PIE_clearInt(obj->
pieHandle,PIE_GroupNumber_3);
291 PWM_setOneShotTrip(obj->
pwmHandle[PWM_Number_1]);
292 PWM_setOneShotTrip(obj->
pwmHandle[PWM_Number_2]);
293 PWM_setOneShotTrip(obj->
pwmHandle[PWM_Number_3]);
345 PWM_clearOneShotTrip(obj->
pwmHandle[PWM_Number_1]);
346 PWM_clearOneShotTrip(obj->
pwmHandle[PWM_Number_2]);
347 PWM_clearOneShotTrip(obj->
pwmHandle[PWM_Number_3]);
375 const ADC_SocNumber_e socNumber)
379 return(ADC_getSocSampleDelay(obj->
adcHandle,socNumber));
393 uint_least8_t sensorNumber)
429 pDutyCycles[0] = PWM_get_CmpA(obj->
pwmHandle[PWM_Number_1]);
430 pDutyCycles[1] = PWM_get_CmpA(obj->
pwmHandle[PWM_Number_2]);
431 pDutyCycles[2] = PWM_get_CmpA(obj->
pwmHandle[PWM_Number_3]);
508 PIE_Obj *pie = (PIE_Obj *)obj->
pieHandle;
511 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
518 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
573 value = value * voltage_sf;
592 pAdcData->
I_A.
value[0] = value * current_sf;
596 pAdcData->
I_A.
value[1] = value * current_sf;
600 pAdcData->
I_A.
value[2] = value * current_sf;
604 pAdcData->
V_V.
value[0] = value * voltage_sf;
608 pAdcData->
V_V.
value[1] = value * voltage_sf;
612 pAdcData->
V_V.
value[2] = value * voltage_sf;
616 pAdcData->
dcBus_V = value * voltage_sf;
631 result = GPIO_read(obj->
gpioHandle, gpioNumber);
644 uint32_t timerCnt = TIMER_getCount(obj->
timerHandle[timerNumber]);
654 PWM_Number_e pwmNumber)
658 PWM_setCount(obj->
pwmHandle[pwmNumber],0);
669 const ADC_SocNumber_e socNumber,
670 const ADC_SocSampleDelay_e sampleDelay)
674 ADC_setSocSampleDelay(obj->
adcHandle,socNumber,sampleDelay);
687 uint_least8_t sensorNumber,
783 PWM_Number_e pwmNumber,
788 PWM_setPeriod(obj->
pwmHandle[pwmNumber],pwmFreq_kHz);
870 const uint_least16_t numPwmTicksPerIsrTick);
961 uint_least8_t pwmCnt;
962 uint_least8_t dataCnt=0;
964 for(pwmCnt=0;pwmCnt<3;pwmCnt++)
972 float_t V_sat_dc_pu = V_sat_pu + 0.5;
973 int16_t pwmValue = (int16_t)(V_sat_dc_pu * period);
985 float_t V_sat_dc_pu = V_sat_pu + 0.5;
986 int16_t pwmValue = (int16_t)(V_sat_dc_pu * period);
1006 uint_least8_t pwmCnt;
1008 for(pwmCnt=0;pwmCnt<3;pwmCnt++)
1010 PWM_Obj *pwm = (PWM_Obj *)obj->
pwmHandle[pwmCnt];
1016 float_t V_sat_dc_pu = V_sat_pu + 0.5;
1017 int16_t pwmValue = (int16_t)(V_sat_dc_pu * period);
1020 PWM_write_CmpA(obj->
pwmHandle[pwmCnt],pwmValue);
1035 uint16_t pwmPeriodValue;
1037 pwmPeriodValue = PWM_getPeriod(obj->
pwmHandle[pwmNumber]);
1039 return(pwmPeriodValue);
1063 #endif // extern "C"
1068 #endif // end of _HAL_H_ definition
void HAL_enableGlobalInts(HAL_Handle handle)
Enables global interrupts.
void HAL_enableAdcInts(HAL_Handle handle)
Enables the ADC interrupts.
void HAL_disableGlobalInts(HAL_Handle handle)
Disables global interrupts.
MATH_vec3 Vabc_pu
the PWM time-durations for each motor phase
static void HAL_setNumCurrentSensors(HAL_Handle handle, const uint_least8_t numCurrentSensors)
Sets the number of current sensors.
HAL_PwmFreq_e
Enumeration for the PWM frequencies.
static void HAL_setNumVoltageSensors(HAL_Handle handle, const uint_least8_t numVoltageSensors)
Sets the number of voltage sensors.
static void HAL_disablePwm(HAL_Handle handle)
Disables the PWM device.
static uint32_t HAL_readTimerCnt(HAL_Handle handle, const uint_least8_t timerNumber)
Reads the timer count.
static void HAL_resetPwmCount(HAL_Handle handle, PWM_Number_e pwmNumber)
Resets the PWM count.
void HAL_OscTempComp(HAL_Handle handle)
Executes the oscillator 1 and 2 calibration functions.
Contains the public interface to the math (MATH) module routines.
interrupt void mainISR(void)
void HAL_setupQEP(QEP_Handle qepHandle, const USER_Params *pUserParams, const uint32_t unitTimerFreq_Hz)
Sets up the QEP peripheral (Quadrature Encoder)
CLK_Handle clkHandle
the clock handle
void HAL_writeDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
Writes data to the driver.
static void HAL_setCurrentScaleFactor(HAL_Handle handle, const float_t current_sf)
Sets the current scale factor in the hal.
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.
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 float_t HAL_getVoltageScaleFactor(HAL_Handle handle)
Gets the voltage scale factor.
PWMDAC_Handle pwmDacHandle[3]
static void HAL_readAdcDataWithOffsets(HAL_Handle handle, HAL_AdcData_t *pAdcData)
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.
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_setupFaults(HAL_Handle handle)
Configures the fault protection logic.
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_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_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 uint_least8_t HAL_getNumVoltageSensors(HAL_Handle handle)
Gets the number of voltage sensors.
GPIO pin number for drv8301kit SW 1.
float_t dcBus_V
the dcBus 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.
struct _OFFSET_Obj_ * OFFSET_Handle
Defines the OFFSET handle.
static void HAL_getDutyCycles(HAL_Handle handle, uint16_t *pDutyCycles)
Gets the PWM duty cycle times.
MATH_vec3 I_A
the current values
uint16_t HAL_computeOscTrimValue(int16_t coarse, int16_t fine)
_iq voltage_sf
the voltage scale factor, volts_pu/cnt
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.
GPIO pin number for drv8301kit SW 2.
static void HAL_writePwmData(HAL_Handle handle, const HAL_PwmData_t *pPwmData)
Writes PWM data to the PWM comparators for motor control.
static void HAL_readAdcData(HAL_Handle handle, HAL_AdcData_t *pAdcData)
Reads the ADC data.
static void HAL_setPwmFreq_kHz(HAL_Handle handle, PWM_Number_e pwmNumber, HAL_PwmFreq_e pwmFreq_kHz)
Sets the PWM frequency.
void HAL_setupSpiB(HAL_Handle handle)
Sets up the spiB peripheral.
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.
MATH_vec3 V_V
the voltage values
void HAL_AdcOffsetSelfCal(HAL_Handle handle)
Executes the offset calibration of the ADC.
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 uint16_t HAL_readPwmPeriod(HAL_Handle handle, const PWM_Number_e pwmNumber)
Reads PWM period register.
static float_t HAL_getCurrentScaleFactor(HAL_Handle handle)
Gets the current scale factor.
ADC_Handle adcHandle
the ADC handle
HAL_Handle HAL_init(void *pMemory, const size_t numBytes)
Initializes the hardware abstraction layer (HAL) object.
static uint_least8_t HAL_getNumCurrentSensors(HAL_Handle handle)
Gets the number of current sensors.
static void HAL_updateAdcBias(HAL_Handle handle, OFFSET_Handle *pOffsetHandle_I, OFFSET_Handle *pOffsetHandle_V)
Updates the ADC bias values.
void HAL_setupPwmDacs(HAL_Handle handle, const float_t systemFreq_MHz, const float_t dacFreq_kHz)
Sets up the PWM DACs (Pulse Width Modulator Digital to Analof Converters)
static void HAL_toggleGpio(HAL_Handle handle, const GPIO_Number_e gpioNumber)
Toggles the GPIO pin.
void HAL_cal(HAL_Handle handle)
Executes calibration routines.
void HAL_setupGate(HAL_Handle handle)
Sets up the GATE object.
TIMER_Handle timerHandle[3]
Enumeration for voltage sensor.
uint16_t HAL_AdcCalConversion(HAL_Handle handle)
Reads the converted value from the selected calibration channel.
GPIO pin number for ControlCARD LED 2.
static void HAL_enablePwm(HAL_Handle handle)
Enables the PWM devices.
static void HAL_setVoltageScaleFactor(HAL_Handle handle, const float_t voltage_sf)
Sets the voltage scale factor in the hal.
interrupt void led2ISR(void)
static void HAL_setGpioHigh(HAL_Handle handle, const GPIO_Number_e gpioNumber)
Sets the GPIO pin high.
static ADC_SocSampleDelay_e HAL_getAdcSocSampleDelay(HAL_Handle handle, const ADC_SocNumber_e socNumber)
Gets the ADC delay value.
HAL_SwNumber_e
Enumeration for the SW numbers.
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.
void HAL_setupAdcs(HAL_Handle handle)
Sets up the ADCs (Analog to Digital Converters)
static void HAL_enableTbClockSync(HAL_Handle handle)
Enables the ePWM module time base clock sync signal.
uint_least8_t numVoltageSensors
the number of voltage sensors
static void HAL_disableTbClockSync(HAL_Handle handle)
Disables the ePWM module time base clock sync signal.
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 bool HAL_readGpio(HAL_Handle handle, const GPIO_Number_e gpioNumber)
Reads the specified general purpose I/O (GPIO)