MotorWare f2806x Module API Documentation
drv8312kit_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 
65 #define Device_cal (void (*)(void))0x3D7C80
66 
67 
70 #define FP_SCALE 32768
71 
73 #define FP_ROUND FP_SCALE/2
74 
78 #define OSC_POSTRIM 32
79 #define OSC_POSTRIM_OFF FP_SCALE*OSC_POSTRIM
80 
81 
83 
85 #define getOsc1FineTrimSlope() (*(int16_t (*)(void))0x3D7E90)()
86 
88 #define getOsc1FineTrimOffset() (*(int16_t (*)(void))0x3D7E93)()
89 
91 #define getOsc1CoarseTrim() (*(int16_t (*)(void))0x3D7E96)()
92 
95 #define getOsc2FineTrimSlope() (*(int16_t (*)(void))0x3D7E99)()
96 
98 #define getOsc2FineTrimOffset() (*(int16_t (*)(void))0x3D7E9C)()
99 
101 #define getOsc2CoarseTrim() (*(int16_t (*)(void))0x3D7E9F)()
102 
104 #define getRefTempOffset() (*(int16_t (*)(void))0x3D7EA2)()
105 
106 
109 #define HAL_PWM_DBFED_CNT 1
110 
111 
114 #define HAL_PWM_DBRED_CNT 1
115 
116 
119 #define HAL_turnLedOff HAL_setGpioLow
120 
121 
124 #define HAL_turnLedOn HAL_setGpioHigh
125 
126 
129 #define HAL_toggleLed HAL_toggleGpio
130 
131 
132 // **************************************************************************
133 // the typedefs
134 
135 
138 typedef enum
139 {
140  HAL_Gpio_LED2=GPIO_Number_31,
141  HAL_Gpio_LED3=GPIO_Number_34
143 
144 
147 typedef enum
148 {
175 } HAL_PwmFreq_e;
176 
177 
180 typedef enum
181 {
185 
186 
187 // **************************************************************************
188 // the globals
189 
190 extern interrupt void led2ISR(void);
191 extern interrupt void led3OffISR(void);
192 extern interrupt void led3OnISR(void);
193 extern interrupt void mainISR(void);
194 
195 
196 // **************************************************************************
197 // the function prototypes
198 
199 extern void HAL_AdcCalChanSelect(HAL_Handle handle, const ADC_SocChanNumber_e chanNumber);
200 
201 
202 extern uint16_t HAL_AdcCalConversion(HAL_Handle handle);
203 
204 
205 extern void HAL_AdcOffsetSelfCal(HAL_Handle handle);
206 
207 
208 
213 static inline void HAL_acqAdcInt(HAL_Handle handle,const ADC_IntNumber_e intNumber)
214 {
215  HAL_Obj *obj = (HAL_Obj *)handle;
216 
217 
218  // clear the ADC interrupt flag
219  ADC_clearIntFlag(obj->adcHandle,intNumber);
220 
221 
222  // Acknowledge interrupt from PIE group 10
223  PIE_clearInt(obj->pieHandle,PIE_GroupNumber_10);
224 
225  return;
226 } // end of HAL_acqAdcInt() function
227 
228 
233 static inline void HAL_acqPwmInt(HAL_Handle handle,const PWM_Number_e pwmNumber)
234 {
235  HAL_Obj *obj = (HAL_Obj *)handle;
236 
237 
238  // clear the PWM interrupt flag
239  PWM_clearIntFlag(obj->pwmHandle[pwmNumber]);
240 
241 
242  // clear the SOCA flag
243  PWM_clearSocAFlag(obj->pwmHandle[pwmNumber]);
244 
245 
246  // Acknowledge interrupt from PIE group 3
247  PIE_clearInt(obj->pieHandle,PIE_GroupNumber_3);
248 
249  return;
250 } // end of HAL_acqPwmInt() function
251 
252 
258 extern void HAL_cal(HAL_Handle handle);
259 
260 
263 extern void HAL_disableGlobalInts(HAL_Handle handle);
264 
265 
270 static inline void HAL_disablePwm(HAL_Handle handle)
271 {
272  HAL_Obj *obj = (HAL_Obj *)handle;
273 
274  PWM_setOneShotTrip(obj->pwmHandle[PWM_Number_1]);
275  PWM_setOneShotTrip(obj->pwmHandle[PWM_Number_2]);
276  PWM_setOneShotTrip(obj->pwmHandle[PWM_Number_3]);
277 
278  return;
279 } // end of HAL_disablePwm() function
280 
281 
284 static inline void HAL_disableTbClockSync(HAL_Handle handle)
285 {
286  HAL_Obj *obj = (HAL_Obj *)handle;
287 
288  CLK_disableTbClockSync(obj->clkHandle);
289 
290  return;
291 } // end of HAL_disableTbClockSync() function
292 
293 
298 extern void HAL_enableAdcInts(HAL_Handle handle);
299 
300 
306 extern void HAL_enableDebugInt(HAL_Handle handle);
307 
308 
311 extern void HAL_enableGlobalInts(HAL_Handle handle);
312 
313 
318 static inline void HAL_enablePwm(HAL_Handle handle)
319 {
320  HAL_Obj *obj = (HAL_Obj *)handle;
321 
322  PWM_clearOneShotTrip(obj->pwmHandle[PWM_Number_1]);
323  PWM_clearOneShotTrip(obj->pwmHandle[PWM_Number_2]);
324  PWM_clearOneShotTrip(obj->pwmHandle[PWM_Number_3]);
325 
326  return;
327 } // end of HAL_enablePwm() function
328 
329 
332 extern void HAL_enablePwmInt(HAL_Handle handle);
333 
334 
337 static inline void HAL_enableTbClockSync(HAL_Handle handle)
338 {
339  HAL_Obj *obj = (HAL_Obj *)handle;
340 
341  CLK_enableTbClockSync(obj->clkHandle);
342 
343  return;
344 } // end of HAL_enableTbClockSync() function
345 
346 
351 static inline ADC_SocSampleDelay_e HAL_getAdcSocSampleDelay(HAL_Handle handle,
352  const ADC_SocNumber_e socNumber)
353 {
354  HAL_Obj *obj = (HAL_Obj *)handle;
355 
356  return(ADC_getSocSampleDelay(obj->adcHandle,socNumber));
357 } // end of HAL_getAdcSocSampleDelay() function
358 
359 
368 static inline float_t HAL_getBias(HAL_Handle handle,
369  const HAL_SensorType_e sensorType,
370  uint_least8_t sensorNumber)
371 {
372  HAL_Obj *obj = (HAL_Obj *)handle;
373  float_t bias = 0.0;
374 
375  if(sensorType == HAL_SensorType_Current)
376  {
377  bias = obj->adcBias.I_A.value[sensorNumber];
378  }
379  else if(sensorType == HAL_SensorType_Voltage)
380  {
381  bias = obj->adcBias.V_V.value[sensorNumber];
382  }
383 
384  return(bias);
385 } // end of HAL_getBias() function
386 
387 
392 {
393  HAL_Obj *obj = (HAL_Obj *)handle;
394 
395  return(obj->current_sf);
396 } // end of HAL_getCurrentScaleFactor() function
397 
398 
402 static inline void HAL_getDutyCycles(HAL_Handle handle,uint16_t *pDutyCycles)
403 {
404  HAL_Obj *obj = (HAL_Obj *)handle;
405 
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]);
409 
410  return;
411 } // end of HAL_getDutyCycles() function
412 
413 
417 static inline uint_least8_t HAL_getNumCurrentSensors(HAL_Handle handle)
418 {
419  HAL_Obj *obj = (HAL_Obj *)handle;
420 
421 
422  return(obj->numCurrentSensors);
423 } // end of HAL_getNumCurrentSensors() function
424 
425 
429 static inline uint_least8_t HAL_getNumVoltageSensors(HAL_Handle handle)
430 {
431  HAL_Obj *obj = (HAL_Obj *)handle;
432 
433 
434  return(obj->numVoltageSensors);
435 } // end of HAL_getNumVoltageSensors() function
436 
437 
442 {
443  HAL_Obj *obj = (HAL_Obj *)handle;
444 
445  return(obj->voltage_sf);
446 } // end of HAL_getVoltageScaleFactor() function
447 
448 
455 extern void HAL_setupFaults(HAL_Handle handle);
456 
457 
464 extern HAL_Handle HAL_init(void *pMemory,const size_t numBytes);
465 
466 
467 extern void HAL_OscTempComp(HAL_Handle handle);
468 
469 
470 extern void HAL_osc1Comp(HAL_Handle handle, const int16_t sensorSample);
471 
472 
473 extern void HAL_osc2Comp(HAL_Handle handle, const int16_t sensorSample);
474 
475 
476 extern uint16_t HAL_computeOscTrimValue(int16_t coarse, int16_t fine);
477 
478 
482 static inline void HAL_initIntVectorTable(HAL_Handle handle)
483  {
484  HAL_Obj *obj = (HAL_Obj *)handle;
485  PIE_Obj *pie = (PIE_Obj *)obj->pieHandle;
486 
487 
488  ENABLE_PROTECTED_REGISTER_WRITE_MODE;
489 
490 // pie->EPWM1_INT = &led2ISR;
491 // pie->ADCINT1 = &led3OffISR;
492 // pie->ADCINT2 = &led3OnISR;
493  pie->ADCINT6 = &mainISR;
494 
495  DISABLE_PROTECTED_REGISTER_WRITE_MODE;
496 
497  return;
498  } // end of HAL_initIntVectorTable() function
499 
500 
508 static inline void HAL_readAdcData(HAL_Handle handle,HAL_AdcData_t *pAdcData)
509 {
510  HAL_Obj *obj = (HAL_Obj *)handle;
511 
512  float_t value;
513  float_t current_sf = -HAL_getCurrentScaleFactor(handle);
514  float_t voltage_sf = HAL_getVoltageScaleFactor(handle);
515 
516 
517  // convert phase A current
518  // sample the first sample twice due to errata sprz342f, ignore the first sample
519  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_1);
520  value = value * current_sf - obj->adcBias.I_A.value[0];
521  pAdcData->I_A.value[0] = value;
522 
523  // convert phase B current
524  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_2);
525  value = value * current_sf - obj->adcBias.I_A.value[1];
526  pAdcData->I_A.value[1] = value;
527 
528  // convert phase C current
529  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_3);
530  value = value * current_sf - obj->adcBias.I_A.value[2];
531  pAdcData->I_A.value[2] = value;
532 
533  // convert phase A voltage
534  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_4);
535  value = value * voltage_sf - obj->adcBias.V_V.value[0];
536  pAdcData->V_V.value[0] = value;
537 
538  // convert phase B voltage
539  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_5);
540  value = value * voltage_sf - obj->adcBias.V_V.value[1];
541  pAdcData->V_V.value[1] = value;
542 
543  // convert phase C voltage
544  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_6);
545  value = value * voltage_sf - obj->adcBias.V_V.value[2];
546  pAdcData->V_V.value[2] = value;
547 
548  // convert dcBus voltage
549  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_7);
550  value = value * voltage_sf;
551  pAdcData->dcBus_V = value;
552 
553  return;
554 } // end of HAL_readAdcData() function
555 
556 
557 static inline void HAL_readAdcDataWithOffsets(HAL_Handle handle,HAL_AdcData_t *pAdcData)
558 {
559  HAL_Obj *obj = (HAL_Obj *)handle;
560 
561  float_t value;
562  float_t current_sf = -HAL_getCurrentScaleFactor(handle);
563  float_t voltage_sf = HAL_getVoltageScaleFactor(handle);
564 
565 
566  // convert phase A current
567  // sample the first sample twice due to errata sprz342f, ignore the first sample
568  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_1);
569  pAdcData->I_A.value[0] = value * current_sf;
570 
571  // convert phase B current
572  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_2);
573  pAdcData->I_A.value[1] = value * current_sf;
574 
575  // convert phase C current
576  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_3);
577  pAdcData->I_A.value[2] = value * current_sf;
578 
579  // convert phase A voltage
580  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_4);
581  pAdcData->V_V.value[0] = value * voltage_sf;
582 
583  // convert phase B voltage
584  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_5);
585  pAdcData->V_V.value[1] = value * voltage_sf;
586 
587  // convert phase C voltage
588  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_6);
589  pAdcData->V_V.value[2] = value * voltage_sf;
590 
591  // convert dcBus voltage
592  value = (float_t)ADC_readResult(obj->adcHandle,ADC_ResultNumber_7);
593  pAdcData->dcBus_V = value * voltage_sf;
594 
595  return;
596 } // end of HAL_readAdcDataWithOffsets() function
597 
598 
603 static inline uint32_t HAL_readTimerCnt(HAL_Handle handle,const uint_least8_t timerNumber)
604 {
605  HAL_Obj *obj = (HAL_Obj *)handle;
606  uint32_t timerCnt = TIMER_getCount(obj->timerHandle[timerNumber]);
607 
608  return(timerCnt);
609 } // end of HAL_readTimerCnt() function
610 
611 
615 static inline void HAL_resetPwmCount(HAL_Handle handle,
616  PWM_Number_e pwmNumber)
617 {
618  HAL_Obj *obj = (HAL_Obj *)handle;
619 
620  PWM_setCount(obj->pwmHandle[pwmNumber],0);
621 
622  return;
623 } // HAL_resetPwmCount() function
624 
625 
630 static inline void HAL_setAdcSocSampleDelay(HAL_Handle handle,
631  const ADC_SocNumber_e socNumber,
632  const ADC_SocSampleDelay_e sampleDelay)
633 {
634  HAL_Obj *obj = (HAL_Obj *)handle;
635 
636  ADC_setSocSampleDelay(obj->adcHandle,socNumber,sampleDelay);
637 
638  return;
639 } // end of HAL_setAdcSocSampleDelay() function
640 
641 
647 static inline void HAL_setBias(HAL_Handle handle,
648  const HAL_SensorType_e sensorType,
649  uint_least8_t sensorNumber,
650  const float_t bias)
651 {
652  HAL_Obj *obj = (HAL_Obj *)handle;
653 
654 
655  if(sensorType == HAL_SensorType_Current)
656  {
657  obj->adcBias.I_A.value[sensorNumber] = bias;
658  }
659  else if(sensorType == HAL_SensorType_Voltage)
660  {
661  obj->adcBias.V_V.value[sensorNumber] = bias;
662  }
663 
664  return;
665 } // end of HAL_setBias() function
666 
667 
671 static inline void HAL_setCurrentScaleFactor(HAL_Handle handle,const float_t current_sf)
672 {
673  HAL_Obj *obj = (HAL_Obj *)handle;
674 
675 
676  obj->current_sf = current_sf;
677 
678  return;
679 } // end of HAL_setCurrentScaleFactor() function
680 
681 
685 static inline void HAL_setGpioHigh(HAL_Handle handle,const GPIO_Number_e gpioNumber)
686 {
687  HAL_Obj *obj = (HAL_Obj *)handle;
688 
689 
690  // set GPIO high
691  GPIO_setHigh(obj->gpioHandle,gpioNumber);
692 
693  return;
694 } // end of HAL_setGpioHigh() function
695 
696 
700 static inline void HAL_setGpioLow(HAL_Handle handle,const GPIO_Number_e gpioNumber)
701 {
702  HAL_Obj *obj = (HAL_Obj *)handle;
703 
704 
705  // set GPIO low
706  GPIO_setLow(obj->gpioHandle,gpioNumber);
707 
708  return;
709 } // end of HAL_setGpioLow() function
710 
711 
715 static inline void HAL_setNumCurrentSensors(HAL_Handle handle,const uint_least8_t numCurrentSensors)
716 {
717  HAL_Obj *obj = (HAL_Obj *)handle;
718 
719 
720  obj->numCurrentSensors = numCurrentSensors;
721 
722  return;
723 } // end of HAL_setNumCurrentSensors() function
724 
725 
729 static inline void HAL_setNumVoltageSensors(HAL_Handle handle,const uint_least8_t numVoltageSensors)
730 {
731  HAL_Obj *obj = (HAL_Obj *)handle;
732 
733 
734  obj->numVoltageSensors = numVoltageSensors;
735 
736  return;
737 } // end of HAL_setNumVoltageSensors() function
738 
739 
744 static inline void HAL_setPwmFreq_kHz(HAL_Handle handle,
745  PWM_Number_e pwmNumber,
746  HAL_PwmFreq_e pwmFreq_kHz)
747 {
748  HAL_Obj *obj = (HAL_Obj *)handle;
749 
750  PWM_setPeriod(obj->pwmHandle[pwmNumber],pwmFreq_kHz);
751 
752  return;
753 } // HAL_setPwmFreq_Hz() function
754 
755 
759 static inline void HAL_setVoltageScaleFactor(HAL_Handle handle,const float_t voltage_sf)
760 {
761  HAL_Obj *obj = (HAL_Obj *)handle;
762 
763  obj->voltage_sf = voltage_sf;
764 
765  return;
766 } // end of HAL_setVoltageScaleFactor() function
767 
768 
775 extern void HAL_setParams(HAL_Handle handle,const USER_Params *pUserParams);
776 
777 
780 extern void HAL_setupAdcs(HAL_Handle handle);
781 
782 
786 extern void HAL_setupClks(HAL_Handle handle);
787 
788 
791 extern void HAL_setupFaults(HAL_Handle handle);
792 
793 
796 extern void HAL_setupGpios(HAL_Handle handle);
797 
798 
800 extern void HAL_setupFlash(HAL_Handle handle);
801 
802 
805 extern void HAL_setupPeripheralClks(HAL_Handle handle);
806 
807 
810 extern void HAL_setupPie(HAL_Handle handle);
811 
812 
816 extern void HAL_setupPll(HAL_Handle handle,const PLL_ClkFreq_e clkFreq);
817 
818 
824 extern void HAL_setupPwms(HAL_Handle handle,
825  const float_t systemFreq_MHz,
826  const float_t pwmPeriod_usec,
827  const uint_least16_t numPwmTicksPerIsrTick);
828 
829 
834 extern void HAL_setupPwmDacs(HAL_Handle handle,
835  const float_t systemFreq_MHz,
836  const float_t dacFreq_kHz);
837 
838 
842 void HAL_setupQEP(QEP_Handle qepHandle,const USER_Params *pUserParams,const uint32_t unitTimerFreq_Hz);
843 
844 
847 extern void HAL_setupSpiA(HAL_Handle handle);
848 
849 
852 extern void HAL_setupSpiB(HAL_Handle handle);
853 
854 
858 void HAL_setupTimers(HAL_Handle handle,const float_t systemFreq_MHz);
859 
860 
864 static inline void HAL_toggleGpio(HAL_Handle handle,const GPIO_Number_e gpioNumber)
865 {
866  HAL_Obj *obj = (HAL_Obj *)handle;
867 
868 
869  // toggle the GPIO
870  GPIO_toggle(obj->gpioHandle,gpioNumber);
871 
872  return;
873 } // end of HAL_toggleGpio() function
874 
875 
880 static inline void HAL_updateAdcBias(HAL_Handle handle,
881  OFFSET_Handle *pOffsetHandle_I,
882  OFFSET_Handle *pOffsetHandle_V)
883 {
884  uint_least8_t cnt;
885 
886 
887  // update the current bias
888  for(cnt=0;cnt<HAL_getNumCurrentSensors(handle);cnt++)
889  {
890  float_t bias = HAL_getBias(handle,HAL_SensorType_Current,cnt);
891 
892  bias += OFFSET_getOffset(pOffsetHandle_I[cnt]);
893 
894  HAL_setBias(handle,HAL_SensorType_Current,cnt,bias);
895  }
896 
897 
898  // update the voltage bias
899  for(cnt=0;cnt<HAL_getNumVoltageSensors(handle);cnt++)
900  {
901  float_t bias = HAL_getBias(handle,HAL_SensorType_Voltage,cnt);
902 
903  bias += OFFSET_getOffset(pOffsetHandle_V[cnt]);
904 
905  HAL_setBias(handle,HAL_SensorType_Voltage,cnt,bias);
906  }
907 
908  return;
909 } // end of HAL_updateAdcBias() function
910 
911 
915 static inline void HAL_writeDacData(HAL_Handle handle,const HAL_DacData_t *pDacData)
916 {
917  HAL_Obj *obj = (HAL_Obj *)handle;
918  uint_least8_t pwmCnt;
919  uint_least8_t dataCnt=0;
920 
921  for(pwmCnt=0;pwmCnt<3;pwmCnt++)
922  {
923  PWM_Obj *pwm = (PWM_Obj *)obj->pwmDacHandle[pwmCnt];
924 
925  // compute the value
926  float_t period = (float_t)(pwm->TBPRD);
927  float_t V_pu = pDacData->value[dataCnt];
928  float_t V_sat_pu = MATH_sat(V_pu,0.5,-0.5);
929  float_t V_sat_dc_pu = V_sat_pu + 0.5;
930  int16_t pwmValue = (int16_t)(V_sat_dc_pu * period);
931 
932  // increment the data counter
933  dataCnt++;
934 
935  // write the PWM data value
936  PWM_write_CmpA(obj->pwmDacHandle[pwmCnt],pwmValue);
937 
938  if(pwmCnt == 0)
939  {
940  float_t V_pu = pDacData->value[dataCnt];
941  float_t V_sat_pu = MATH_sat(V_pu,0.5,-0.5);
942  float_t V_sat_dc_pu = V_sat_pu + 0.5;
943  int16_t pwmValue = (int16_t)(V_sat_dc_pu * period);
944 
945  // write the PWM data value
946  PWM_write_CmpB(obj->pwmDacHandle[pwmCnt],pwmValue);
947 
948  // increment the data counter
949  dataCnt++;
950  }
951  }
952 
953  return;
954 } // end of HAL_writeDacData() function
955 
956 
960 static inline void HAL_writePwmData(HAL_Handle handle,const HAL_PwmData_t *pPwmData)
961 {
962  HAL_Obj *obj = (HAL_Obj *)handle;
963  uint_least8_t pwmCnt;
964 
965  for(pwmCnt=0;pwmCnt<3;pwmCnt++)
966  {
967  PWM_Obj *pwm = (PWM_Obj *)obj->pwmHandle[pwmCnt];
968 
969  // compute the value
970  float_t period = (float_t)(pwm->TBPRD);
971  float_t V_pu = -pPwmData->Vabc_pu.value[pwmCnt];
972  float_t V_sat_pu = MATH_sat(V_pu,0.5,-0.5);
973  float_t V_sat_dc_pu = V_sat_pu + 0.5;
974  int16_t pwmValue = (int16_t)(V_sat_dc_pu * period);
975 
976  // write the PWM data value
977  PWM_write_CmpA(obj->pwmHandle[pwmCnt],pwmValue);
978  }
979 
980  return;
981 } // end of HAL_writePwmData() function
982 
987 static inline uint16_t HAL_readPwmPeriod(HAL_Handle handle,const PWM_Number_e pwmNumber)
988 {
989  HAL_Obj *obj = (HAL_Obj *)handle;
990 
991  // the period value to be returned
992  uint16_t pwmPeriodValue;
993 
994  pwmPeriodValue = PWM_getPeriod(obj->pwmHandle[pwmNumber]);
995 
996  return(pwmPeriodValue);
997 } // end of HAL_readPwmPeriod() function
998 
999 
1000 #ifdef __cplusplus
1001 }
1002 #endif // extern "C"
1003 
1005 
1006 
1007 #endif // end of _HAL_H_ definition
1008 
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
Definition: 32b/hal_data.h:69
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.
_iq value[3]
Definition: 32b/math.h:261
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
static void HAL_readAdcData(HAL_Handle handle, HAL_AdcData_t *pAdcData)
Reads the ADC data.
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.
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.
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.
Definition: 32b/offset.h:95
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.
static uint16_t HAL_readPwmPeriod(HAL_Handle handle, const PWM_Number_e pwmNumber)
Reads PWM period register.
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.
Definition: 32b/offset.h:115
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.
Definition: types.h:121
Defines the hardware abstraction layer (HAL) data.
GPIO_Handle gpioHandle
the GPIO handle