MotorWare f2806x Module API Documentation
drv8301kit_revD/f28x/f2806x/src/float/hal.h
Go to the documentation of this file.
1 #ifndef _HAL_H_
2 #define _HAL_H_
3 /* --COPYRIGHT--,BSD
4  * Copyright (c) 2012, Texas Instruments Incorporated
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution.
17  *
18  * * Neither the name of Texas Instruments Incorporated nor the names of
19  * its contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
26  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
29  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
31  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
32  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  * --/COPYRIGHT--*/
34 
40 
41 
42 // **************************************************************************
43 // the includes
44 
45 
46 // platforms
48 #include "hal_obj.h"
49 
54 
55 
56 
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60 
61 
62 // **************************************************************************
63 // the defines
64 
66 #define DRV8301_SPI
67 
68 #define Device_cal (void (*)(void))0x3D7C80
69 
70 
73 #define FP_SCALE 32768
74 
76 #define FP_ROUND FP_SCALE/2
77 
81 #define OSC_POSTRIM 32
82 #define OSC_POSTRIM_OFF FP_SCALE*OSC_POSTRIM
83 
84 
86 
88 #define getOsc1FineTrimSlope() (*(int16_t (*)(void))0x3D7E90)()
89 
91 #define getOsc1FineTrimOffset() (*(int16_t (*)(void))0x3D7E93)()
92 
94 #define getOsc1CoarseTrim() (*(int16_t (*)(void))0x3D7E96)()
95 
98 #define getOsc2FineTrimSlope() (*(int16_t (*)(void))0x3D7E99)()
99 
101 #define getOsc2FineTrimOffset() (*(int16_t (*)(void))0x3D7E9C)()
102 
104 #define getOsc2CoarseTrim() (*(int16_t (*)(void))0x3D7E9F)()
105 
107 #define getRefTempOffset() (*(int16_t (*)(void))0x3D7EA2)()
108 
109 
112 #define HAL_PWM_DBFED_CNT (uint16_t)(0.050 * (float_t)USER_SYSTEM_FREQ_MHz) // 50 ns
113 
114 
117 #define HAL_PWM_DBRED_CNT (uint16_t)(0.050 * (float_t)USER_SYSTEM_FREQ_MHz) // 50 ns
118 
119 
122 #define HAL_readSW HAL_readGpio
123 
124 
127 #define HAL_turnLedOff HAL_setGpioLow
128 
129 
132 #define HAL_turnLedOn HAL_setGpioHigh
133 
134 
137 #define HAL_toggleLed HAL_toggleGpio
138 
139 
140 // **************************************************************************
141 // the typedefs
142 
143 
146 typedef enum
147 {
148  HAL_Gpio_LED2=GPIO_Number_31,
149  HAL_Gpio_LED3=GPIO_Number_34
151 
152 
155 typedef enum
156 {
157  HAL_Gpio_SW1=GPIO_Number_9,
158  HAL_Gpio_SW2=GPIO_Number_7
160 
161 
164 typedef enum
165 {
192 } HAL_PwmFreq_e;
193 
194 
197 typedef enum
198 {
202 
203 
204 // **************************************************************************
205 // the globals
206 
207 extern interrupt void led2ISR(void);
208 extern interrupt void led3OffISR(void);
209 extern interrupt void led3OnISR(void);
210 extern interrupt void mainISR(void);
211 
212 
213 // **************************************************************************
214 // the function prototypes
215 
216 extern void HAL_AdcCalChanSelect(HAL_Handle handle, const ADC_SocChanNumber_e chanNumber);
217 
218 
219 extern uint16_t HAL_AdcCalConversion(HAL_Handle handle);
220 
221 
222 extern void HAL_AdcOffsetSelfCal(HAL_Handle handle);
223 
224 
225 
230 static inline void HAL_acqAdcInt(HAL_Handle handle,const ADC_IntNumber_e intNumber)
231 {
232  HAL_Obj *obj = (HAL_Obj *)handle;
233 
234 
235  // clear the ADC interrupt flag
236  ADC_clearIntFlag(obj->adcHandle,intNumber);
237 
238 
239  // Acknowledge interrupt from PIE group 10
240  PIE_clearInt(obj->pieHandle,PIE_GroupNumber_10);
241 
242  return;
243 } // end of HAL_acqAdcInt() function
244 
245 
250 static inline void HAL_acqPwmInt(HAL_Handle handle,const PWM_Number_e pwmNumber)
251 {
252  HAL_Obj *obj = (HAL_Obj *)handle;
253 
254 
255  // clear the PWM interrupt flag
256  PWM_clearIntFlag(obj->pwmHandle[pwmNumber]);
257 
258 
259  // clear the SOCA flag
260  PWM_clearSocAFlag(obj->pwmHandle[pwmNumber]);
261 
262 
263  // Acknowledge interrupt from PIE group 3
264  PIE_clearInt(obj->pieHandle,PIE_GroupNumber_3);
265 
266  return;
267 } // end of HAL_acqPwmInt() function
268 
269 
275 extern void HAL_cal(HAL_Handle handle);
276 
277 
280 extern void HAL_disableGlobalInts(HAL_Handle handle);
281 
282 
287 static inline void HAL_disablePwm(HAL_Handle handle)
288 {
289  HAL_Obj *obj = (HAL_Obj *)handle;
290 
291  PWM_setOneShotTrip(obj->pwmHandle[PWM_Number_1]);
292  PWM_setOneShotTrip(obj->pwmHandle[PWM_Number_2]);
293  PWM_setOneShotTrip(obj->pwmHandle[PWM_Number_3]);
294 
295  return;
296 } // end of HAL_disablePwm() function
297 
298 
301 static inline void HAL_disableTbClockSync(HAL_Handle handle)
302 {
303  HAL_Obj *obj = (HAL_Obj *)handle;
304 
305  CLK_disableTbClockSync(obj->clkHandle);
306 
307  return;
308 } // end of HAL_disableTbClockSync() function
309 
310 
315 extern void HAL_enableAdcInts(HAL_Handle handle);
316 
317 
323 extern void HAL_enableDebugInt(HAL_Handle handle);
324 
325 
328 extern void HAL_enableGlobalInts(HAL_Handle handle);
329 
330 
334 extern void HAL_enableDrv(HAL_Handle handle);
335 
336 
341 static inline void HAL_enablePwm(HAL_Handle handle)
342 {
343  HAL_Obj *obj = (HAL_Obj *)handle;
344 
345  PWM_clearOneShotTrip(obj->pwmHandle[PWM_Number_1]);
346  PWM_clearOneShotTrip(obj->pwmHandle[PWM_Number_2]);
347  PWM_clearOneShotTrip(obj->pwmHandle[PWM_Number_3]);
348 
349  return;
350 } // end of HAL_enablePwm() function
351 
352 
355 extern void HAL_enablePwmInt(HAL_Handle handle);
356 
357 
360 static inline void HAL_enableTbClockSync(HAL_Handle handle)
361 {
362  HAL_Obj *obj = (HAL_Obj *)handle;
363 
364  CLK_enableTbClockSync(obj->clkHandle);
365 
366  return;
367 } // end of HAL_enableTbClockSync() function
368 
369 
374 static inline ADC_SocSampleDelay_e HAL_getAdcSocSampleDelay(HAL_Handle handle,
375  const ADC_SocNumber_e socNumber)
376 {
377  HAL_Obj *obj = (HAL_Obj *)handle;
378 
379  return(ADC_getSocSampleDelay(obj->adcHandle,socNumber));
380 } // end of HAL_getAdcSocSampleDelay() function
381 
382 
391 static inline float_t HAL_getBias(HAL_Handle handle,
392  const HAL_SensorType_e sensorType,
393  uint_least8_t sensorNumber)
394 {
395  HAL_Obj *obj = (HAL_Obj *)handle;
396  float_t bias = 0.0;
397 
398  if(sensorType == HAL_SensorType_Current)
399  {
400  bias = obj->adcBias.I_A.value[sensorNumber];
401  }
402  else if(sensorType == HAL_SensorType_Voltage)
403  {
404  bias = obj->adcBias.V_V.value[sensorNumber];
405  }
406 
407  return(bias);
408 } // end of HAL_getBias() function
409 
410 
415 {
416  HAL_Obj *obj = (HAL_Obj *)handle;
417 
418  return(obj->current_sf);
419 } // end of HAL_getCurrentScaleFactor() function
420 
421 
425 static inline void HAL_getDutyCycles(HAL_Handle handle,uint16_t *pDutyCycles)
426 {
427  HAL_Obj *obj = (HAL_Obj *)handle;
428 
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]);
432 
433  return;
434 } // end of HAL_getDutyCycles() function
435 
436 
440 static inline uint_least8_t HAL_getNumCurrentSensors(HAL_Handle handle)
441 {
442  HAL_Obj *obj = (HAL_Obj *)handle;
443 
444 
445  return(obj->numCurrentSensors);
446 } // end of HAL_getNumCurrentSensors() function
447 
448 
452 static inline uint_least8_t HAL_getNumVoltageSensors(HAL_Handle handle)
453 {
454  HAL_Obj *obj = (HAL_Obj *)handle;
455 
456 
457  return(obj->numVoltageSensors);
458 } // end of HAL_getNumVoltageSensors() function
459 
460 
465 {
466  HAL_Obj *obj = (HAL_Obj *)handle;
467 
468  return(obj->voltage_sf);
469 } // end of HAL_getVoltageScaleFactor() function
470 
471 
478 extern void HAL_setupFaults(HAL_Handle handle);
479 
480 
487 extern HAL_Handle HAL_init(void *pMemory,const size_t numBytes);
488 
489 
490 extern void HAL_OscTempComp(HAL_Handle handle);
491 
492 
493 extern void HAL_osc1Comp(HAL_Handle handle, const int16_t sensorSample);
494 
495 
496 extern void HAL_osc2Comp(HAL_Handle handle, const int16_t sensorSample);
497 
498 
499 extern uint16_t HAL_computeOscTrimValue(int16_t coarse, int16_t fine);
500 
501 
505 static inline void HAL_initIntVectorTable(HAL_Handle handle)
506  {
507  HAL_Obj *obj = (HAL_Obj *)handle;
508  PIE_Obj *pie = (PIE_Obj *)obj->pieHandle;
509 
510 
511  ENABLE_PROTECTED_REGISTER_WRITE_MODE;
512 
513 // pie->EPWM1_INT = &led2ISR;
514 // pie->ADCINT1 = &led3OffISR;
515 // pie->ADCINT2 = &led3OnISR;
516  pie->ADCINT6 = &mainISR;
517 
518  DISABLE_PROTECTED_REGISTER_WRITE_MODE;
519 
520  return;
521  } // end of HAL_initIntVectorTable() function
522 
523 
531 static inline void HAL_readAdcData(HAL_Handle handle,HAL_AdcData_t *pAdcData)
532 {
533  HAL_Obj *obj = (HAL_Obj *)handle;
534 
535  float_t value;
536  float_t current_sf = HAL_getCurrentScaleFactor(handle);
537  float_t voltage_sf = HAL_getVoltageScaleFactor(handle);
538 
539 
540  // convert phase A current
541  // sample the first sample twice due to errata sprz342f, ignore the first sample
542  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_1);
543  value = value * current_sf - obj->adcBias.I_A.value[0];
544  pAdcData->I_A.value[0] = value;
545 
546  // convert phase B current
547  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_2);
548  value = value * current_sf - obj->adcBias.I_A.value[1];
549  pAdcData->I_A.value[1] = value;
550 
551  // convert phase C current
552  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_3);
553  value = value * current_sf - obj->adcBias.I_A.value[2];
554  pAdcData->I_A.value[2] = value;
555 
556  // convert phase A voltage
557  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_4);
558  value = value * voltage_sf - obj->adcBias.V_V.value[0];
559  pAdcData->V_V.value[0] = value;
560 
561  // convert phase B voltage
562  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_5);
563  value = value * voltage_sf - obj->adcBias.V_V.value[1];
564  pAdcData->V_V.value[1] = value;
565 
566  // convert phase C voltage
567  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_6);
568  value = value * voltage_sf - obj->adcBias.V_V.value[2];
569  pAdcData->V_V.value[2] = value;
570 
571  // convert dcBus voltage
572  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_7);
573  value = value * voltage_sf;
574  pAdcData->dcBus_V = value;
575 
576  return;
577 } // end of HAL_readAdcData() function
578 
579 
580 static inline void HAL_readAdcDataWithOffsets(HAL_Handle handle,HAL_AdcData_t *pAdcData)
581 {
582  HAL_Obj *obj = (HAL_Obj *)handle;
583 
584  float_t value;
585  float_t current_sf = HAL_getCurrentScaleFactor(handle);
586  float_t voltage_sf = HAL_getVoltageScaleFactor(handle);
587 
588 
589  // convert phase A current
590  // sample the first sample twice due to errata sprz342f, ignore the first sample
591  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_1);
592  pAdcData->I_A.value[0] = value * current_sf;
593 
594  // convert phase B current
595  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_2);
596  pAdcData->I_A.value[1] = value * current_sf;
597 
598  // convert phase C current
599  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_3);
600  pAdcData->I_A.value[2] = value * current_sf;
601 
602  // convert phase A voltage
603  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_4);
604  pAdcData->V_V.value[0] = value * voltage_sf;
605 
606  // convert phase B voltage
607  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_5);
608  pAdcData->V_V.value[1] = value * voltage_sf;
609 
610  // convert phase C voltage
611  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_6);
612  pAdcData->V_V.value[2] = value * voltage_sf;
613 
614  // convert dcBus voltage
615  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_7);
616  pAdcData->dcBus_V = value * voltage_sf;
617 
618  return;
619 } // end of HAL_readAdcDataWithOffsets() function
620 
621 
626 static inline bool HAL_readGpio(HAL_Handle handle, const GPIO_Number_e gpioNumber)
627 {
628  HAL_Obj *obj = (HAL_Obj *)handle;
629  bool result = false;
630 
631  result = GPIO_read(obj->gpioHandle, gpioNumber);
632 
633  return result;
634 } // end of HAL_readGpio() function
635 
636 
641 static inline uint32_t HAL_readTimerCnt(HAL_Handle handle,const uint_least8_t timerNumber)
642 {
643  HAL_Obj *obj = (HAL_Obj *)handle;
644  uint32_t timerCnt = TIMER_getCount(obj->timerHandle[timerNumber]);
645 
646  return(timerCnt);
647 } // end of HAL_readTimerCnt() function
648 
649 
653 static inline void HAL_resetPwmCount(HAL_Handle handle,
654  PWM_Number_e pwmNumber)
655 {
656  HAL_Obj *obj = (HAL_Obj *)handle;
657 
658  PWM_setCount(obj->pwmHandle[pwmNumber],0);
659 
660  return;
661 } // HAL_resetPwmCount() function
662 
663 
668 static inline void HAL_setAdcSocSampleDelay(HAL_Handle handle,
669  const ADC_SocNumber_e socNumber,
670  const ADC_SocSampleDelay_e sampleDelay)
671 {
672  HAL_Obj *obj = (HAL_Obj *)handle;
673 
674  ADC_setSocSampleDelay(obj->adcHandle,socNumber,sampleDelay);
675 
676  return;
677 } // end of HAL_setAdcSocSampleDelay() function
678 
679 
685 static inline void HAL_setBias(HAL_Handle handle,
686  const HAL_SensorType_e sensorType,
687  uint_least8_t sensorNumber,
688  const float_t bias)
689 {
690  HAL_Obj *obj = (HAL_Obj *)handle;
691 
692 
693  if(sensorType == HAL_SensorType_Current)
694  {
695  obj->adcBias.I_A.value[sensorNumber] = bias;
696  }
697  else if(sensorType == HAL_SensorType_Voltage)
698  {
699  obj->adcBias.V_V.value[sensorNumber] = bias;
700  }
701 
702  return;
703 } // end of HAL_setBias() function
704 
705 
709 static inline void HAL_setCurrentScaleFactor(HAL_Handle handle,const float_t current_sf)
710 {
711  HAL_Obj *obj = (HAL_Obj *)handle;
712 
713 
714  obj->current_sf = current_sf;
715 
716  return;
717 } // end of HAL_setCurrentScaleFactor() function
718 
719 
723 static inline void HAL_setGpioHigh(HAL_Handle handle,const GPIO_Number_e gpioNumber)
724 {
725  HAL_Obj *obj = (HAL_Obj *)handle;
726 
727 
728  // set GPIO high
729  GPIO_setHigh(obj->gpioHandle,gpioNumber);
730 
731  return;
732 } // end of HAL_setGpioHigh() function
733 
734 
738 static inline void HAL_setGpioLow(HAL_Handle handle,const GPIO_Number_e gpioNumber)
739 {
740  HAL_Obj *obj = (HAL_Obj *)handle;
741 
742 
743  // set GPIO low
744  GPIO_setLow(obj->gpioHandle,gpioNumber);
745 
746  return;
747 } // end of HAL_setGpioLow() function
748 
749 
753 static inline void HAL_setNumCurrentSensors(HAL_Handle handle,const uint_least8_t numCurrentSensors)
754 {
755  HAL_Obj *obj = (HAL_Obj *)handle;
756 
757 
758  obj->numCurrentSensors = numCurrentSensors;
759 
760  return;
761 } // end of HAL_setNumCurrentSensors() function
762 
763 
767 static inline void HAL_setNumVoltageSensors(HAL_Handle handle,const uint_least8_t numVoltageSensors)
768 {
769  HAL_Obj *obj = (HAL_Obj *)handle;
770 
771 
772  obj->numVoltageSensors = numVoltageSensors;
773 
774  return;
775 } // end of HAL_setNumVoltageSensors() function
776 
777 
782 static inline void HAL_setPwmFreq_kHz(HAL_Handle handle,
783  PWM_Number_e pwmNumber,
784  HAL_PwmFreq_e pwmFreq_kHz)
785 {
786  HAL_Obj *obj = (HAL_Obj *)handle;
787 
788  PWM_setPeriod(obj->pwmHandle[pwmNumber],pwmFreq_kHz);
789 
790  return;
791 } // HAL_setPwmFreq_Hz() function
792 
793 
797 static inline void HAL_setVoltageScaleFactor(HAL_Handle handle,const float_t voltage_sf)
798 {
799  HAL_Obj *obj = (HAL_Obj *)handle;
800 
801  obj->voltage_sf = voltage_sf;
802 
803  return;
804 } // end of HAL_setVoltageScaleFactor() function
805 
806 
813 extern void HAL_setParams(HAL_Handle handle,const USER_Params *pUserParams);
814 
815 
818 extern void HAL_setupAdcs(HAL_Handle handle);
819 
820 
824 extern void HAL_setupClks(HAL_Handle handle);
825 
826 
829 extern void HAL_setupFaults(HAL_Handle handle);
830 
831 
834 void HAL_setupGate(HAL_Handle handle);
835 
836 
839 extern void HAL_setupGpios(HAL_Handle handle);
840 
841 
843 extern void HAL_setupFlash(HAL_Handle handle);
844 
845 
848 extern void HAL_setupPeripheralClks(HAL_Handle handle);
849 
850 
853 extern void HAL_setupPie(HAL_Handle handle);
854 
855 
859 extern void HAL_setupPll(HAL_Handle handle,const PLL_ClkFreq_e clkFreq);
860 
861 
867 extern void HAL_setupPwms(HAL_Handle handle,
868  const float_t systemFreq_MHz,
869  const float_t pwmPeriod_usec,
870  const uint_least16_t numPwmTicksPerIsrTick);
871 
872 
877 extern void HAL_setupPwmDacs(HAL_Handle handle,
878  const float_t systemFreq_MHz,
879  const float_t dacFreq_kHz);
880 
881 
885 void HAL_setupQEP(QEP_Handle qepHandle,const USER_Params *pUserParams,const uint32_t unitTimerFreq_Hz);
886 
887 
890 extern void HAL_setupSpiA(HAL_Handle handle);
891 
892 
895 extern void HAL_setupSpiB(HAL_Handle handle);
896 
897 
901 void HAL_setupTimers(HAL_Handle handle,const float_t systemFreq_MHz);
902 
903 
907 static inline void HAL_toggleGpio(HAL_Handle handle,const GPIO_Number_e gpioNumber)
908 {
909  HAL_Obj *obj = (HAL_Obj *)handle;
910 
911 
912  // toggle the GPIO
913  GPIO_toggle(obj->gpioHandle,gpioNumber);
914 
915  return;
916 } // end of HAL_toggleGpio() function
917 
918 
923 static inline void HAL_updateAdcBias(HAL_Handle handle,
924  OFFSET_Handle *pOffsetHandle_I,
925  OFFSET_Handle *pOffsetHandle_V)
926 {
927  uint_least8_t cnt;
928 
929 
930  // update the current bias
931  for(cnt=0;cnt<HAL_getNumCurrentSensors(handle);cnt++)
932  {
933  float_t bias = HAL_getBias(handle,HAL_SensorType_Current,cnt);
934 
935  bias += OFFSET_getOffset(pOffsetHandle_I[cnt]);
936 
937  HAL_setBias(handle,HAL_SensorType_Current,cnt,bias);
938  }
939 
940 
941  // update the voltage bias
942  for(cnt=0;cnt<HAL_getNumVoltageSensors(handle);cnt++)
943  {
944  float_t bias = HAL_getBias(handle,HAL_SensorType_Voltage,cnt);
945 
946  bias += OFFSET_getOffset(pOffsetHandle_V[cnt]);
947 
948  HAL_setBias(handle,HAL_SensorType_Voltage,cnt,bias);
949  }
950 
951  return;
952 } // end of HAL_updateAdcBias() function
953 
954 
958 static inline void HAL_writeDacData(HAL_Handle handle,const HAL_DacData_t *pDacData)
959 {
960  HAL_Obj *obj = (HAL_Obj *)handle;
961  uint_least8_t pwmCnt;
962  uint_least8_t dataCnt=0;
963 
964  for(pwmCnt=0;pwmCnt<3;pwmCnt++)
965  {
966  PWM_Obj *pwm = (PWM_Obj *)obj->pwmDacHandle[pwmCnt];
967 
968  // compute the value
969  float_t period = (float_t)(pwm->TBPRD);
970  float_t V_pu = pDacData->value[dataCnt];
971  float_t V_sat_pu = MATH_sat(V_pu,0.5,-0.5);
972  float_t V_sat_dc_pu = V_sat_pu + 0.5;
973  int16_t pwmValue = (int16_t)(V_sat_dc_pu * period);
974 
975  // increment the data counter
976  dataCnt++;
977 
978  // write the PWM data value
979  PWM_write_CmpA(obj->pwmDacHandle[pwmCnt],pwmValue);
980 
981  if(pwmCnt == 0)
982  {
983  float_t V_pu = pDacData->value[dataCnt];
984  float_t V_sat_pu = MATH_sat(V_pu,0.5,-0.5);
985  float_t V_sat_dc_pu = V_sat_pu + 0.5;
986  int16_t pwmValue = (int16_t)(V_sat_dc_pu * period);
987 
988  // write the PWM data value
989  PWM_write_CmpB(obj->pwmDacHandle[pwmCnt],pwmValue);
990 
991  // increment the data counter
992  dataCnt++;
993  }
994  }
995 
996  return;
997 } // end of HAL_writeDacData() function
998 
999 
1003 static inline void HAL_writePwmData(HAL_Handle handle,const HAL_PwmData_t *pPwmData)
1004 {
1005  HAL_Obj *obj = (HAL_Obj *)handle;
1006  uint_least8_t pwmCnt;
1007 
1008  for(pwmCnt=0;pwmCnt<3;pwmCnt++)
1009  {
1010  PWM_Obj *pwm = (PWM_Obj *)obj->pwmHandle[pwmCnt];
1011 
1012  // compute the value
1013  float_t period = (float_t)(pwm->TBPRD);
1014  float_t V_pu = -pPwmData->Vabc_pu.value[pwmCnt];
1015  float_t V_sat_pu = MATH_sat(V_pu,0.5,-0.5);
1016  float_t V_sat_dc_pu = V_sat_pu + 0.5;
1017  int16_t pwmValue = (int16_t)(V_sat_dc_pu * period);
1018 
1019  // write the PWM data value
1020  PWM_write_CmpA(obj->pwmHandle[pwmCnt],pwmValue);
1021  }
1022 
1023  return;
1024 } // end of HAL_writePwmData() function
1025 
1030 static inline uint16_t HAL_readPwmPeriod(HAL_Handle handle,const PWM_Number_e pwmNumber)
1031 {
1032  HAL_Obj *obj = (HAL_Obj *)handle;
1033 
1034  // the period value to be returned
1035  uint16_t pwmPeriodValue;
1036 
1037  pwmPeriodValue = PWM_getPeriod(obj->pwmHandle[pwmNumber]);
1038 
1039  return(pwmPeriodValue);
1040 } // end of HAL_readPwmPeriod() function
1041 
1042 
1046 void HAL_writeDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars);
1047 
1048 
1052 void HAL_readDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars);
1053 
1054 
1058 void HAL_setupDrvSpi(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars);
1059 
1060 
1061 #ifdef __cplusplus
1062 }
1063 #endif // extern "C"
1064 
1066 
1067 
1068 #endif // end of _HAL_H_ definition
1069 
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
Definition: 32b/hal_data.h:69
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.
_iq value[3]
Definition: 32b/math.h:261
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
static float_t HAL_getVoltageScaleFactor(HAL_Handle handle)
Gets the voltage scale factor.
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.
Definition: float/math.h:218
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.
Definition: 32b/offset.h:95
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.
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.
Definition: 32b/offset.h:115
float float_t
Defines the portable data type for 32 bit, signed floating-point data.
Definition: types.h:121
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)