MotorWare f2806x Module API Documentation
hvkit_rev1p1/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
47 #include "hal_obj.h"
48 
53 
54 
55 
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 
60 
61 // **************************************************************************
62 // the defines
63 
64 #define Device_cal (void (*)(void))0x3D7C80
65 
66 
69 #define FP_SCALE 32768
70 
72 #define FP_ROUND FP_SCALE/2
73 
77 #define OSC_POSTRIM 32
78 #define OSC_POSTRIM_OFF FP_SCALE*OSC_POSTRIM
79 
80 
82 
84 #define getOsc1FineTrimSlope() (*(int16_t (*)(void))0x3D7E90)()
85 
87 #define getOsc1FineTrimOffset() (*(int16_t (*)(void))0x3D7E93)()
88 
90 #define getOsc1CoarseTrim() (*(int16_t (*)(void))0x3D7E96)()
91 
94 #define getOsc2FineTrimSlope() (*(int16_t (*)(void))0x3D7E99)()
95 
97 #define getOsc2FineTrimOffset() (*(int16_t (*)(void))0x3D7E9C)()
98 
100 #define getOsc2CoarseTrim() (*(int16_t (*)(void))0x3D7E9F)()
101 
103 #define getRefTempOffset() (*(int16_t (*)(void))0x3D7EA2)()
104 
105 
108 #define HAL_PWM_DBFED_CNT (uint16_t)(2.0 * (float_t)USER_SYSTEM_FREQ_MHz) // 2 usec
109 
110 
113 #define HAL_PWM_DBRED_CNT (uint16_t)(2.0 * (float_t)USER_SYSTEM_FREQ_MHz) // 2 usec
114 
115 
118 #define HAL_readSW HAL_readGpio
119 
120 
123 #define HAL_turnLedOff HAL_setGpioLow
124 
125 
128 #define HAL_turnLedOn HAL_setGpioHigh
129 
130 
133 #define HAL_toggleLed HAL_toggleGpio
134 
135 
136 // **************************************************************************
137 // the typedefs
138 
139 
142 typedef enum
143 {
144  HAL_Gpio_LED2=GPIO_Number_31,
145  HAL_Gpio_LED3=GPIO_Number_34
147 
148 
151 typedef enum
152 {
179 } HAL_PwmFreq_e;
180 
181 
184 typedef enum
185 {
189 
190 
191 // **************************************************************************
192 // the globals
193 
194 extern interrupt void led2ISR(void);
195 extern interrupt void led3OffISR(void);
196 extern interrupt void led3OnISR(void);
197 extern interrupt void mainISR(void);
198 
199 
200 // **************************************************************************
201 // the function prototypes
202 
203 extern void HAL_AdcCalChanSelect(HAL_Handle handle, const ADC_SocChanNumber_e chanNumber);
204 
205 
206 extern uint16_t HAL_AdcCalConversion(HAL_Handle handle);
207 
208 
209 extern void HAL_AdcOffsetSelfCal(HAL_Handle handle);
210 
211 
212 
217 static inline void HAL_acqAdcInt(HAL_Handle handle,const ADC_IntNumber_e intNumber)
218 {
219  HAL_Obj *obj = (HAL_Obj *)handle;
220 
221 
222  // clear the ADC interrupt flag
223  ADC_clearIntFlag(obj->adcHandle,intNumber);
224 
225 
226  // Acknowledge interrupt from PIE group 10
227  PIE_clearInt(obj->pieHandle,PIE_GroupNumber_10);
228 
229  return;
230 } // end of HAL_acqAdcInt() function
231 
232 
237 static inline void HAL_acqPwmInt(HAL_Handle handle,const PWM_Number_e pwmNumber)
238 {
239  HAL_Obj *obj = (HAL_Obj *)handle;
240 
241 
242  // clear the PWM interrupt flag
243  PWM_clearIntFlag(obj->pwmHandle[pwmNumber]);
244 
245 
246  // clear the SOCA flag
247  PWM_clearSocAFlag(obj->pwmHandle[pwmNumber]);
248 
249 
250  // Acknowledge interrupt from PIE group 3
251  PIE_clearInt(obj->pieHandle,PIE_GroupNumber_3);
252 
253  return;
254 } // end of HAL_acqPwmInt() function
255 
256 
262 extern void HAL_cal(HAL_Handle handle);
263 
264 
267 extern void HAL_disableGlobalInts(HAL_Handle handle);
268 
269 
274 static inline void HAL_disablePwm(HAL_Handle handle)
275 {
276  HAL_Obj *obj = (HAL_Obj *)handle;
277 
278  PWM_setOneShotTrip(obj->pwmHandle[PWM_Number_1]);
279  PWM_setOneShotTrip(obj->pwmHandle[PWM_Number_2]);
280  PWM_setOneShotTrip(obj->pwmHandle[PWM_Number_3]);
281 
282  return;
283 } // end of HAL_disablePwm() function
284 
285 
288 static inline void HAL_disableTbClockSync(HAL_Handle handle)
289 {
290  HAL_Obj *obj = (HAL_Obj *)handle;
291 
292  CLK_disableTbClockSync(obj->clkHandle);
293 
294  return;
295 } // end of HAL_disableTbClockSync() function
296 
297 
302 extern void HAL_enableAdcInts(HAL_Handle handle);
303 
304 
310 extern void HAL_enableDebugInt(HAL_Handle handle);
311 
312 
315 extern void HAL_enableGlobalInts(HAL_Handle handle);
316 
317 
322 static inline void HAL_enablePwm(HAL_Handle handle)
323 {
324  HAL_Obj *obj = (HAL_Obj *)handle;
325 
326  PWM_clearOneShotTrip(obj->pwmHandle[PWM_Number_1]);
327  PWM_clearOneShotTrip(obj->pwmHandle[PWM_Number_2]);
328  PWM_clearOneShotTrip(obj->pwmHandle[PWM_Number_3]);
329 
330  return;
331 } // end of HAL_enablePwm() function
332 
333 
336 extern void HAL_enablePwmInt(HAL_Handle handle);
337 
338 
341 static inline void HAL_enableTbClockSync(HAL_Handle handle)
342 {
343  HAL_Obj *obj = (HAL_Obj *)handle;
344 
345  CLK_enableTbClockSync(obj->clkHandle);
346 
347  return;
348 } // end of HAL_enableTbClockSync() function
349 
350 
355 static inline ADC_SocSampleDelay_e HAL_getAdcSocSampleDelay(HAL_Handle handle,
356  const ADC_SocNumber_e socNumber)
357 {
358  HAL_Obj *obj = (HAL_Obj *)handle;
359 
360  return(ADC_getSocSampleDelay(obj->adcHandle,socNumber));
361 } // end of HAL_getAdcSocSampleDelay() function
362 
363 
372 static inline float_t HAL_getBias(HAL_Handle handle,
373  const HAL_SensorType_e sensorType,
374  uint_least8_t sensorNumber)
375 {
376  HAL_Obj *obj = (HAL_Obj *)handle;
377  float_t bias = 0.0;
378 
379  if(sensorType == HAL_SensorType_Current)
380  {
381  bias = obj->adcBias.I_A.value[sensorNumber];
382  }
383  else if(sensorType == HAL_SensorType_Voltage)
384  {
385  bias = obj->adcBias.V_V.value[sensorNumber];
386  }
387 
388  return(bias);
389 } // end of HAL_getBias() function
390 
391 
396 {
397  HAL_Obj *obj = (HAL_Obj *)handle;
398 
399  return(obj->current_sf);
400 } // end of HAL_getCurrentScaleFactor() function
401 
402 
406 static inline void HAL_getDutyCycles(HAL_Handle handle,uint16_t *pDutyCycles)
407 {
408  HAL_Obj *obj = (HAL_Obj *)handle;
409 
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]);
413 
414  return;
415 } // end of HAL_getDutyCycles() function
416 
417 
421 static inline uint_least8_t HAL_getNumCurrentSensors(HAL_Handle handle)
422 {
423  HAL_Obj *obj = (HAL_Obj *)handle;
424 
425 
426  return(obj->numCurrentSensors);
427 } // end of HAL_getNumCurrentSensors() function
428 
429 
433 static inline uint_least8_t HAL_getNumVoltageSensors(HAL_Handle handle)
434 {
435  HAL_Obj *obj = (HAL_Obj *)handle;
436 
437 
438  return(obj->numVoltageSensors);
439 } // end of HAL_getNumVoltageSensors() function
440 
441 
446 {
447  HAL_Obj *obj = (HAL_Obj *)handle;
448 
449  return(obj->voltage_sf);
450 } // end of HAL_getVoltageScaleFactor() function
451 
452 
459 extern void HAL_setupFaults(HAL_Handle handle);
460 
461 
468 extern HAL_Handle HAL_init(void *pMemory,const size_t numBytes);
469 
470 
471 extern void HAL_OscTempComp(HAL_Handle handle);
472 
473 
474 extern void HAL_osc1Comp(HAL_Handle handle, const int16_t sensorSample);
475 
476 
477 extern void HAL_osc2Comp(HAL_Handle handle, const int16_t sensorSample);
478 
479 
480 extern uint16_t HAL_computeOscTrimValue(int16_t coarse, int16_t fine);
481 
482 
486 static inline void HAL_initIntVectorTable(HAL_Handle handle)
487  {
488  HAL_Obj *obj = (HAL_Obj *)handle;
489  PIE_Obj *pie = (PIE_Obj *)obj->pieHandle;
490 
491 
492  ENABLE_PROTECTED_REGISTER_WRITE_MODE;
493 
494 // pie->EPWM1_INT = &led2ISR;
495 // pie->ADCINT1 = &led3OffISR;
496 // pie->ADCINT2 = &led3OnISR;
497  pie->ADCINT6 = &mainISR;
498 
499  DISABLE_PROTECTED_REGISTER_WRITE_MODE;
500 
501  return;
502  } // end of HAL_initIntVectorTable() function
503 
504 
512 static inline void HAL_readAdcData(HAL_Handle handle,HAL_AdcData_t *pAdcData)
513 {
514  HAL_Obj *obj = (HAL_Obj *)handle;
515 
516  float_t value;
517  float_t current_sf = HAL_getCurrentScaleFactor(handle);
518  float_t voltage_sf = HAL_getVoltageScaleFactor(handle);
519 
520 
521  // convert phase A current
522  // sample the first sample twice due to errata sprz342f, ignore the first sample
523  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_1);
524  value = value * current_sf - obj->adcBias.I_A.value[0];
525  pAdcData->I_A.value[0] = value;
526 
527  // convert phase B current
528  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_2);
529  value = value * current_sf - obj->adcBias.I_A.value[1];
530  pAdcData->I_A.value[1] = value;
531 
532  // convert phase C current
533  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_3);
534  value = value * current_sf - obj->adcBias.I_A.value[2];
535  pAdcData->I_A.value[2] = value;
536 
537  // convert phase A voltage
538  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_4);
539  value = value * voltage_sf - obj->adcBias.V_V.value[0];
540  pAdcData->V_V.value[0] = value;
541 
542  // convert phase B voltage
543  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_5);
544  value = value * voltage_sf - obj->adcBias.V_V.value[1];
545  pAdcData->V_V.value[1] = value;
546 
547  // convert phase C voltage
548  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_6);
549  value = value * voltage_sf - obj->adcBias.V_V.value[2];
550  pAdcData->V_V.value[2] = value;
551 
552  // convert dcBus voltage
553  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_7);
554  value = value * voltage_sf;
555  pAdcData->dcBus_V = value;
556 
557  return;
558 } // end of HAL_readAdcData() function
559 
560 
561 static inline void HAL_readAdcDataWithOffsets(HAL_Handle handle,HAL_AdcData_t *pAdcData)
562 {
563  HAL_Obj *obj = (HAL_Obj *)handle;
564 
565  float_t value;
566  float_t current_sf = HAL_getCurrentScaleFactor(handle);
567  float_t voltage_sf = HAL_getVoltageScaleFactor(handle);
568 
569 
570  // convert phase A current
571  // sample the first sample twice due to errata sprz342f, ignore the first sample
572  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_1);
573  pAdcData->I_A.value[0] = value * current_sf;
574 
575  // convert phase B current
576  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_2);
577  pAdcData->I_A.value[1] = value * current_sf;
578 
579  // convert phase C current
580  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_3);
581  pAdcData->I_A.value[2] = value * current_sf;
582 
583  // convert phase A voltage
584  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_4);
585  pAdcData->V_V.value[0] = value * voltage_sf;
586 
587  // convert phase B voltage
588  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_5);
589  pAdcData->V_V.value[1] = value * voltage_sf;
590 
591  // convert phase C voltage
592  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_6);
593  pAdcData->V_V.value[2] = value * voltage_sf;
594 
595  // convert dcBus voltage
596  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_7);
597  pAdcData->dcBus_V = value * voltage_sf;
598 
599  return;
600 } // end of HAL_readAdcDataWithOffsets() function
601 
602 
607 static inline uint32_t HAL_readTimerCnt(HAL_Handle handle,const uint_least8_t timerNumber)
608 {
609  HAL_Obj *obj = (HAL_Obj *)handle;
610  uint32_t timerCnt = TIMER_getCount(obj->timerHandle[timerNumber]);
611 
612  return(timerCnt);
613 } // end of HAL_readTimerCnt() function
614 
615 
619 static inline void HAL_resetPwmCount(HAL_Handle handle,
620  PWM_Number_e pwmNumber)
621 {
622  HAL_Obj *obj = (HAL_Obj *)handle;
623 
624  PWM_setCount(obj->pwmHandle[pwmNumber],0);
625 
626  return;
627 } // HAL_resetPwmCount() function
628 
629 
634 static inline void HAL_setAdcSocSampleDelay(HAL_Handle handle,
635  const ADC_SocNumber_e socNumber,
636  const ADC_SocSampleDelay_e sampleDelay)
637 {
638  HAL_Obj *obj = (HAL_Obj *)handle;
639 
640  ADC_setSocSampleDelay(obj->adcHandle,socNumber,sampleDelay);
641 
642  return;
643 } // end of HAL_setAdcSocSampleDelay() function
644 
645 
651 static inline void HAL_setBias(HAL_Handle handle,
652  const HAL_SensorType_e sensorType,
653  uint_least8_t sensorNumber,
654  const float_t bias)
655 {
656  HAL_Obj *obj = (HAL_Obj *)handle;
657 
658 
659  if(sensorType == HAL_SensorType_Current)
660  {
661  obj->adcBias.I_A.value[sensorNumber] = bias;
662  }
663  else if(sensorType == HAL_SensorType_Voltage)
664  {
665  obj->adcBias.V_V.value[sensorNumber] = bias;
666  }
667 
668  return;
669 } // end of HAL_setBias() function
670 
671 
675 static inline void HAL_setCurrentScaleFactor(HAL_Handle handle,const float_t current_sf)
676 {
677  HAL_Obj *obj = (HAL_Obj *)handle;
678 
679 
680  obj->current_sf = current_sf;
681 
682  return;
683 } // end of HAL_setCurrentScaleFactor() function
684 
685 
689 static inline void HAL_setGpioHigh(HAL_Handle handle,const GPIO_Number_e gpioNumber)
690 {
691  HAL_Obj *obj = (HAL_Obj *)handle;
692 
693 
694  // set GPIO high
695  GPIO_setHigh(obj->gpioHandle,gpioNumber);
696 
697  return;
698 } // end of HAL_setGpioHigh() function
699 
700 
704 static inline void HAL_setGpioLow(HAL_Handle handle,const GPIO_Number_e gpioNumber)
705 {
706  HAL_Obj *obj = (HAL_Obj *)handle;
707 
708 
709  // set GPIO low
710  GPIO_setLow(obj->gpioHandle,gpioNumber);
711 
712  return;
713 } // end of HAL_setGpioLow() function
714 
715 
719 static inline void HAL_setNumCurrentSensors(HAL_Handle handle,const uint_least8_t numCurrentSensors)
720 {
721  HAL_Obj *obj = (HAL_Obj *)handle;
722 
723 
724  obj->numCurrentSensors = numCurrentSensors;
725 
726  return;
727 } // end of HAL_setNumCurrentSensors() function
728 
729 
733 static inline void HAL_setNumVoltageSensors(HAL_Handle handle,const uint_least8_t numVoltageSensors)
734 {
735  HAL_Obj *obj = (HAL_Obj *)handle;
736 
737 
738  obj->numVoltageSensors = numVoltageSensors;
739 
740  return;
741 } // end of HAL_setNumVoltageSensors() function
742 
743 
748 static inline void HAL_setPwmFreq_kHz(HAL_Handle handle,
749  PWM_Number_e pwmNumber,
750  HAL_PwmFreq_e pwmFreq_kHz)
751 {
752  HAL_Obj *obj = (HAL_Obj *)handle;
753 
754  PWM_setPeriod(obj->pwmHandle[pwmNumber],pwmFreq_kHz);
755 
756  return;
757 } // HAL_setPwmFreq_Hz() function
758 
759 
763 static inline void HAL_setVoltageScaleFactor(HAL_Handle handle,const float_t voltage_sf)
764 {
765  HAL_Obj *obj = (HAL_Obj *)handle;
766 
767  obj->voltage_sf = voltage_sf;
768 
769  return;
770 } // end of HAL_setVoltageScaleFactor() function
771 
772 
779 extern void HAL_setParams(HAL_Handle handle,const USER_Params *pUserParams);
780 
781 
784 extern void HAL_setupAdcs(HAL_Handle handle);
785 
786 
790 extern void HAL_setupClks(HAL_Handle handle);
791 
792 
795 extern void HAL_setupFaults(HAL_Handle handle);
796 
797 
800 extern void HAL_setupGpios(HAL_Handle handle);
801 
802 
804 extern void HAL_setupFlash(HAL_Handle handle);
805 
806 
809 extern void HAL_setupPeripheralClks(HAL_Handle handle);
810 
811 
814 extern void HAL_setupPie(HAL_Handle handle);
815 
816 
820 extern void HAL_setupPll(HAL_Handle handle,const PLL_ClkFreq_e clkFreq);
821 
822 
828 extern void HAL_setupPwms(HAL_Handle handle,
829  const float_t systemFreq_MHz,
830  const float_t pwmPeriod_usec,
831  const uint_least16_t numPwmTicksPerIsrTick);
832 
833 
838 extern void HAL_setupPwmDacs(HAL_Handle handle,
839  const float_t systemFreq_MHz,
840  const float_t dacFreq_kHz);
841 
842 
846 void HAL_setupTimers(HAL_Handle handle,const float_t systemFreq_MHz);
847 
848 
852 static inline void HAL_toggleGpio(HAL_Handle handle,const GPIO_Number_e gpioNumber)
853 {
854  HAL_Obj *obj = (HAL_Obj *)handle;
855 
856 
857  // toggle the GPIO
858  GPIO_toggle(obj->gpioHandle,gpioNumber);
859 
860  return;
861 } // end of HAL_toggleGpio() function
862 
863 
868 static inline void HAL_updateAdcBias(HAL_Handle handle,
869  OFFSET_Handle *pOffsetHandle_I,
870  OFFSET_Handle *pOffsetHandle_V)
871 {
872  uint_least8_t cnt;
873 
874 
875  // update the current bias
876  for(cnt=0;cnt<HAL_getNumCurrentSensors(handle);cnt++)
877  {
878  float_t bias = HAL_getBias(handle,HAL_SensorType_Current,cnt);
879 
880  bias += OFFSET_getOffset(pOffsetHandle_I[cnt]);
881 
882  HAL_setBias(handle,HAL_SensorType_Current,cnt,bias);
883  }
884 
885 
886  // update the voltage bias
887  for(cnt=0;cnt<HAL_getNumVoltageSensors(handle);cnt++)
888  {
889  float_t bias = HAL_getBias(handle,HAL_SensorType_Voltage,cnt);
890 
891  bias += OFFSET_getOffset(pOffsetHandle_V[cnt]);
892 
893  HAL_setBias(handle,HAL_SensorType_Voltage,cnt,bias);
894  }
895 
896  return;
897 } // end of HAL_updateAdcBias() function
898 
899 
903 static inline void HAL_writeDacData(HAL_Handle handle,const HAL_DacData_t *pDacData)
904 {
905  HAL_Obj *obj = (HAL_Obj *)handle;
906  uint_least8_t pwmCnt;
907  uint_least8_t dataCnt=0;
908 
909  for(pwmCnt=0;pwmCnt<3;pwmCnt++)
910  {
911  PWM_Obj *pwm = (PWM_Obj *)obj->pwmDacHandle[pwmCnt];
912 
913  // compute the value
914  float_t period = (float_t)(pwm->TBPRD);
915  float_t V_pu = pDacData->value[dataCnt];
916  float_t V_sat_pu = MATH_sat(V_pu,0.5,-0.5);
917  float_t V_sat_dc_pu = V_sat_pu + 0.5;
918  int16_t pwmValue = (int16_t)(V_sat_dc_pu * period);
919 
920  // increment the data counter
921  dataCnt++;
922 
923  // write the PWM data value
924  PWM_write_CmpA(obj->pwmDacHandle[pwmCnt],pwmValue);
925 
926  if(pwmCnt == 0)
927  {
928  float_t V_pu = pDacData->value[dataCnt];
929  float_t V_sat_pu = MATH_sat(V_pu,0.5,-0.5);
930  float_t V_sat_dc_pu = V_sat_pu + 0.5;
931  int16_t pwmValue = (int16_t)(V_sat_dc_pu * period);
932 
933  // write the PWM data value
934  PWM_write_CmpB(obj->pwmDacHandle[pwmCnt],pwmValue);
935 
936  // increment the data counter
937  dataCnt++;
938  }
939  }
940 
941  return;
942 } // end of HAL_writeDacData() function
943 
944 
948 static inline void HAL_writePwmData(HAL_Handle handle,const HAL_PwmData_t *pPwmData)
949 {
950  HAL_Obj *obj = (HAL_Obj *)handle;
951  uint_least8_t pwmCnt;
952 
953  for(pwmCnt=0;pwmCnt<3;pwmCnt++)
954  {
955  PWM_Obj *pwm = (PWM_Obj *)obj->pwmHandle[pwmCnt];
956 
957  // compute the value
958  float_t period = (float_t)(pwm->TBPRD);
959  float_t V_pu = -pPwmData->Vabc_pu.value[pwmCnt];
960  float_t V_sat_pu = MATH_sat(V_pu,0.5,-0.5);
961  float_t V_sat_dc_pu = V_sat_pu + 0.5;
962  int16_t pwmValue = (int16_t)(V_sat_dc_pu * period);
963 
964  // write the PWM data value
965  PWM_write_CmpA(obj->pwmHandle[pwmCnt],pwmValue);
966  }
967 
968  return;
969 } // end of HAL_writePwmData() function
970 
975 static inline uint16_t HAL_readPwmPeriod(HAL_Handle handle,const PWM_Number_e pwmNumber)
976 {
977  HAL_Obj *obj = (HAL_Obj *)handle;
978 
979  // the period value to be returned
980  uint16_t pwmPeriodValue;
981 
982  pwmPeriodValue = PWM_getPeriod(obj->pwmHandle[pwmNumber]);
983 
984  return(pwmPeriodValue);
985 } // end of HAL_readPwmPeriod() function
986 
987 
988 #ifdef __cplusplus
989 }
990 #endif // extern "C"
991 
993 
994 
995 #endif // end of _HAL_H_ definition
996 
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
Definition: 32b/hal_data.h:69
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.
_iq value[3]
Definition: 32b/math.h:261
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.
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.
Definition: float/math.h:218
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.
Definition: 32b/offset.h:95
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.
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.
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 void HAL_setCurrentScaleFactor(HAL_Handle handle, const float_t current_sf)
Sets the current scale factor in the hal.