MotorWare f2806x Module API Documentation

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

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