MotorWare f2806x Module API Documentation
hvkit_rev1p1/f28x/f2806x/src/hal.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2012, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
36 
37 
38 // **************************************************************************
39 // the includes
40 
41 // drivers
42 
43 // modules
44 
45 // platforms
46 #include "hal.h"
47 #include "user.h"
48 #include "hal_obj.h"
49 
50 #ifdef FLASH
51 #pragma CODE_SECTION(HAL_setupFlash,"ramfuncs");
52 #endif
53 
54 // **************************************************************************
55 // the defines
56 
57 
58 // **************************************************************************
59 // the globals
60 
62 
63 
64 // **************************************************************************
65 // the functions
66 
67 void HAL_cal(HAL_Handle handle)
68 {
69  HAL_Obj *obj = (HAL_Obj *)handle;
70 
71 
72  // enable the ADC clock
73  CLK_enableAdcClock(obj->clkHandle);
74 
75 
76  // Run the Device_cal() function
77  // This function copies the ADC and oscillator calibration values from TI reserved
78  // OTP into the appropriate trim registers
79  // This boot ROM automatically calls this function to calibrate the interal
80  // oscillators and ADC with device specific calibration data.
81  // If the boot ROM is bypassed by Code Composer Studio during the development process,
82  // then the calibration must be initialized by the application
83  ENABLE_PROTECTED_REGISTER_WRITE_MODE;
84  (*Device_cal)();
85  DISABLE_PROTECTED_REGISTER_WRITE_MODE;
86 
87  // run offsets calibration in user's memory
88  HAL_AdcOffsetSelfCal(handle);
89 
90  // run oscillator compensation
91  HAL_OscTempComp(handle);
92 
93  // disable the ADC clock
94  CLK_disableAdcClock(obj->clkHandle);
95 
96  return;
97 } // end of HAL_cal() function
98 
99 
101 {
102  HAL_Obj *obj = (HAL_Obj *)handle;
103  uint16_t Temperature;
104 
105  // disable the ADCs
106  ADC_disable(obj->adcHandle);
107 
108  // power up the bandgap circuit
109  ADC_enableBandGap(obj->adcHandle);
110 
111  // set the ADC voltage reference source to internal
112  ADC_setVoltRefSrc(obj->adcHandle,ADC_VoltageRefSrc_Int);
113 
114  // enable the ADC reference buffers
115  ADC_enableRefBuffers(obj->adcHandle);
116 
117  // Set main clock scaling factor (max45MHz clock for the ADC module)
118  ADC_setDivideSelect(obj->adcHandle,ADC_DivideSelect_ClkIn_by_2);
119 
120  // power up the ADCs
121  ADC_powerUp(obj->adcHandle);
122 
123  // enable the ADCs
124  ADC_enable(obj->adcHandle);
125 
126  // enable non-overlap mode
127  ADC_enableNoOverlapMode(obj->adcHandle);
128 
129  // connect channel A5 internally to the temperature sensor
130  ADC_setTempSensorSrc(obj->adcHandle, ADC_TempSensorSrc_Int);
131 
132  // set SOC0 channel select to ADCINA5
133  ADC_setSocChanNumber(obj->adcHandle, ADC_SocNumber_0, ADC_SocChanNumber_A5);
134 
135  // set SOC0 acquisition period to 26 ADCCLK
136  ADC_setSocSampleDelay(obj->adcHandle, ADC_SocNumber_0, ADC_SocSampleDelay_64_cycles);
137 
138  // connect ADCINT1 to EOC0
139  ADC_setIntSrc(obj->adcHandle, ADC_IntNumber_1, ADC_IntSrc_EOC0);
140 
141  // clear ADCINT1 flag
142  ADC_clearIntFlag(obj->adcHandle, ADC_IntNumber_1);
143 
144  // enable ADCINT1
145  ADC_enableInt(obj->adcHandle, ADC_IntNumber_1);
146 
147  // force start of conversion on SOC0
148  ADC_setSocFrc(obj->adcHandle, ADC_SocFrc_0);
149 
150  // wait for end of conversion
151  while (ADC_getIntFlag(obj->adcHandle, ADC_IntNumber_1) == 0){}
152 
153  // clear ADCINT1 flag
154  ADC_clearIntFlag(obj->adcHandle, ADC_IntNumber_1);
155 
156  Temperature = ADC_readResult(obj->adcHandle, ADC_ResultNumber_0);
157 
158  HAL_osc1Comp(handle, Temperature);
159 
160  HAL_osc2Comp(handle, Temperature);
161 
162  return;
163 } // end of HAL_OscTempComp() function
164 
165 
166 void HAL_osc1Comp(HAL_Handle handle, const int16_t sensorSample)
167 {
168  int16_t compOscFineTrim;
169  HAL_Obj *obj = (HAL_Obj *)handle;
170 
171  ENABLE_PROTECTED_REGISTER_WRITE_MODE;
172 
173  compOscFineTrim = ((sensorSample - getRefTempOffset())*(int32_t)getOsc1FineTrimSlope()
175 
176  if(compOscFineTrim > 31)
177  {
178  compOscFineTrim = 31;
179  }
180  else if(compOscFineTrim < -31)
181  {
182  compOscFineTrim = -31;
183  }
184 
185  OSC_setTrim(obj->oscHandle, OSC_Number_1, HAL_getOscTrimValue(getOsc1CoarseTrim(), compOscFineTrim));
186 
187  DISABLE_PROTECTED_REGISTER_WRITE_MODE;
188 
189  return;
190 } // end of HAL_osc1Comp() function
191 
192 
193 void HAL_osc2Comp(HAL_Handle handle, const int16_t sensorSample)
194 {
195  int16_t compOscFineTrim;
196  HAL_Obj *obj = (HAL_Obj *)handle;
197 
198  ENABLE_PROTECTED_REGISTER_WRITE_MODE;
199 
200  compOscFineTrim = ((sensorSample - getRefTempOffset())*(int32_t)getOsc2FineTrimSlope()
202 
203  if(compOscFineTrim > 31)
204  {
205  compOscFineTrim = 31;
206  }
207  else if(compOscFineTrim < -31)
208  {
209  compOscFineTrim = -31;
210  }
211 
212  OSC_setTrim(obj->oscHandle, OSC_Number_2, HAL_getOscTrimValue(getOsc2CoarseTrim(), compOscFineTrim));
213 
214  DISABLE_PROTECTED_REGISTER_WRITE_MODE;
215 
216  return;
217 } // end of HAL_osc2Comp() function
218 
219 
220 uint16_t HAL_getOscTrimValue(int16_t coarse, int16_t fine)
221 {
222  uint16_t regValue = 0;
223 
224  if(fine < 0)
225  {
226  regValue = ((-fine) | 0x20) << 9;
227  }
228  else
229  {
230  regValue = fine << 9;
231  }
232 
233  if(coarse < 0)
234  {
235  regValue |= ((-coarse) | 0x80);
236  }
237  else
238  {
239  regValue |= coarse;
240  }
241 
242  return regValue;
243 } // end of HAL_getOscTrimValue() function
244 
245 
247 {
248  HAL_Obj *obj = (HAL_Obj *)handle;
249  uint16_t AdcConvMean;
250 
251  // disable the ADCs
252  ADC_disable(obj->adcHandle);
253 
254  // power up the bandgap circuit
255  ADC_enableBandGap(obj->adcHandle);
256 
257  // set the ADC voltage reference source to internal
258  ADC_setVoltRefSrc(obj->adcHandle,ADC_VoltageRefSrc_Int);
259 
260  // enable the ADC reference buffers
261  ADC_enableRefBuffers(obj->adcHandle);
262 
263  // Set main clock scaling factor (max45MHz clock for the ADC module)
264  ADC_setDivideSelect(obj->adcHandle,ADC_DivideSelect_ClkIn_by_2);
265 
266  // power up the ADCs
267  ADC_powerUp(obj->adcHandle);
268 
269  // enable the ADCs
270  ADC_enable(obj->adcHandle);
271 
272  //Select VREFLO internal connection on B5
273  ADC_enableVoltRefLoConv(obj->adcHandle);
274 
275  //Select channel B5 for all SOC
276  HAL_AdcCalChanSelect(handle, ADC_SocChanNumber_B5);
277 
278  //Apply artificial offset (+80) to account for a negative offset that may reside in the ADC core
279  ADC_setOffTrim(obj->adcHandle, 80);
280 
281  //Capture ADC conversion on VREFLO
282  AdcConvMean = HAL_AdcCalConversion(handle);
283 
284  //Set offtrim register with new value (i.e remove artical offset (+80) and create a two's compliment of the offset error)
285  ADC_setOffTrim(obj->adcHandle, 80 - AdcConvMean);
286 
287  //Select external ADCIN5 input pin on B5
288  ADC_disableVoltRefLoConv(obj->adcHandle);
289 
290  return;
291 } // end of HAL_AdcOffsetSelfCal() function
292 
293 
294 void HAL_AdcCalChanSelect(HAL_Handle handle, const ADC_SocChanNumber_e chanNumber)
295 {
296  HAL_Obj *obj = (HAL_Obj *)handle;
297 
298  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_0,chanNumber);
299  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_1,chanNumber);
300  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_2,chanNumber);
301  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_3,chanNumber);
302  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_4,chanNumber);
303  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_5,chanNumber);
304  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_6,chanNumber);
305  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_7,chanNumber);
306  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_8,chanNumber);
307  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_9,chanNumber);
308  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_10,chanNumber);
309  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_11,chanNumber);
310  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_12,chanNumber);
311  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_13,chanNumber);
312  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_14,chanNumber);
313  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_15,chanNumber);
314 
315  return;
316 } // end of HAL_AdcCalChanSelect() function
317 
318 
320 {
321  HAL_Obj *obj = (HAL_Obj *)handle;
322  uint16_t index, SampleSize, Mean;
323  uint32_t Sum;
324  ADC_SocSampleDelay_e ACQPS_Value;
325 
326  index = 0; //initialize index to 0
327  SampleSize = 256; //set sample size to 256 (**NOTE: Sample size must be multiples of 2^x where is an integer >= 4)
328  Sum = 0; //set sum to 0
329  Mean = 999; //initialize mean to known value
330 
331  //Set the ADC sample window to the desired value (Sample window = ACQPS + 1)
332  ACQPS_Value = ADC_SocSampleDelay_7_cycles;
333 
334  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_0,ACQPS_Value);
335  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_1,ACQPS_Value);
336  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_2,ACQPS_Value);
337  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_3,ACQPS_Value);
338  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_4,ACQPS_Value);
339  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_5,ACQPS_Value);
340  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_6,ACQPS_Value);
341  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_7,ACQPS_Value);
342  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_8,ACQPS_Value);
343  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_9,ACQPS_Value);
344  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_10,ACQPS_Value);
345  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_11,ACQPS_Value);
346  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_12,ACQPS_Value);
347  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_13,ACQPS_Value);
348  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_14,ACQPS_Value);
349  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_15,ACQPS_Value);
350 
351  // Enabled ADCINT1 and ADCINT2
352  ADC_enableInt(obj->adcHandle, ADC_IntNumber_1);
353  ADC_enableInt(obj->adcHandle, ADC_IntNumber_2);
354 
355  // Disable continuous sampling for ADCINT1 and ADCINT2
356  ADC_setIntMode(obj->adcHandle, ADC_IntNumber_1, ADC_IntMode_EOC);
357  ADC_setIntMode(obj->adcHandle, ADC_IntNumber_2, ADC_IntMode_EOC);
358 
359  //ADCINTs trigger at end of conversion
360  ADC_setIntPulseGenMode(obj->adcHandle, ADC_IntPulseGenMode_Prior);
361 
362  // Setup ADCINT1 and ADCINT2 trigger source
363  ADC_setIntSrc(obj->adcHandle, ADC_IntNumber_1, ADC_IntSrc_EOC6);
364  ADC_setIntSrc(obj->adcHandle, ADC_IntNumber_2, ADC_IntSrc_EOC14);
365 
366  // Setup each SOC's ADCINT trigger source
367  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_0, ADC_Int2TriggersSOC);
368  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_1, ADC_Int2TriggersSOC);
369  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_2, ADC_Int2TriggersSOC);
370  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_3, ADC_Int2TriggersSOC);
371  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_4, ADC_Int2TriggersSOC);
372  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_5, ADC_Int2TriggersSOC);
373  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_6, ADC_Int2TriggersSOC);
374  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_7, ADC_Int2TriggersSOC);
375  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_8, ADC_Int1TriggersSOC);
376  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_9, ADC_Int1TriggersSOC);
377  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_10, ADC_Int1TriggersSOC);
378  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_11, ADC_Int1TriggersSOC);
379  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_12, ADC_Int1TriggersSOC);
380  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_13, ADC_Int1TriggersSOC);
381  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_14, ADC_Int1TriggersSOC);
382  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_15, ADC_Int1TriggersSOC);
383 
384  // Delay before converting ADC channels
385  usDelay(ADC_DELAY_usec);
386 
387  ADC_setSocFrcWord(obj->adcHandle, 0x00FF);
388 
389  while( index < SampleSize )
390  {
391  //Wait for ADCINT1 to trigger, then add ADCRESULT0-7 registers to sum
392  while (ADC_getIntFlag(obj->adcHandle, ADC_IntNumber_1) == 0){}
393 
394  //Must clear ADCINT1 flag since INT1CONT = 0
395  ADC_clearIntFlag(obj->adcHandle, ADC_IntNumber_1);
396 
397  Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_0);
398  Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_1);
399  Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_2);
400  Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_3);
401  Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_4);
402  Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_5);
403  Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_6);
404  Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_7);
405 
406  //Wait for ADCINT2 to trigger, then add ADCRESULT8-15 registers to sum
407  while (ADC_getIntFlag(obj->adcHandle, ADC_IntNumber_2) == 0){}
408 
409  //Must clear ADCINT2 flag since INT2CONT = 0
410  ADC_clearIntFlag(obj->adcHandle, ADC_IntNumber_2);
411 
412  Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_8);
413  Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_9);
414  Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_10);
415  Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_11);
416  Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_12);
417  Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_13);
418  Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_14);
419  Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_15);
420 
421  index+=16;
422 
423  } // end data collection
424 
425  //Disable ADCINT1 and ADCINT2 to STOP the ping-pong sampling
426  ADC_disableInt(obj->adcHandle, ADC_IntNumber_1);
427  ADC_disableInt(obj->adcHandle, ADC_IntNumber_2);
428 
429  //Calculate average ADC sample value
430  Mean = Sum / SampleSize;
431 
432  // Clear start of conversion trigger
433  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_0, ADC_NoIntTriggersSOC);
434  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_1, ADC_NoIntTriggersSOC);
435  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_2, ADC_NoIntTriggersSOC);
436  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_3, ADC_NoIntTriggersSOC);
437  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_4, ADC_NoIntTriggersSOC);
438  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_5, ADC_NoIntTriggersSOC);
439  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_6, ADC_NoIntTriggersSOC);
440  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_7, ADC_NoIntTriggersSOC);
441  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_8, ADC_NoIntTriggersSOC);
442  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_9, ADC_NoIntTriggersSOC);
443  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_10, ADC_NoIntTriggersSOC);
444  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_11, ADC_NoIntTriggersSOC);
445  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_12, ADC_NoIntTriggersSOC);
446  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_13, ADC_NoIntTriggersSOC);
447  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_14, ADC_NoIntTriggersSOC);
448  ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_15, ADC_NoIntTriggersSOC);
449 
450  //return the average
451  return(Mean);
452 } // end of HAL_AdcCalConversion() function
453 
454 
456 {
457  HAL_Obj *hal = (HAL_Obj *)halHandle;
458 
459 
460  WDOG_disable(hal->wdogHandle);
461 
462 
463  return;
464 } // end of HAL_disableWdog() function
465 
466 
468 {
469  HAL_Obj *obj = (HAL_Obj *)handle;
470 
471 
472  CPU_disableGlobalInts(obj->cpuHandle);
473 
474  return;
475 } // end of HAL_disableGlobalInts() function
476 
477 
479 {
480  HAL_Obj *obj = (HAL_Obj *)handle;
481 
482 
483  // enable the PIE interrupts associated with the ADC interrupts
484  PIE_enableAdcInt(obj->pieHandle,ADC_IntNumber_1);
485 
486 
487  // enable the ADC interrupts
488  ADC_enableInt(obj->adcHandle,ADC_IntNumber_1);
489 
490 
491  // enable the cpu interrupt for ADC interrupts
492  CPU_enableInt(obj->cpuHandle,CPU_IntNumber_10);
493 
494  return;
495 } // end of HAL_enableAdcInts() function
496 
497 
499 {
500  HAL_Obj *obj = (HAL_Obj *)handle;
501 
502 
503  CPU_enableDebugInt(obj->cpuHandle);
504 
505  return;
506 } // end of HAL_enableDebugInt() function
507 
508 
510 {
511  HAL_Obj *obj = (HAL_Obj *)handle;
512 
513 
514  CPU_enableGlobalInts(obj->cpuHandle);
515 
516  return;
517 } // end of HAL_enableGlobalInts() function
518 
519 
521 {
522  HAL_Obj *obj = (HAL_Obj *)handle;
523 
524 
525  PIE_enablePwmInt(obj->pieHandle,PWM_Number_1);
526 
527 
528  // enable the interrupt
529  PWM_enableInt(obj->pwmHandle[PWM_Number_1]);
530 
531 
532  // enable the cpu interrupt for EPWM1_INT
533  CPU_enableInt(obj->cpuHandle,CPU_IntNumber_3);
534 
535  return;
536 } // end of HAL_enablePwmInt() function
537 
538 
540 {
541  HAL_Obj *obj = (HAL_Obj *)handle;
542  uint_least8_t cnt;
543 
544 
545  // Configure Trip Mechanism for the Motor control software
546  // -Cycle by cycle trip on CPU halt
547  // -One shot fault trip zone
548  // These trips need to be repeated for EPWM1 ,2 & 3
549  for(cnt=0;cnt<3;cnt++)
550  {
551  PWM_enableTripZoneSrc(obj->pwmHandle[cnt],PWM_TripZoneSrc_CycleByCycle_TZ6_NOT);
552 
553  PWM_enableTripZoneSrc(obj->pwmHandle[cnt],PWM_TripZoneSrc_OneShot_TZ1_NOT);
554 
555  // What do we want the OST/CBC events to do?
556  // TZA events can force EPWMxA
557  // TZB events can force EPWMxB
558 
559  PWM_setTripZoneState_TZA(obj->pwmHandle[cnt],PWM_TripZoneState_EPWM_Low);
560  PWM_setTripZoneState_TZB(obj->pwmHandle[cnt],PWM_TripZoneState_EPWM_Low);
561 
562  // Clear faults from flip flop
563  GPIO_setLow(obj->gpioHandle,GPIO_Number_9);
564  GPIO_setHigh(obj->gpioHandle,GPIO_Number_9);
565  }
566 
567  return;
568 } // end of HAL_setupFaults() function
569 
570 
571 HAL_Handle HAL_init(void *pMemory,const size_t numBytes)
572 {
573  uint_least8_t cnt;
574  HAL_Handle handle;
575  HAL_Obj *obj;
576 
577 
578  if(numBytes < sizeof(HAL_Obj))
579  return((HAL_Handle)NULL);
580 
581 
582  // assign the handle
583  handle = (HAL_Handle)pMemory;
584 
585 
586  // assign the object
587  obj = (HAL_Obj *)handle;
588 
589 
590  // initialize the watchdog driver
591  obj->wdogHandle = WDOG_init((void *)WDOG_BASE_ADDR,sizeof(WDOG_Obj));
592 
593 
594  // disable watchdog
595  HAL_disableWdog(handle);
596 
597 
598  // initialize the ADC
599  obj->adcHandle = ADC_init((void *)ADC_BASE_ADDR,sizeof(ADC_Obj));
600 
601 
602  // initialize the clock handle
603  obj->clkHandle = CLK_init((void *)CLK_BASE_ADDR,sizeof(CLK_Obj));
604 
605 
606  // initialize the CPU handle
607  obj->cpuHandle = CPU_init(&cpu,sizeof(cpu));
608 
609 
610  // initialize the FLASH handle
611  obj->flashHandle = FLASH_init((void *)FLASH_BASE_ADDR,sizeof(FLASH_Obj));
612 
613 
614  // initialize the GPIO handle
615  obj->gpioHandle = GPIO_init((void *)GPIO_BASE_ADDR,sizeof(GPIO_Obj));
616 
617 
618  // initialize the current offset estimator handles
619  for(cnt=0;cnt<USER_NUM_CURRENT_SENSORS;cnt++)
620  {
621  obj->offsetHandle_I[cnt] = OFFSET_init(&obj->offset_I[cnt],sizeof(obj->offset_I[cnt]));
622  }
623 
624 
625  // initialize the voltage offset estimator handles
626  for(cnt=0;cnt<USER_NUM_VOLTAGE_SENSORS;cnt++)
627  {
628  obj->offsetHandle_V[cnt] = OFFSET_init(&obj->offset_V[cnt],sizeof(obj->offset_V[cnt]));
629  }
630 
631 
632  // initialize the oscillator handle
633  obj->oscHandle = OSC_init((void *)OSC_BASE_ADDR,sizeof(OSC_Obj));
634 
635 
636  // initialize the PIE handle
637  obj->pieHandle = PIE_init((void *)PIE_BASE_ADDR,sizeof(PIE_Obj));
638 
639 
640  // initialize the PLL handle
641  obj->pllHandle = PLL_init((void *)PLL_BASE_ADDR,sizeof(PLL_Obj));
642 
643 
644  // initialize PWM handles
645  obj->pwmHandle[0] = PWM_init((void *)PWM_ePWM1_BASE_ADDR,sizeof(PWM_Obj));
646  obj->pwmHandle[1] = PWM_init((void *)PWM_ePWM2_BASE_ADDR,sizeof(PWM_Obj));
647  obj->pwmHandle[2] = PWM_init((void *)PWM_ePWM3_BASE_ADDR,sizeof(PWM_Obj));
648 
649 
650  // initialize PWM DAC handles
651  obj->pwmDacHandle[0] = PWMDAC_init((void *)PWM_ePWM6_BASE_ADDR,sizeof(PWM_Obj));
652  obj->pwmDacHandle[1] = PWMDAC_init((void *)PWM_ePWM5_BASE_ADDR,sizeof(PWM_Obj));
653  obj->pwmDacHandle[2] = PWMDAC_init((void *)PWM_ePWM4_BASE_ADDR,sizeof(PWM_Obj));
654 
655 
656  // initialize power handle
657  obj->pwrHandle = PWR_init((void *)PWR_BASE_ADDR,sizeof(PWR_Obj));
658 
659 
660  // initialize timer handles
661  obj->timerHandle[0] = TIMER_init((void *)TIMER0_BASE_ADDR,sizeof(TIMER_Obj));
662  obj->timerHandle[1] = TIMER_init((void *)TIMER1_BASE_ADDR,sizeof(TIMER_Obj));
663  obj->timerHandle[2] = TIMER_init((void *)TIMER2_BASE_ADDR,sizeof(TIMER_Obj));
664 
665 #ifdef QEP
666  // initialize QEP driver
667  obj->qepHandle[0] = QEP_init((void*)QEP1_BASE_ADDR,sizeof(QEP_Obj));
668 #endif
669 
670  return(handle);
671 } // end of HAL_init() function
672 
673 
674 void HAL_setParams(HAL_Handle handle,const USER_Params *pUserParams)
675 {
676  uint_least8_t cnt;
677  HAL_Obj *obj = (HAL_Obj *)handle;
678  _iq beta_lp_pu = _IQ(pUserParams->offsetPole_rps/(float_t)pUserParams->ctrlFreq_Hz);
679 
680 
681  HAL_setNumCurrentSensors(handle,pUserParams->numCurrentSensors);
682  HAL_setNumVoltageSensors(handle,pUserParams->numVoltageSensors);
683 
684 
685  for(cnt=0;cnt<HAL_getNumCurrentSensors(handle);cnt++)
686  {
687  HAL_setOffsetBeta_lp_pu(handle,HAL_SensorType_Current,cnt,beta_lp_pu);
690  }
691 
692 
693  for(cnt=0;cnt<HAL_getNumVoltageSensors(handle);cnt++)
694  {
695  HAL_setOffsetBeta_lp_pu(handle,HAL_SensorType_Voltage,cnt,beta_lp_pu);
698  }
699 
700 
701  // disable global interrupts
702  CPU_disableGlobalInts(obj->cpuHandle);
703 
704 
705  // disable cpu interrupts
706  CPU_disableInts(obj->cpuHandle);
707 
708 
709  // clear cpu interrupt flags
710  CPU_clearIntFlags(obj->cpuHandle);
711 
712 
713  // setup the clocks
714  HAL_setupClks(handle);
715 
716 
717  // Setup the PLL
718  HAL_setupPll(handle,PLL_ClkFreq_90_MHz);
719 
720 
721  // setup the PIE
722  HAL_setupPie(handle);
723 
724 
725  // run the device calibration
726  HAL_cal(handle);
727 
728 
729  // setup the peripheral clocks
730  HAL_setupPeripheralClks(handle);
731 
732 
733  // setup the GPIOs
734  HAL_setupGpios(handle);
735 
736 
737  // setup the flash
738  HAL_setupFlash(handle);
739 
740 
741  // setup the ADCs
742  HAL_setupAdcs(handle);
743 
744 
745  // setup the PWMs
746  HAL_setupPwms(handle,
747  (float_t)pUserParams->systemFreq_MHz,
748  pUserParams->pwmPeriod_usec,
749  USER_NUM_PWM_TICKS_PER_ISR_TICK);
750 
751 #ifdef QEP
752  // setup the QEP
753  HAL_setupQEP(handle,HAL_Qep_QEP1);
754 #endif
755 
756  // setup the PWM DACs
757  HAL_setupPwmDacs(handle);
758 
759 
760  // setup the timers
761  HAL_setupTimers(handle,
762  (float_t)pUserParams->systemFreq_MHz);
763 
764 
765  // set the default current bias
766  {
767  uint_least8_t cnt;
768  _iq bias = _IQ12mpy(ADC_dataBias,_IQ(pUserParams->current_sf));
769 
770  for(cnt=0;cnt<HAL_getNumCurrentSensors(handle);cnt++)
771  {
772  HAL_setBias(handle,HAL_SensorType_Current,cnt,bias);
773  }
774  }
775 
776 
777  // set the current scale factor
778  {
779  _iq current_sf = _IQ(pUserParams->current_sf);
780 
781  HAL_setCurrentScaleFactor(handle,current_sf);
782  }
783 
784 
785  // set the default voltage bias
786  {
787  uint_least8_t cnt;
788  _iq bias = _IQ(0.0);
789 
790  for(cnt=0;cnt<HAL_getNumVoltageSensors(handle);cnt++)
791  {
792  HAL_setBias(handle,HAL_SensorType_Voltage,cnt,bias);
793  }
794  }
795 
796 
797  // set the voltage scale factor
798  {
799  _iq voltage_sf = _IQ(pUserParams->voltage_sf);
800 
801  HAL_setVoltageScaleFactor(handle,voltage_sf);
802  }
803 
804  return;
805 } // end of HAL_setParams() function
806 
807 
809 {
810  HAL_Obj *obj = (HAL_Obj *)handle;
811 
812 
813  // disable the ADCs
814  ADC_disable(obj->adcHandle);
815 
816 
817  // power up the bandgap circuit
818  ADC_enableBandGap(obj->adcHandle);
819 
820 
821  // set the ADC voltage reference source to internal
822  ADC_setVoltRefSrc(obj->adcHandle,ADC_VoltageRefSrc_Int);
823 
824 
825  // enable the ADC reference buffers
826  ADC_enableRefBuffers(obj->adcHandle);
827 
828 
829  // Set main clock scaling factor (max45MHz clock for the ADC module)
830  ADC_setDivideSelect(obj->adcHandle,ADC_DivideSelect_ClkIn_by_2);
831 
832 
833  // power up the ADCs
834  ADC_powerUp(obj->adcHandle);
835 
836 
837  // enable the ADCs
838  ADC_enable(obj->adcHandle);
839 
840 
841  // set the ADC interrupt pulse generation to prior
842  ADC_setIntPulseGenMode(obj->adcHandle,ADC_IntPulseGenMode_Prior);
843 
844 
845  // set the temperature sensor source to external
846  ADC_setTempSensorSrc(obj->adcHandle,ADC_TempSensorSrc_Ext);
847 
848 
849  // configure the interrupt sources
850  ADC_disableInt(obj->adcHandle,ADC_IntNumber_1);
851  ADC_setIntMode(obj->adcHandle,ADC_IntNumber_1,ADC_IntMode_ClearFlag);
852  ADC_setIntSrc(obj->adcHandle,ADC_IntNumber_1,ADC_IntSrc_EOC7);
853 
854 
855  //configure the SOCs for hvkit_rev1p1
856  // EXT IA-FB
857  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_0,ADC_SocChanNumber_A1);
858  ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_0,ADC_SocTrigSrc_EPWM1_ADCSOCA);
859  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_0,ADC_SocSampleDelay_9_cycles);
860 
861  // EXT IA-FB
862  // Duplicate conversion due to ADC Initial Conversion bug (SPRZ342)
863  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_1,ADC_SocChanNumber_A1);
864  ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_1,ADC_SocTrigSrc_EPWM1_ADCSOCA);
865  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_1,ADC_SocSampleDelay_9_cycles);
866 
867  // EXT IB-FB
868  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_2,ADC_SocChanNumber_B1);
869  ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_2,ADC_SocTrigSrc_EPWM1_ADCSOCA);
870  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_2,ADC_SocSampleDelay_9_cycles);
871 
872  // EXT IC-FB
873  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_3,ADC_SocChanNumber_A3);
874  ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_3,ADC_SocTrigSrc_EPWM1_ADCSOCA);
875  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_3,ADC_SocSampleDelay_9_cycles);
876 
877  // ADC-Vhb1
878  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_4,ADC_SocChanNumber_B7);
879  ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_4,ADC_SocTrigSrc_EPWM1_ADCSOCA);
880  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_4,ADC_SocSampleDelay_9_cycles);
881 
882  // ADC-Vhb2
883  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_5,ADC_SocChanNumber_B6);
884  ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_5,ADC_SocTrigSrc_EPWM1_ADCSOCA);
885  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_5,ADC_SocSampleDelay_9_cycles);
886 
887  // ADC-Vhb3
888  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_6,ADC_SocChanNumber_B4);
889  ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_6,ADC_SocTrigSrc_EPWM1_ADCSOCA);
890  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_6,ADC_SocSampleDelay_9_cycles);
891 
892  // VDCBUS
893  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_7,ADC_SocChanNumber_A7);
894  ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_7,ADC_SocTrigSrc_EPWM1_ADCSOCA);
895  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_7,ADC_SocSampleDelay_9_cycles);
896 
897  return;
898 } // end of HAL_setupAdcs() function
899 
900 
902 {
903  HAL_Obj *obj = (HAL_Obj *)handle;
904 
905 
906  // enable internal oscillator 1
907  CLK_enableOsc1(obj->clkHandle);
908 
909  // set the oscillator source
910  CLK_setOscSrc(obj->clkHandle,CLK_OscSrc_Internal);
911 
912  // disable the external clock in
913  CLK_disableClkIn(obj->clkHandle);
914 
915  // disable the crystal oscillator
916  CLK_disableCrystalOsc(obj->clkHandle);
917 
918  // disable oscillator 2
919  CLK_disableOsc2(obj->clkHandle);
920 
921  // set the low speed clock prescaler
922  CLK_setLowSpdPreScaler(obj->clkHandle,CLK_LowSpdPreScaler_SysClkOut_by_1);
923 
924  // set the clock out prescaler
925  CLK_setClkOutPreScaler(obj->clkHandle,CLK_ClkOutPreScaler_SysClkOut_by_1);
926 
927  return;
928 } // end of HAL_setupClks() function
929 
930 
932 {
933  HAL_Obj *obj = (HAL_Obj *)handle;
934 
935 
936  FLASH_enablePipelineMode(obj->flashHandle);
937 
938  FLASH_setNumPagedReadWaitStates(obj->flashHandle,FLASH_NumPagedWaitStates_3);
939 
940  FLASH_setNumRandomReadWaitStates(obj->flashHandle,FLASH_NumRandomWaitStates_3);
941 
942  FLASH_setOtpWaitStates(obj->flashHandle,FLASH_NumOtpWaitStates_5);
943 
944  FLASH_setStandbyWaitCount(obj->flashHandle,FLASH_STANDBY_WAIT_COUNT_DEFAULT);
945 
946  FLASH_setActiveWaitCount(obj->flashHandle,FLASH_ACTIVE_WAIT_COUNT_DEFAULT);
947 
948  return;
949 } // HAL_setupFlash() function
950 
951 
953 {
954  HAL_Obj *obj = (HAL_Obj *)handle;
955 
956 
957  // PWM1
958  GPIO_setMode(obj->gpioHandle,GPIO_Number_0,GPIO_0_Mode_EPWM1A);
959 
960  // PWM2
961  GPIO_setMode(obj->gpioHandle,GPIO_Number_1,GPIO_1_Mode_EPWM1B);
962 
963  // PWM3
964  GPIO_setMode(obj->gpioHandle,GPIO_Number_2,GPIO_2_Mode_EPWM2A);
965 
966  // PWM4
967  GPIO_setMode(obj->gpioHandle,GPIO_Number_3,GPIO_3_Mode_EPWM2B);
968 
969  // PWM5
970  GPIO_setMode(obj->gpioHandle,GPIO_Number_4,GPIO_4_Mode_EPWM3A);
971 
972  // PWM6
973  GPIO_setMode(obj->gpioHandle,GPIO_Number_5,GPIO_5_Mode_EPWM3B);
974 
975  // PWM-DAC4
976  GPIO_setMode(obj->gpioHandle,GPIO_Number_6,GPIO_6_Mode_EPWM4A);
977 
978  // Input
979  GPIO_setMode(obj->gpioHandle,GPIO_Number_7,GPIO_7_Mode_GeneralPurpose);
980 
981  // PWM-DAC3
982  GPIO_setMode(obj->gpioHandle,GPIO_Number_8,GPIO_8_Mode_EPWM5A);
983 
984  // CLR-FAULT
985  GPIO_setMode(obj->gpioHandle,GPIO_Number_9,GPIO_9_Mode_GeneralPurpose);
986  GPIO_setHigh(obj->gpioHandle,GPIO_Number_9);
987  GPIO_setDirection(obj->gpioHandle,GPIO_Number_9,GPIO_Direction_Output);
988 
989  // PWM-DAC1
990  GPIO_setMode(obj->gpioHandle,GPIO_Number_10,GPIO_10_Mode_EPWM6A);
991 
992  // PWM-DAC2
993  GPIO_setMode(obj->gpioHandle,GPIO_Number_11,GPIO_11_Mode_EPWM6B);
994 
995  // TZ-1
996  GPIO_setMode(obj->gpioHandle,GPIO_Number_12,GPIO_12_Mode_TZ1_NOT);
997 
998  // HALL-2
999  GPIO_setMode(obj->gpioHandle,GPIO_Number_13,GPIO_13_Mode_GeneralPurpose);
1000 
1001  // HALL-3
1002  GPIO_setMode(obj->gpioHandle,GPIO_Number_14,GPIO_14_Mode_GeneralPurpose);
1003 
1004  // LED2
1005  GPIO_setMode(obj->gpioHandle,GPIO_Number_15,GPIO_15_Mode_GeneralPurpose);
1006 
1007  // Set Qualification Period for GPIO16-23, 22*2*(1/90MHz) = 0.48us
1008  GPIO_setQualificationPeriod(obj->gpioHandle,GPIO_Number_16,22);
1009 
1010  // SPI-SIMO
1011  GPIO_setMode(obj->gpioHandle,GPIO_Number_16,GPIO_16_Mode_GeneralPurpose);
1012 
1013  // SPI-SOMI
1014  GPIO_setMode(obj->gpioHandle,GPIO_Number_17,GPIO_17_Mode_GeneralPurpose);
1015 
1016  // SPI-CLK
1017  GPIO_setMode(obj->gpioHandle,GPIO_Number_18,GPIO_18_Mode_GeneralPurpose);
1018 
1019  // SPI-STE
1020  GPIO_setMode(obj->gpioHandle,GPIO_Number_19,GPIO_19_Mode_GeneralPurpose);
1021 
1022 #ifdef QEP
1023  // EQEPA
1024  GPIO_setMode(obj->gpioHandle,GPIO_Number_20,GPIO_20_Mode_EQEP1A);
1025  GPIO_setQualification(obj->gpioHandle,GPIO_Number_20,GPIO_Qual_Sample_3);
1026 
1027  // EQEPB
1028  GPIO_setMode(obj->gpioHandle,GPIO_Number_21,GPIO_21_Mode_EQEP1B);
1029  GPIO_setQualification(obj->gpioHandle,GPIO_Number_21,GPIO_Qual_Sample_3);
1030 
1031  // STATUS
1032  GPIO_setMode(obj->gpioHandle,GPIO_Number_22,GPIO_22_Mode_GeneralPurpose);
1033 
1034  // EQEP1I
1035  GPIO_setMode(obj->gpioHandle,GPIO_Number_23,GPIO_23_Mode_EQEP1I);
1036  GPIO_setQualification(obj->gpioHandle,GPIO_Number_23,GPIO_Qual_Sample_3);
1037 #else
1038  // EQEPA
1039  GPIO_setMode(obj->gpioHandle,GPIO_Number_20,GPIO_20_Mode_GeneralPurpose);
1040 
1041  // EQEPB
1042  GPIO_setMode(obj->gpioHandle,GPIO_Number_21,GPIO_21_Mode_GeneralPurpose);
1043 
1044  // STATUS
1045  GPIO_setMode(obj->gpioHandle,GPIO_Number_22,GPIO_22_Mode_GeneralPurpose);
1046 
1047  // EQEP1I
1048  GPIO_setMode(obj->gpioHandle,GPIO_Number_23,GPIO_23_Mode_GeneralPurpose);
1049 #endif
1050 
1051  // SPI SIMO B
1052  GPIO_setMode(obj->gpioHandle,GPIO_Number_24,GPIO_24_Mode_GeneralPurpose);
1053 
1054  // SPI SOMI B
1055  GPIO_setMode(obj->gpioHandle,GPIO_Number_25,GPIO_25_Mode_GeneralPurpose);
1056 
1057  // SPI CLK B
1058  GPIO_setMode(obj->gpioHandle,GPIO_Number_26,GPIO_26_Mode_GeneralPurpose);
1059 
1060  // SPI CSn B
1061  GPIO_setMode(obj->gpioHandle,GPIO_Number_27,GPIO_27_Mode_GeneralPurpose);
1062 
1063  // No Connection
1064  GPIO_setMode(obj->gpioHandle,GPIO_Number_28,GPIO_28_Mode_GeneralPurpose);
1065 
1066  // No Connection
1067  GPIO_setMode(obj->gpioHandle,GPIO_Number_29,GPIO_29_Mode_GeneralPurpose);
1068 
1069  // No Connection
1070  GPIO_setMode(obj->gpioHandle,GPIO_Number_30,GPIO_30_Mode_GeneralPurpose);
1071 
1072  // ControlCARD LED2
1073  GPIO_setMode(obj->gpioHandle,GPIO_Number_31,GPIO_31_Mode_GeneralPurpose);
1074  GPIO_setLow(obj->gpioHandle,GPIO_Number_31);
1075  GPIO_setDirection(obj->gpioHandle,GPIO_Number_31,GPIO_Direction_Output);
1076 
1077  // No Connection
1078  GPIO_setMode(obj->gpioHandle,GPIO_Number_32,GPIO_32_Mode_ADCSOCAO_NOT);
1079 
1080  // No Connection
1081  GPIO_setMode(obj->gpioHandle,GPIO_Number_33,GPIO_33_Mode_GeneralPurpose);
1082 
1083  // ControlCARD LED3
1084  GPIO_setMode(obj->gpioHandle,GPIO_Number_34,GPIO_34_Mode_GeneralPurpose);
1085  GPIO_setLow(obj->gpioHandle,GPIO_Number_34);
1086  GPIO_setDirection(obj->gpioHandle,GPIO_Number_34,GPIO_Direction_Output);
1087 
1088  // JTAG
1089  GPIO_setMode(obj->gpioHandle,GPIO_Number_35,GPIO_35_Mode_JTAG_TDI);
1090  GPIO_setMode(obj->gpioHandle,GPIO_Number_36,GPIO_36_Mode_JTAG_TMS);
1091  GPIO_setMode(obj->gpioHandle,GPIO_Number_37,GPIO_37_Mode_JTAG_TDO);
1092  GPIO_setMode(obj->gpioHandle,GPIO_Number_38,GPIO_38_Mode_JTAG_TCK);
1093 
1094  // No Connection
1095  GPIO_setMode(obj->gpioHandle,GPIO_Number_39,GPIO_39_Mode_GeneralPurpose);
1096 
1097  // CAP1
1098  GPIO_setMode(obj->gpioHandle,GPIO_Number_40,GPIO_40_Mode_GeneralPurpose);
1099 
1100  // CAP2
1101  GPIO_setMode(obj->gpioHandle,GPIO_Number_41,GPIO_41_Mode_GeneralPurpose);
1102 
1103  // CAP3
1104  GPIO_setMode(obj->gpioHandle,GPIO_Number_42,GPIO_42_Mode_GeneralPurpose);
1105 
1106  // DC_CAL
1107  GPIO_setMode(obj->gpioHandle,GPIO_Number_43,GPIO_43_Mode_GeneralPurpose);
1108 
1109  // No Connection
1110  GPIO_setMode(obj->gpioHandle,GPIO_Number_44,GPIO_44_Mode_GeneralPurpose);
1111 
1112  // No Connection
1113  GPIO_setMode(obj->gpioHandle,GPIO_Number_50,GPIO_50_Mode_GeneralPurpose);
1114 
1115  // No Connection
1116  GPIO_setMode(obj->gpioHandle,GPIO_Number_51,GPIO_51_Mode_GeneralPurpose);
1117 
1118  // No Connection
1119  GPIO_setMode(obj->gpioHandle,GPIO_Number_52,GPIO_52_Mode_GeneralPurpose);
1120 
1121  // No Connection
1122  GPIO_setMode(obj->gpioHandle,GPIO_Number_53,GPIO_53_Mode_GeneralPurpose);
1123 
1124  // No Connection
1125  GPIO_setMode(obj->gpioHandle,GPIO_Number_54,GPIO_54_Mode_GeneralPurpose);
1126 
1127  // No Connection
1128  GPIO_setMode(obj->gpioHandle,GPIO_Number_55,GPIO_55_Mode_GeneralPurpose);
1129 
1130  // No Connection
1131  GPIO_setMode(obj->gpioHandle,GPIO_Number_56,GPIO_56_Mode_GeneralPurpose);
1132 
1133  // No Connection
1134  GPIO_setMode(obj->gpioHandle,GPIO_Number_57,GPIO_57_Mode_GeneralPurpose);
1135 
1136  // No Connection
1137  GPIO_setMode(obj->gpioHandle,GPIO_Number_58,GPIO_58_Mode_GeneralPurpose);
1138 
1139  return;
1140 } // end of HAL_setupGpios() function
1141 
1142 
1144 {
1145  HAL_Obj *obj = (HAL_Obj *)handle;
1146 
1147 
1148  PIE_disable(obj->pieHandle);
1149 
1150  PIE_disableAllInts(obj->pieHandle);
1151 
1152  PIE_clearAllInts(obj->pieHandle);
1153 
1154  PIE_clearAllFlags(obj->pieHandle);
1155 
1156  PIE_setDefaultIntVectorTable(obj->pieHandle);
1157 
1158  PIE_enable(obj->pieHandle);
1159 
1160  return;
1161 } // end of HAL_setupPie() function
1162 
1163 
1165 {
1166  HAL_Obj *obj = (HAL_Obj *)handle;
1167 
1168 
1169  CLK_enableAdcClock(obj->clkHandle);
1170 
1171  CLK_enableCompClock(obj->clkHandle,CLK_CompNumber_1);
1172  CLK_enableCompClock(obj->clkHandle,CLK_CompNumber_2);
1173  CLK_enableCompClock(obj->clkHandle,CLK_CompNumber_3);
1174 
1175  CLK_enableEcap1Clock(obj->clkHandle);
1176 
1177  CLK_disableEcanaClock(obj->clkHandle);
1178 
1179 #ifdef QEP
1180  CLK_enableEqep1Clock(obj->clkHandle);
1181  CLK_disableEqep2Clock(obj->clkHandle);
1182 #endif
1183 
1184  CLK_enablePwmClock(obj->clkHandle,PWM_Number_1);
1185  CLK_enablePwmClock(obj->clkHandle,PWM_Number_2);
1186  CLK_enablePwmClock(obj->clkHandle,PWM_Number_3);
1187  CLK_enablePwmClock(obj->clkHandle,PWM_Number_4);
1188  CLK_enablePwmClock(obj->clkHandle,PWM_Number_5);
1189  CLK_enablePwmClock(obj->clkHandle,PWM_Number_6);
1190  CLK_enablePwmClock(obj->clkHandle,PWM_Number_7);
1191 
1192  CLK_disableHrPwmClock(obj->clkHandle);
1193 
1194  CLK_disableI2cClock(obj->clkHandle);
1195 
1196  CLK_disableLinAClock(obj->clkHandle);
1197 
1198  CLK_disableClaClock(obj->clkHandle);
1199 
1200  CLK_enableSciaClock(obj->clkHandle);
1201 
1202  CLK_disableSpiaClock(obj->clkHandle);
1203  CLK_disableSpibClock(obj->clkHandle);
1204 
1205  CLK_enableTbClockSync(obj->clkHandle);
1206 
1207  return;
1208 } // end of HAL_setupPeripheralClks() function
1209 
1210 
1211 void HAL_setupPll(HAL_Handle handle,const PLL_ClkFreq_e clkFreq)
1212 {
1213  HAL_Obj *obj = (HAL_Obj *)handle;
1214 
1215 
1216  // make sure PLL is not running in limp mode
1217  if(PLL_getClkStatus(obj->pllHandle) != PLL_ClkStatus_Normal)
1218  {
1219  // reset the clock detect
1220  PLL_resetClkDetect(obj->pllHandle);
1221 
1222  // ???????
1223  asm(" ESTOP0");
1224  }
1225 
1226 
1227  // Divide Select must be ClkIn/4 before the clock rate can be changed
1228  if(PLL_getDivideSelect(obj->pllHandle) != PLL_DivideSelect_ClkIn_by_4)
1229  {
1230  PLL_setDivideSelect(obj->pllHandle,PLL_DivideSelect_ClkIn_by_4);
1231  }
1232 
1233 
1234  if(PLL_getClkFreq(obj->pllHandle) != clkFreq)
1235  {
1236  // disable the clock detect
1237  PLL_disableClkDetect(obj->pllHandle);
1238 
1239  // set the clock rate
1240  PLL_setClkFreq(obj->pllHandle,clkFreq);
1241  }
1242 
1243 
1244  // wait until locked
1245  while(PLL_getLockStatus(obj->pllHandle) != PLL_LockStatus_Done) {}
1246 
1247 
1248  // enable the clock detect
1249  PLL_enableClkDetect(obj->pllHandle);
1250 
1251 
1252  // set divide select to ClkIn/2 to get desired clock rate
1253  // NOTE: clock must be locked before setting this register
1254  PLL_setDivideSelect(obj->pllHandle,PLL_DivideSelect_ClkIn_by_2);
1255 
1256  return;
1257 } // end of HAL_setupPll() function
1258 
1259 
1261  const float_t systemFreq_MHz,
1262  const float_t pwmPeriod_usec,
1263  const uint_least16_t numPwmTicksPerIsrTick)
1264 {
1265  HAL_Obj *obj = (HAL_Obj *)handle;
1266  uint16_t halfPeriod_cycles = (uint16_t)(systemFreq_MHz*pwmPeriod_usec) >> 1;
1267  uint_least8_t cnt;
1268 
1269 
1270  // turns off the outputs of the EPWM peripherals which will put the power switches
1271  // into a high impedance state.
1272  PWM_setOneShotTrip(obj->pwmHandle[PWM_Number_1]);
1273  PWM_setOneShotTrip(obj->pwmHandle[PWM_Number_2]);
1274  PWM_setOneShotTrip(obj->pwmHandle[PWM_Number_3]);
1275 
1276  for(cnt=0;cnt<3;cnt++)
1277  {
1278  // setup the Time-Base Control Register (TBCTL)
1279  PWM_setCounterMode(obj->pwmHandle[cnt],PWM_CounterMode_UpDown);
1280  PWM_disableCounterLoad(obj->pwmHandle[cnt]);
1281  PWM_setPeriodLoad(obj->pwmHandle[cnt],PWM_PeriodLoad_Immediate);
1282  PWM_setSyncMode(obj->pwmHandle[cnt],PWM_SyncMode_EPWMxSYNC);
1283  PWM_setHighSpeedClkDiv(obj->pwmHandle[cnt],PWM_HspClkDiv_by_1);
1284  PWM_setClkDiv(obj->pwmHandle[cnt],PWM_ClkDiv_by_1);
1285  PWM_setPhaseDir(obj->pwmHandle[cnt],PWM_PhaseDir_CountUp);
1286  PWM_setRunMode(obj->pwmHandle[cnt],PWM_RunMode_FreeRun);
1287 
1288  // setup the Timer-Based Phase Register (TBPHS)
1289  PWM_setPhase(obj->pwmHandle[cnt],0);
1290 
1291  // setup the Time-Base Counter Register (TBCTR)
1292  PWM_setCount(obj->pwmHandle[cnt],0);
1293 
1294  // setup the Time-Base Period Register (TBPRD)
1295  // set to zero initially
1296  PWM_setPeriod(obj->pwmHandle[cnt],0);
1297 
1298  // setup the Counter-Compare Control Register (CMPCTL)
1299  PWM_setLoadMode_CmpA(obj->pwmHandle[cnt],PWM_LoadMode_Zero);
1300  PWM_setLoadMode_CmpB(obj->pwmHandle[cnt],PWM_LoadMode_Zero);
1301  PWM_setShadowMode_CmpA(obj->pwmHandle[cnt],PWM_ShadowMode_Shadow);
1302  PWM_setShadowMode_CmpB(obj->pwmHandle[cnt],PWM_ShadowMode_Immediate);
1303 
1304  // setup the Action-Qualifier Output A Register (AQCTLA)
1305  PWM_setActionQual_CntUp_CmpA_PwmA(obj->pwmHandle[cnt],PWM_ActionQual_Set);
1306  PWM_setActionQual_CntDown_CmpA_PwmA(obj->pwmHandle[cnt],PWM_ActionQual_Clear);
1307 
1308  // setup the Dead-Band Generator Control Register (DBCTL)
1309  PWM_setDeadBandOutputMode(obj->pwmHandle[cnt],PWM_DeadBandOutputMode_EPWMxA_Rising_EPWMxB_Falling);
1310  PWM_setDeadBandPolarity(obj->pwmHandle[cnt],PWM_DeadBandPolarity_EPWMxB_Inverted);
1311 
1312  // setup the Dead-Band Rising Edge Delay Register (DBRED)
1313  PWM_setDeadBandRisingEdgeDelay(obj->pwmHandle[cnt],HAL_PWM_DBRED_CNT);
1314 
1315  // setup the Dead-Band Falling Edge Delay Register (DBFED)
1316  PWM_setDeadBandFallingEdgeDelay(obj->pwmHandle[cnt],HAL_PWM_DBFED_CNT);
1317  // setup the PWM-Chopper Control Register (PCCTL)
1318  PWM_disableChopping(obj->pwmHandle[cnt]);
1319 
1320  // setup the Trip Zone Select Register (TZSEL)
1321  PWM_disableTripZones(obj->pwmHandle[cnt]);
1322  }
1323 
1324 
1325  // setup the Event Trigger Selection Register (ETSEL)
1326  PWM_disableInt(obj->pwmHandle[PWM_Number_1]);
1327  PWM_setSocAPulseSrc(obj->pwmHandle[PWM_Number_1],PWM_SocPulseSrc_CounterEqualZero);
1328  PWM_enableSocAPulse(obj->pwmHandle[PWM_Number_1]);
1329 
1330 
1331  // setup the Event Trigger Prescale Register (ETPS)
1332  if(numPwmTicksPerIsrTick == 3)
1333  {
1334  PWM_setIntPeriod(obj->pwmHandle[PWM_Number_1],PWM_IntPeriod_ThirdEvent);
1335  PWM_setSocAPeriod(obj->pwmHandle[PWM_Number_1],PWM_SocPeriod_ThirdEvent);
1336  }
1337  else if(numPwmTicksPerIsrTick == 2)
1338  {
1339  PWM_setIntPeriod(obj->pwmHandle[PWM_Number_1],PWM_IntPeriod_SecondEvent);
1340  PWM_setSocAPeriod(obj->pwmHandle[PWM_Number_1],PWM_SocPeriod_SecondEvent);
1341  }
1342  else
1343  {
1344  PWM_setIntPeriod(obj->pwmHandle[PWM_Number_1],PWM_IntPeriod_FirstEvent);
1345  PWM_setSocAPeriod(obj->pwmHandle[PWM_Number_1],PWM_SocPeriod_FirstEvent);
1346  }
1347 
1348 
1349  // setup the Event Trigger Clear Register (ETCLR)
1350  PWM_clearIntFlag(obj->pwmHandle[PWM_Number_1]);
1351  PWM_clearSocAFlag(obj->pwmHandle[PWM_Number_1]);
1352 
1353  // first step to synchronize the pwms
1354  CLK_disableTbClockSync(obj->clkHandle);
1355 
1356  // since the PWM is configured as an up/down counter, the period register is set to one-half
1357  // of the desired PWM period
1358  PWM_setPeriod(obj->pwmHandle[PWM_Number_1],halfPeriod_cycles);
1359  PWM_setPeriod(obj->pwmHandle[PWM_Number_2],halfPeriod_cycles);
1360  PWM_setPeriod(obj->pwmHandle[PWM_Number_3],halfPeriod_cycles);
1361 
1362  // last step to synchronize the pwms
1363  CLK_enableTbClockSync(obj->clkHandle);
1364 
1365  return;
1366 } // end of HAL_setupPwms() function
1367 
1368 #ifdef QEP
1369 void HAL_setupQEP(HAL_Handle handle,HAL_QepSelect_e qep)
1370 {
1371  HAL_Obj *obj = (HAL_Obj *)handle;
1372 
1373 
1374  // hold the counter in reset
1375  QEP_reset_counter(obj->qepHandle[qep]);
1376 
1377  // set the QPOSINIT register
1378  QEP_set_posn_init_count(obj->qepHandle[qep], 0);
1379 
1380  // disable all interrupts
1381  QEP_disable_all_interrupts(obj->qepHandle[qep]);
1382 
1383  // clear the interrupt flags
1384  QEP_clear_all_interrupt_flags(obj->qepHandle[qep]);
1385 
1386  // clear the position counter
1387  QEP_clear_posn_counter(obj->qepHandle[qep]);
1388 
1389  // setup the max position
1390  QEP_set_max_posn_count(obj->qepHandle[qep], (4*USER_MOTOR_ENCODER_LINES)-1);
1391 
1392  // setup the QDECCTL register
1393  QEP_set_QEP_source(obj->qepHandle[qep], QEP_Qsrc_Quad_Count_Mode);
1394  QEP_disable_sync_out(obj->qepHandle[qep]);
1395  QEP_set_swap_quad_inputs(obj->qepHandle[qep], QEP_Swap_Not_Swapped);
1396  QEP_disable_gate_index(obj->qepHandle[qep]);
1397  QEP_set_ext_clock_rate(obj->qepHandle[qep], QEP_Xcr_2x_Res);
1398  QEP_set_A_polarity(obj->qepHandle[qep], QEP_Qap_No_Effect);
1399  QEP_set_B_polarity(obj->qepHandle[qep], QEP_Qbp_No_Effect);
1400  QEP_set_index_polarity(obj->qepHandle[qep], QEP_Qip_No_Effect);
1401 
1402  // setup the QEPCTL register
1403  QEP_set_emu_control(obj->qepHandle[qep], QEPCTL_Freesoft_Unaffected_Halt);
1404  QEP_set_posn_count_reset_mode(obj->qepHandle[qep], QEPCTL_Pcrm_Max_Reset);
1405  QEP_set_strobe_event_init(obj->qepHandle[qep], QEPCTL_Sei_Nothing);
1406  QEP_set_index_event_init(obj->qepHandle[qep], QEPCTL_Iei_Nothing);
1407  QEP_set_index_event_latch(obj->qepHandle[qep], QEPCTL_Iel_Rising_Edge);
1408  QEP_set_soft_init(obj->qepHandle[qep], QEPCTL_Swi_Nothing);
1409  QEP_disable_unit_timer(obj->qepHandle[qep]);
1410  QEP_disable_watchdog(obj->qepHandle[qep]);
1411 
1412  // setup the QPOSCTL register
1413  QEP_disable_posn_compare(obj->qepHandle[qep]);
1414 
1415  // setup the QCAPCTL register
1416  QEP_disable_capture(obj->qepHandle[qep]);
1417 
1418  // renable the position counter
1419  QEP_enable_counter(obj->qepHandle[qep]);
1420 
1421 
1422  return;
1423 }
1424 #endif
1425 
1427 {
1428  HAL_Obj *obj = (HAL_Obj *)handle;
1429  uint16_t halfPeriod_cycles = 512; // 3000->10kHz, 1500->20kHz, 1000-> 30kHz, 500->60kHz
1430  uint_least8_t cnt;
1431 
1432 
1433  for(cnt=0;cnt<3;cnt++)
1434  {
1435  // initialize the Time-Base Control Register (TBCTL)
1436  PWMDAC_setCounterMode(obj->pwmDacHandle[cnt],PWM_CounterMode_UpDown);
1437  PWMDAC_disableCounterLoad(obj->pwmDacHandle[cnt]);
1438  PWMDAC_setPeriodLoad(obj->pwmDacHandle[cnt],PWM_PeriodLoad_Immediate);
1439  PWMDAC_setSyncMode(obj->pwmDacHandle[cnt],PWM_SyncMode_EPWMxSYNC);
1440  PWMDAC_setHighSpeedClkDiv(obj->pwmDacHandle[cnt],PWM_HspClkDiv_by_1);
1441  PWMDAC_setClkDiv(obj->pwmDacHandle[cnt],PWM_ClkDiv_by_1);
1442  PWMDAC_setPhaseDir(obj->pwmDacHandle[cnt],PWM_PhaseDir_CountUp);
1443  PWMDAC_setRunMode(obj->pwmDacHandle[cnt],PWM_RunMode_FreeRun);
1444 
1445  // initialize the Timer-Based Phase Register (TBPHS)
1446  PWMDAC_setPhase(obj->pwmDacHandle[cnt],0);
1447 
1448  // setup the Time-Base Counter Register (TBCTR)
1449  PWMDAC_setCount(obj->pwmDacHandle[cnt],0);
1450 
1451  // Initialize the Time-Base Period Register (TBPRD)
1452  // set to zero initially
1453  PWMDAC_setPeriod(obj->pwmDacHandle[cnt],0);
1454 
1455  // initialize the Counter-Compare Control Register (CMPCTL)
1456  PWMDAC_setLoadMode_CmpA(obj->pwmDacHandle[cnt],PWM_LoadMode_Zero);
1457  PWMDAC_setLoadMode_CmpB(obj->pwmDacHandle[cnt],PWM_LoadMode_Zero);
1458  PWMDAC_setShadowMode_CmpA(obj->pwmDacHandle[cnt],PWM_ShadowMode_Shadow);
1459  PWMDAC_setShadowMode_CmpB(obj->pwmDacHandle[cnt],PWM_ShadowMode_Shadow);
1460 
1461  // Initialize the Action-Qualifier Output A Register (AQCTLA)
1462  PWMDAC_setActionQual_CntUp_CmpA_PwmA(obj->pwmDacHandle[cnt],PWM_ActionQual_Clear);
1463  PWMDAC_setActionQual_CntDown_CmpA_PwmA(obj->pwmDacHandle[cnt],PWM_ActionQual_Set);
1464 
1465  // account for EPWM6B
1466  if(cnt == 0)
1467  {
1468  PWMDAC_setActionQual_CntUp_CmpB_PwmB(obj->pwmDacHandle[cnt],PWM_ActionQual_Clear);
1469  PWMDAC_setActionQual_CntDown_CmpB_PwmB(obj->pwmDacHandle[cnt],PWM_ActionQual_Set);
1470  }
1471 
1472  // Initialize the Dead-Band Control Register (DBCTL)
1473  PWMDAC_disableDeadBand(obj->pwmDacHandle[cnt]);
1474 
1475  // Initialize the PWM-Chopper Control Register (PCCTL)
1476  PWMDAC_disableChopping(obj->pwmDacHandle[cnt]);
1477 
1478  // Initialize the Trip-Zone Control Register (TZSEL)
1479  PWMDAC_disableTripZones(obj->pwmDacHandle[cnt]);
1480 
1481  // Initialize the Trip-Zone Control Register (TZCTL)
1482  PWMDAC_setTripZoneState_TZA(obj->pwmDacHandle[cnt],PWM_TripZoneState_HighImp);
1483  PWMDAC_setTripZoneState_TZB(obj->pwmDacHandle[cnt],PWM_TripZoneState_HighImp);
1484  PWMDAC_setTripZoneState_DCAEVT1(obj->pwmDacHandle[cnt],PWM_TripZoneState_HighImp);
1485  PWMDAC_setTripZoneState_DCAEVT2(obj->pwmDacHandle[cnt],PWM_TripZoneState_HighImp);
1486  PWMDAC_setTripZoneState_DCBEVT1(obj->pwmDacHandle[cnt],PWM_TripZoneState_HighImp);
1487  }
1488 
1489  // since the PWM is configured as an up/down counter, the period register is set to one-half
1490  // of the desired PWM period
1491  PWMDAC_setPeriod(obj->pwmDacHandle[PWMDAC_Number_1],halfPeriod_cycles);
1492  PWMDAC_setPeriod(obj->pwmDacHandle[PWMDAC_Number_2],halfPeriod_cycles);
1493  PWMDAC_setPeriod(obj->pwmDacHandle[PWMDAC_Number_3],halfPeriod_cycles);
1494 
1495  return;
1496 } // end of HAL_setupPwmDacs() function
1497 
1498 
1499 void HAL_setupTimers(HAL_Handle handle,const float_t systemFreq_MHz)
1500 {
1501  HAL_Obj *obj = (HAL_Obj *)handle;
1502  uint32_t timerPeriod_cnts = (uint32_t)(systemFreq_MHz * (float_t)1000000.0) - 1;
1503 
1504  // use timer 0 for frequency diagnostics
1505  TIMER_setDecimationFactor(obj->timerHandle[0],0);
1506  TIMER_setEmulationMode(obj->timerHandle[0],TIMER_EmulationMode_RunFree);
1507  TIMER_setPeriod(obj->timerHandle[0],timerPeriod_cnts);
1508  TIMER_setPreScaler(obj->timerHandle[0],0);
1509 
1510  // use timer 1 for CPU usage diagnostics
1511  TIMER_setDecimationFactor(obj->timerHandle[1],0);
1512  TIMER_setEmulationMode(obj->timerHandle[1],TIMER_EmulationMode_RunFree);
1513  TIMER_setPeriod(obj->timerHandle[1],timerPeriod_cnts);
1514  TIMER_setPreScaler(obj->timerHandle[1],0);
1515 
1516  return;
1517 } // end of HAL_setupTimers() function
1518 
1519 // end of file
static void HAL_setNumVoltageSensors(HAL_Handle handle, const uint_least8_t numVoltageSensors)
Sets the number of voltage sensors.
#define FP_ROUND
Defines the quantity added to Q15 numbers before converting to integer to round the number...
OFFSET_Handle offsetHandle_I[3]
the handles for the current offset estimators
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.
OFFSET_Obj offset_V[3]
the voltage offset objects
void HAL_disableGlobalInts(HAL_Handle handle)
Disables global interrupts.
static void HAL_setCurrentScaleFactor(HAL_Handle handle, const _iq current_sf)
Sets the current scale factor in the hardware abstraction layer.
#define getOsc2CoarseTrim()
Defines the oscillator 2 coarse trim.
#define _IQ(A)
#define getOsc1FineTrimSlope()
The following functions return reference values stored in OTP.
#define HAL_PWM_DBFED_CNT
Defines the PWM deadband falling edge delay count (system clocks)
void HAL_OscTempComp(HAL_Handle handle)
Executes the oscillator 1 and 2 calibration functions.
#define getOsc1FineTrimOffset()
Defines the oscillator 1 fine trim at high temp.
static void HAL_setOffsetValue(HAL_Handle handle, const HAL_SensorType_e sensorType, const uint_least8_t sensorNumber, const _iq value)
Sets the initial offset value for offset estimation.
CLK_Handle clkHandle
the clock handle
static void HAL_setOffsetInitCond(HAL_Handle handle, const HAL_SensorType_e sensorType, const uint_least8_t sensorNumber, const _iq initCond)
Sets the offset initial condition value for offset estimation.
uint_least16_t systemFreq_MHz
Defines the system clock frequency, MHz.
Defines a structure for the user parameters.
uint_least8_t numCurrentSensors
Defines the number of current sensors.
void HAL_AdcCalChanSelect(HAL_Handle handle, const ADC_SocChanNumber_e chanNumber)
Selects the analog channel used for calibration.
HAL_QepSelect_e
Enumeration for the QEP setup.
#define getOsc2FineTrimOffset()
Defines the oscillator 2 fine trim at high temp.
void HAL_setupPeripheralClks(HAL_Handle handle)
Sets up the peripheral clocks.
void HAL_setupTimers(HAL_Handle handle, const float_t systemFreq_MHz)
Sets up the timers.
long _iq
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)
FLASH_Handle flashHandle
the flash handle
void HAL_setupGpios(HAL_Handle handle)
Sets up the GPIO (General Purpose I/O) pins.
static void HAL_setOffsetBeta_lp_pu(HAL_Handle handle, const HAL_SensorType_e sensorType, const uint_least8_t sensorNumber, const _iq beta_lp_pu)
Sets the value used to set the low pass filter pole for offset estimation.
void HAL_setupFlash(HAL_Handle handle)
Sets up the FLASH.
void HAL_enablePwmInt(HAL_Handle handle)
Enables the PWM interrupt.
void HAL_setupClks(HAL_Handle handle)
Sets up the clocks.
#define HAL_PWM_DBRED_CNT
Defines the PWM deadband rising edge delay count (system clocks)
void HAL_setupFaults(HAL_Handle handle)
Configures the fault protection logic.
static void HAL_setVoltageScaleFactor(HAL_Handle handle, const _iq voltage_sf)
Sets the voltage scale factor in the hardware abstraction layer.
#define _IQ12mpy(A, B)
struct _HAL_Obj_ * HAL_Handle
Defines the HAL handle.
void HAL_osc1Comp(HAL_Handle handle, const int16_t sensorSample)
Executes the oscillator 1 calibration based on input sample.
float_t voltage_sf
Defines the voltage scale factor for the system.
void usDelay(const uint_least32_t delay_usec)
Provides a prescribes micro-second delay.
uint_least8_t numVoltageSensors
Defines the number of voltage 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.
float_t offsetPole_rps
Defines the pole location for the voltage and current offset estimation, rad/s.
#define getRefTempOffset()
Defines the ADC reading of temperature sensor at reference temperature for compensation.
static void HAL_setNumCurrentSensors(HAL_Handle handle, const uint_least8_t numCurrentSensors)
Sets the number of current sensors.
float_t pwmPeriod_usec
Defines the Pulse Width Modulation (PWM) period, usec.
#define getOsc1CoarseTrim()
Defines the oscillator 1 coarse trim.
static uint_least8_t HAL_getNumVoltageSensors(HAL_Handle handle)
Gets the number of voltage sensors.
static uint_least8_t HAL_getNumCurrentSensors(HAL_Handle handle)
Gets the number of current sensors.
float_t current_sf
Defines the current scale factor for the system.
WDOG_Handle wdogHandle
the watchdog handle
void HAL_AdcOffsetSelfCal(HAL_Handle handle)
Executes the offset calibration of the ADC.
#define FP_SCALE
Defines used in oscillator calibration functions.
OSC_Handle oscHandle
the oscillator handle
ADC_Handle adcHandle
the ADC handle
HAL_Handle HAL_init(void *pMemory, const size_t numBytes)
Initializes the hardware abstraction layer (HAL) object.
CPU_Handle cpuHandle
the CPU handle
uint_least32_t ctrlFreq_Hz
Defines the controller frequency, Hz.
void HAL_cal(HAL_Handle handle)
Executes calibration routines.
HAL_Obj hal
Defines the HAL object.
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_setBias(HAL_Handle handle, const HAL_SensorType_e sensorType, uint_least8_t sensorNumber, const _iq bias)
Sets the ADC bias value.
uint16_t HAL_getOscTrimValue(int16_t coarse, int16_t fine)
Converts coarse and fine oscillator trim values into a single 16bit word value.
OFFSET_Obj offset_I[3]
the current offset objects
OFFSET_Handle OFFSET_init(void *pMemory, const size_t numBytes)
Initializes the offset.
Definition: 32b/offset.c:70
PLL_Handle pllHandle
the PLL handle
void HAL_setParams(HAL_Handle handle, const USER_Params *pUserParams)
Sets the hardware abstraction layer parameters.
void HAL_setupAdcs(HAL_Handle handle)
Sets up the ADCs (Analog to Digital Converters)
void HAL_disableWdog(HAL_Handle halHandle)
Disables the watch dog.
OFFSET_Handle offsetHandle_V[3]
the handles for the voltage offset estimators
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
#define OSC_POSTRIM
Defines the amount to add to Q16.15 fixed point number to shift from a fine trim range of...
#define getOsc2FineTrimSlope()
Defines the slope used to compensate oscillator 2 (fine trim steps / ADC code). Stored.