MotorWare f2806x Module API Documentation

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

hal_both.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 HAL_Obj hal;
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
100 void HAL_OscTempComp(HAL_Handle handle)
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()
174 + OSC_POSTRIM_OFF + FP_ROUND )/FP_SCALE + getOsc1FineTrimOffset() - OSC_POSTRIM;
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()
201 + OSC_POSTRIM_OFF + FP_ROUND )/FP_SCALE + getOsc2FineTrimOffset() - OSC_POSTRIM;
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
246 void HAL_AdcOffsetSelfCal(HAL_Handle handle)
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
319 uint16_t HAL_AdcCalConversion(HAL_Handle handle)
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
455 void HAL_disableWdog(HAL_Handle halHandle)
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
467 void HAL_disableGlobalInts(HAL_Handle handle)
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
478 void HAL_enableAdcInts(HAL_Handle handle)
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
498 void HAL_enableDebugInt(HAL_Handle handle)
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 #error fix this
509 void HAL_enableDrv(HAL_Handle handle)
510 {
511 HAL_Obj *obj = (HAL_Obj *)handle;
512
513 DRV8301_enable(obj->drv8301Handle);
514
515 return;
516 } // end of HAL_enableDrv() function
517
518
519 void HAL_enableGlobalInts(HAL_Handle handle)
520 {
521 HAL_Obj *obj = (HAL_Obj *)handle;
522
523
524 CPU_enableGlobalInts(obj->cpuHandle);
525
526 return;
527 } // end of HAL_enableGlobalInts() function
528
529
530 void HAL_enablePwmInt(HAL_Handle handle)
531 {
532 HAL_Obj *obj = (HAL_Obj *)handle;
533
534
535 PIE_enablePwmInt(obj->pieHandle,PWM_Number_1);
536
537
538 // enable the interrupt
539 PWM_enableInt(obj->pwmHandle[0]);
540
541
542 // enable the cpu interrupt for EPWM1_INT
543 CPU_enableInt(obj->cpuHandle,CPU_IntNumber_3);
544
545 return;
546 } // end of HAL_enablePwmInt() function
547
548
549 void HAL_enableTimer0Int(HAL_Handle handle)
550 {
551 HAL_Obj *obj = (HAL_Obj *)handle;
552
553
554 PIE_enableTimer0Int(obj->pieHandle);
555
556
557 // enable the interrupt
558 TIMER_enableInt(obj->timerHandle[0]);
559
560
561 // enable the cpu interrupt for TINT0
562 CPU_enableInt(obj->cpuHandle,CPU_IntNumber_1);
563
564 return;
565 } // end of HAL_enablePwmInt() function
566
567
568 void HAL_setupFaults(HAL_Handle handle)
569 {
570 HAL_Obj *obj = (HAL_Obj *)handle;
571 uint_least8_t cnt;
572
573
574 // Configure Trip Mechanism for the Motor control software
575 // -Cycle by cycle trip on CPU halt
576 // -One shot fault trip zone
577 // These trips need to be repeated for EPWM1 ,2 & 3
578 for(cnt=0;cnt<3;cnt++)
579 {
580 PWM_enableTripZoneSrc(obj->pwmHandle[cnt],PWM_TripZoneSrc_CycleByCycle_TZ6_NOT);
581
582 PWM_enableTripZoneSrc(obj->pwmHandle[cnt],PWM_TripZoneSrc_CycleByCycle_TZ3_NOT);
583
584 PWM_enableTripZoneSrc(obj->pwmHandle[cnt],PWM_TripZoneSrc_CycleByCycle_TZ2_NOT);
585
586 // What do we want the OST/CBC events to do?
587 // TZA events can force EPWMxA
588 // TZB events can force EPWMxB
589
590 PWM_setTripZoneState_TZA(obj->pwmHandle[cnt],PWM_TripZoneState_EPWM_Low);
591 PWM_setTripZoneState_TZB(obj->pwmHandle[cnt],PWM_TripZoneState_EPWM_Low);
592 }
593
594 return;
595 } // end of HAL_setupFaults() function
596
597
598 HAL_Handle HAL_init(void *pMemory,const size_t numBytes)
599 {
600 uint_least8_t cnt;
601 HAL_Handle handle;
602 HAL_Obj *obj;
603
604
605 if(numBytes < sizeof(HAL_Obj))
606 return((HAL_Handle)NULL);
607
608
609 // assign the handle
610 handle = (HAL_Handle)pMemory;
611
612
613 // assign the object
614 obj = (HAL_Obj *)handle;
615
616
617 // initialize the watchdog driver
618 obj->wdogHandle = WDOG_init((void *)WDOG_BASE_ADDR,sizeof(WDOG_Obj));
619
620
621 // disable watchdog
622 HAL_disableWdog(handle);
623
624
625 // initialize the ADC
626 obj->adcHandle = ADC_init((void *)ADC_BASE_ADDR,sizeof(ADC_Obj));
627
628
629 // initialize the clock handle
630 obj->clkHandle = CLK_init((void *)CLK_BASE_ADDR,sizeof(CLK_Obj));
631
632
633 // initialize the CPU handle
634 obj->cpuHandle = CPU_init(&cpu,sizeof(cpu));
635
636
637 // initialize the FLASH handle
638 obj->flashHandle = FLASH_init((void *)FLASH_BASE_ADDR,sizeof(FLASH_Obj));
639
640
641 // initialize the GPIO handle
642 obj->gpioHandle = GPIO_init((void *)GPIO_BASE_ADDR,sizeof(GPIO_Obj));
643
644
645 // initialize the current offset estimator handles
646 for(cnt=0;cnt<USER_NUM_CURRENT_SENSORS;cnt++)
647 {
648 obj->offsetHandle_I[cnt] = OFFSET_init(&obj->offset_I[cnt],sizeof(obj->offset_I[cnt]));
649 }
650
651
652 // initialize the voltage offset estimator handles
653 for(cnt=0;cnt<USER_NUM_VOLTAGE_SENSORS;cnt++)
654 {
655 obj->offsetHandle_V[cnt] = OFFSET_init(&obj->offset_V[cnt],sizeof(obj->offset_V[cnt]));
656 }
657
658
659 // initialize the oscillator handle
660 obj->oscHandle = OSC_init((void *)OSC_BASE_ADDR,sizeof(OSC_Obj));
661
662
663 // initialize the PIE handle
664 obj->pieHandle = PIE_init((void *)PIE_BASE_ADDR,sizeof(PIE_Obj));
665
666
667 // initialize the PLL handle
668 obj->pllHandle = PLL_init((void *)PLL_BASE_ADDR,sizeof(PLL_Obj));
669
670
671 // initialize the SPIA handle
672 obj->spiAHandle = SPI_init((void *)SPIA_BASE_ADDR,sizeof(SPI_Obj));
673
674
675 // initialize the SPIB handle
676 obj->spiBHandle = SPI_init((void *)SPIB_BASE_ADDR,sizeof(SPI_Obj));
677
678
679 // initialize PWM handles
680 obj->pwmHandle[0] = PWM_init((void *)PWM_ePWM1_BASE_ADDR,sizeof(PWM_Obj));
681 obj->pwmHandle[1] = PWM_init((void *)PWM_ePWM2_BASE_ADDR,sizeof(PWM_Obj));
682 obj->pwmHandle[2] = PWM_init((void *)PWM_ePWM3_BASE_ADDR,sizeof(PWM_Obj));
683 obj->pwmHandle[3] = PWM_init((void *)PWM_ePWM4_BASE_ADDR,sizeof(PWM_Obj));
684 obj->pwmHandle[4] = PWM_init((void *)PWM_ePWM5_BASE_ADDR,sizeof(PWM_Obj));
685 obj->pwmHandle[5] = PWM_init((void *)PWM_ePWM6_BASE_ADDR,sizeof(PWM_Obj));
686
687
688 // initialize PWM DAC handles
689 obj->pwmDacHandle[0] = PWMDAC_init((void *)PWM_ePWM7_BASE_ADDR,sizeof(PWM_Obj));
690 obj->pwmDacHandle[1] = PWMDAC_init((void *)PWM_ePWM8_BASE_ADDR,sizeof(PWM_Obj));
691
692
693 // initialize power handle
694 obj->pwrHandle = PWR_init((void *)PWR_BASE_ADDR,sizeof(PWR_Obj));
695
696
697 // initialize timer handles
698 obj->timerHandle[0] = TIMER_init((void *)TIMER0_BASE_ADDR,sizeof(TIMER_Obj));
699 obj->timerHandle[1] = TIMER_init((void *)TIMER1_BASE_ADDR,sizeof(TIMER_Obj));
700 obj->timerHandle[2] = TIMER_init((void *)TIMER2_BASE_ADDR,sizeof(TIMER_Obj));
701
702
703 // initialize drv8301 interface
704 obj->drv8301Handle[0] = DRV8301_init(&obj->drv8301[0],sizeof(obj->drv8301[0]));
705 obj->drv8301Handle[1] = DRV8301_init(&obj->drv8301[1],sizeof(obj->drv8301[1]));
706
707
708 #ifdef QEP
709 // initialize QEP driver
710 obj->qepHandle[0] = QEP_init((void*)QEP1_BASE_ADDR,sizeof(QEP_Obj));
711 obj->qepHandle[1] = QEP_init((void*)QEP2_BASE_ADDR,sizeof(QEP_Obj));
712 #endif
713
714 return(handle);
715 } // end of HAL_init() function
716
717
718 void HAL_setParams(HAL_Handle handle,const USER_Params *pUserParams)
719 {
720 uint_least8_t cnt;
721 HAL_Obj *obj = (HAL_Obj *)handle;
722 _iq beta_lp_pu = _IQ(pUserParams->offsetPole_rps/(float_t)pUserParams->ctrlFreq_Hz);
723
724
725 HAL_setNumCurrentSensors(handle,pUserParams->numCurrentSensors);
726 HAL_setNumVoltageSensors(handle,pUserParams->numVoltageSensors);
727
728
729 for(cnt=0;cnt<HAL_getNumCurrentSensors(handle);cnt++)
730 {
731 HAL_setOffsetBeta_lp_pu(handle,HAL_SensorType_Current,cnt,beta_lp_pu);
732 HAL_setOffsetInitCond(handle,HAL_SensorType_Current,cnt,_IQ(0.0));
733 HAL_setOffsetValue(handle,HAL_SensorType_Current,cnt,_IQ(0.0));
734 }
735
736
737 for(cnt=0;cnt<HAL_getNumVoltageSensors(handle);cnt++)
738 {
739 HAL_setOffsetBeta_lp_pu(handle,HAL_SensorType_Voltage,cnt,beta_lp_pu);
740 HAL_setOffsetInitCond(handle,HAL_SensorType_Voltage,cnt,_IQ(0.0));
741 HAL_setOffsetValue(handle,HAL_SensorType_Voltage,cnt,_IQ(0.0));
742 }
743
744
745 // disable global interrupts
746 CPU_disableGlobalInts(obj->cpuHandle);
747
748
749 // disable cpu interrupts
750 CPU_disableInts(obj->cpuHandle);
751
752
753 // clear cpu interrupt flags
754 CPU_clearIntFlags(obj->cpuHandle);
755
756
757 // setup the clocks
758 HAL_setupClks(handle);
759
760
761 // Setup the PLL
762 HAL_setupPll(handle,PLL_ClkFreq_90_MHz);
763
764
765 // setup the PIE
766 HAL_setupPie(handle);
767
768
769 // run the device calibration
770 HAL_cal(handle);
771
772
773 // setup the peripheral clocks
774 HAL_setupPeripheralClks(handle);
775
776
777 // setup the GPIOs
778 HAL_setupGpios(handle);
779
780
781 // setup the flash
782 HAL_setupFlash(handle);
783
784
785 // setup the ADCs
786 HAL_setupAdcs(handle);
787
788
789 // setup the PWMs
790 HAL_setupPwms(handle,
791 (float_t)pUserParams->systemFreq_MHz,
792 pUserParams->pwmPeriod_usec,
793 USER_NUM_PWM_TICKS_PER_ISR_TICK);
794
795
796 // setup the spiA
797 HAL_setupSpiA(handle);
798
799
800 // setup the spiB
801 HAL_setupSpiB(handle);
802
803
804 // setup the PWM DACs
805 HAL_setupPwmDacs(handle);
806
807
808 // setup the timers
809 HAL_setupTimers(handle,
810 (float_t)pUserParams->systemFreq_MHz);
811
812
813 // setup the drv8301 interface
814 HAL_setupGate(handle);
815
816
817 // set the default current bias
818 {
819 uint_least8_t cnt;
820 _iq bias = _IQ12mpy(ADC_dataBias,_IQ(pUserParams->current_sf));
821
822 for(cnt=0;cnt<HAL_getNumCurrentSensors(handle);cnt++)
823 {
824 HAL_setBias(handle,HAL_SensorType_Current,cnt,bias);
825 }
826 }
827
828
829 // set the current scale factor
830 {
831 _iq current_sf = _IQ(pUserParams->current_sf);
832
833 HAL_setCurrentScaleFactor(handle,current_sf);
834 }
835
836
837 // set the default voltage bias
838 {
839 uint_least8_t cnt;
840 _iq bias = _IQ(0.0);
841
842 for(cnt=0;cnt<HAL_getNumVoltageSensors(handle);cnt++)
843 {
844 HAL_setBias(handle,HAL_SensorType_Voltage,cnt,bias);
845 }
846 }
847
848
849 // set the voltage scale factor
850 {
851 _iq voltage_sf = _IQ(pUserParams->voltage_sf);
852
853 HAL_setVoltageScaleFactor(handle,voltage_sf);
854 }
855
856 return;
857 } // end of HAL_setParams() function
858
859
860 void HAL_setupAdcs(HAL_Handle handle)
861 {
862 HAL_Obj *obj = (HAL_Obj *)handle;
863
864
865 // disable the ADCs
866 ADC_disable(obj->adcHandle);
867
868
869 // power up the bandgap circuit
870 ADC_enableBandGap(obj->adcHandle);
871
872
873 // set the ADC voltage reference source to internal
874 ADC_setVoltRefSrc(obj->adcHandle,ADC_VoltageRefSrc_Int);
875
876
877 // enable the ADC reference buffers
878 ADC_enableRefBuffers(obj->adcHandle);
879
880
881 // Set main clock scaling factor (max45MHz clock for the ADC module)
882 ADC_setDivideSelect(obj->adcHandle,ADC_DivideSelect_ClkIn_by_2);
883
884
885 // power up the ADCs
886 ADC_powerUp(obj->adcHandle);
887
888
889 // enable the ADCs
890 ADC_enable(obj->adcHandle);
891
892
893 // set the ADC interrupt pulse generation to prior
894 ADC_setIntPulseGenMode(obj->adcHandle,ADC_IntPulseGenMode_Prior);
895
896
897 // set the temperature sensor source to external
898 ADC_setTempSensorSrc(obj->adcHandle,ADC_TempSensorSrc_Ext);
899
900
901 // configure the interrupt sources
902 ADC_disableInt(obj->adcHandle,ADC_IntNumber_1);
903 ADC_setIntMode(obj->adcHandle,ADC_IntNumber_1,ADC_IntMode_ClearFlag);
904 ADC_setIntSrc(obj->adcHandle,ADC_IntNumber_1,ADC_IntSrc_EOC7);
905
906 #error "Setup ADCs for 2 motor sampling"
907 //configure the SOCs for boostxldrv8301_revB on J1 & J5 Connection
908 // EXT IA-FB
909 ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_0,ADC_SocChanNumber_A3);
910 ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_0,ADC_SocTrigSrc_EPWM4_ADCSOCA);
911 ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_0,ADC_SocSampleDelay_9_cycles);
912
913 // EXT IA-FB
914 // Duplicate conversion due to ADC Initial Conversion bug (SPRZ342)
915 ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_1,ADC_SocChanNumber_A3);
916 ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_1,ADC_SocTrigSrc_EPWM4_ADCSOCA);
917 ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_1,ADC_SocSampleDelay_9_cycles);
918
919 // EXT IB-FB
920 ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_2,ADC_SocChanNumber_B3);
921 ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_2,ADC_SocTrigSrc_EPWM4_ADCSOCA);
922 ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_2,ADC_SocSampleDelay_9_cycles);
923
924 // EXT IC-FB
925 ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_3,ADC_SocChanNumber_A4);
926 ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_3,ADC_SocTrigSrc_EPWM4_ADCSOCA);
927 ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_3,ADC_SocSampleDelay_9_cycles);
928
929 // ADC-Vhb1
930 ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_4,ADC_SocChanNumber_B4);
931 ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_4,ADC_SocTrigSrc_EPWM4_ADCSOCA);
932 ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_4,ADC_SocSampleDelay_9_cycles);
933
934 // ADC-Vhb2
935 ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_5,ADC_SocChanNumber_A5);
936 ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_5,ADC_SocTrigSrc_EPWM4_ADCSOCA);
937 ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_5,ADC_SocSampleDelay_9_cycles);
938
939 // ADC-Vhb3
940 ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_6,ADC_SocChanNumber_B5);
941 ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_6,ADC_SocTrigSrc_EPWM4_ADCSOCA);
942 ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_6,ADC_SocSampleDelay_9_cycles);
943
944 // VDCBUS
945 ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_7,ADC_SocChanNumber_B7);
946 ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_7,ADC_SocTrigSrc_EPWM4_ADCSOCA);
947 ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_7,ADC_SocSampleDelay_9_cycles);
948
949 return;
950 } // end of HAL_setupAdcs() function
951
952
953 void HAL_setupClks(HAL_Handle handle)
954 {
955 HAL_Obj *obj = (HAL_Obj *)handle;
956
957
958 // enable internal oscillator 1
959 CLK_enableOsc1(obj->clkHandle);
960
961 // set the oscillator source
962 CLK_setOscSrc(obj->clkHandle,CLK_OscSrc_Internal);
963
964 // disable the external clock in
965 CLK_disableClkIn(obj->clkHandle);
966
967 // disable the crystal oscillator
968 CLK_disableCrystalOsc(obj->clkHandle);
969
970 // disable oscillator 2
971 CLK_disableOsc2(obj->clkHandle);
972
973 // set the low speed clock prescaler
974 CLK_setLowSpdPreScaler(obj->clkHandle,CLK_LowSpdPreScaler_SysClkOut_by_1);
975
976 // set the clock out prescaler
977 CLK_setClkOutPreScaler(obj->clkHandle,CLK_ClkOutPreScaler_SysClkOut_by_1);
978
979 return;
980 } // end of HAL_setupClks() function
981
982
983 void HAL_setupFlash(HAL_Handle handle)
984 {
985 HAL_Obj *obj = (HAL_Obj *)handle;
986
987
988 FLASH_enablePipelineMode(obj->flashHandle);
989
990 FLASH_setNumPagedReadWaitStates(obj->flashHandle,FLASH_NumPagedWaitStates_3);
991
992 FLASH_setNumRandomReadWaitStates(obj->flashHandle,FLASH_NumRandomWaitStates_3);
993
994 FLASH_setOtpWaitStates(obj->flashHandle,FLASH_NumOtpWaitStates_5);
995
996 FLASH_setStandbyWaitCount(obj->flashHandle,FLASH_STANDBY_WAIT_COUNT_DEFAULT);
997
998 FLASH_setActiveWaitCount(obj->flashHandle,FLASH_ACTIVE_WAIT_COUNT_DEFAULT);
999
1000 return;
1001 } // HAL_setupFlash() function
1002
1003
1004 void HAL_setupGate(HAL_Handle handle)
1005 {
1006 HAL_Obj *obj = (HAL_Obj *)handle;
1007
1008 DRV8301_setSpiHandle(obj->drv8301Handle[0],obj->spiAHandle);
1009 DRV8301_setGpioHandle(obj->drv8301Handle[0],obj->gpioHandle);
1010 DRV8301_setGpioNumber(obj->drv8301Handle[0],GPIO_Number_50);
1011
1012 DRV8301_setSpiHandle(obj->drv8301Handle[1],obj->spiBHandle);
1013 DRV8301_setGpioHandle(obj->drv8301Handle[1],obj->gpioHandle);
1014 DRV8301_setGpioNumber(obj->drv8301Handle[1],GPIO_Number_52);
1015
1016 return;
1017 } // HAL_setupGate() function
1018
1019
1020 void HAL_setupGpios(HAL_Handle handle)
1021 {
1022 HAL_Obj *obj = (HAL_Obj *)handle;
1023
1024
1025 // PWM1
1026 GPIO_setMode(obj->gpioHandle,GPIO_Number_0,GPIO_0_Mode_EPWM1A);
1027
1028 // PWM2
1029 GPIO_setMode(obj->gpioHandle,GPIO_Number_1,GPIO_1_Mode_EPWM1B);
1030
1031 // PWM3
1032 GPIO_setMode(obj->gpioHandle,GPIO_Number_2,GPIO_2_Mode_EPWM2A);
1033
1034 // PWM4
1035 GPIO_setMode(obj->gpioHandle,GPIO_Number_3,GPIO_3_Mode_EPWM2B);
1036
1037 // PWM5
1038 GPIO_setMode(obj->gpioHandle,GPIO_Number_4,GPIO_4_Mode_EPWM3A);
1039
1040 // PWM6
1041 GPIO_setMode(obj->gpioHandle,GPIO_Number_5,GPIO_5_Mode_EPWM3B);
1042
1043 // PWM4A
1044 GPIO_setMode(obj->gpioHandle,GPIO_Number_6,GPIO_6_Mode_EPWM4A);
1045
1046 // PWM4B
1047 GPIO_setMode(obj->gpioHandle,GPIO_Number_7,GPIO_7_Mode_EPWM4B);
1048
1049 // PWM5A
1050 GPIO_setMode(obj->gpioHandle,GPIO_Number_8,GPIO_8_Mode_EPWM5A);
1051
1052 // PWM5B
1053 GPIO_setMode(obj->gpioHandle,GPIO_Number_9,GPIO_9_Mode_EPWM5B);
1054
1055 // PWM6A
1056 GPIO_setMode(obj->gpioHandle,GPIO_Number_10,GPIO_10_Mode_EPWM6A);
1057
1058 // PWM6B
1059 GPIO_setMode(obj->gpioHandle,GPIO_Number_11,GPIO_11_Mode_EPWM6B);
1060
1061 // GPIO
1062 GPIO_setMode(obj->gpioHandle,GPIO_Number_12,GPIO_12_Mode_GeneralPurpose);
1063
1064 // GPIO
1065 GPIO_setMode(obj->gpioHandle,GPIO_Number_13,GPIO_13_Mode_GeneralPurpose);
1066
1067 // SPIB CLK
1068 GPIO_setMode(obj->gpioHandle,GPIO_Number_14,GPIO_14_Mode_SPICLKB);
1069
1070 // UARTB RX
1071 GPIO_setMode(obj->gpioHandle,GPIO_Number_15,GPIO_15_Mode_SCIRXDB);
1072
1073 // SPIA SIMO
1074 GPIO_setMode(obj->gpioHandle,GPIO_Number_16,GPIO_16_Mode_SPISIMOA);
1075
1076 // SPIA SOMI
1077 GPIO_setMode(obj->gpioHandle,GPIO_Number_17,GPIO_17_Mode_SPISOMIA);
1078
1079 // SPIA CLK
1080 GPIO_setMode(obj->gpioHandle,GPIO_Number_18,GPIO_18_Mode_SPICLKA);
1081
1082 // SPIA CS
1083 GPIO_setMode(obj->gpioHandle,GPIO_Number_19,GPIO_19_Mode_SPISTEA_NOT);
1084
1085 #ifdef QEP
1086 // EQEP1A
1087 GPIO_setMode(obj->gpioHandle,GPIO_Number_20,GPIO_20_Mode_EQEP1A);
1088
1089 // EQEP1B
1090 GPIO_setMode(obj->gpioHandle,GPIO_Number_21,GPIO_21_Mode_EQEP1B);
1091
1092 // GPIO
1093 GPIO_setMode(obj->gpioHandle,GPIO_Number_22,GPIO_22_Mode_GeneralPurpose);
1094
1095 // EQEP1I
1096 GPIO_setMode(obj->gpioHandle,GPIO_Number_23,GPIO_23_Mode_EQEP1I);
1097 #else
1098 // GPIO
1099 GPIO_setMode(obj->gpioHandle,GPIO_Number_20,GPIO_20_Mode_GeneralPurpose);
1100
1101 // GPIO
1102 GPIO_setMode(obj->gpioHandle,GPIO_Number_21,GPIO_21_Mode_GeneralPurpose);
1103
1104 // GPIO
1105 GPIO_setMode(obj->gpioHandle,GPIO_Number_22,GPIO_22_Mode_GeneralPurpose);
1106
1107 // GPIO
1108 GPIO_setMode(obj->gpioHandle,GPIO_Number_23,GPIO_23_Mode_GeneralPurpose);
1109 #endif
1110
1111 // SPIB SIMO
1112 GPIO_setMode(obj->gpioHandle,GPIO_Number_24,GPIO_24_Mode_SPISIMOB);
1113
1114 // SPIB SOMI
1115 GPIO_setMode(obj->gpioHandle,GPIO_Number_25,GPIO_25_Mode_SPISOMIB);
1116
1117 // GPIO
1118 GPIO_setMode(obj->gpioHandle,GPIO_Number_26,GPIO_26_Mode_GeneralPurpose);
1119
1120 // SPIB CS
1121 GPIO_setMode(obj->gpioHandle,GPIO_Number_27,GPIO_27_Mode_SPISTEB_NOT);
1122
1123 // OCTWn
1124 GPIO_setMode(obj->gpioHandle,GPIO_Number_28,GPIO_28_Mode_TZ2_NOT);
1125
1126 // FAULTn
1127 GPIO_setMode(obj->gpioHandle,GPIO_Number_29,GPIO_29_Mode_TZ3_NOT);
1128
1129 // CAN RX
1130 GPIO_setMode(obj->gpioHandle,GPIO_Number_30,GPIO_30_Mode_CANRXA);
1131
1132 // CAN TX
1133 GPIO_setMode(obj->gpioHandle,GPIO_Number_31,GPIO_31_Mode_CANTXA);
1134
1135 // I2C Data
1136 GPIO_setMode(obj->gpioHandle,GPIO_Number_32,GPIO_32_Mode_SDAA);
1137
1138 // I2C Clock
1139 GPIO_setMode(obj->gpioHandle,GPIO_Number_33,GPIO_33_Mode_SCLA);
1140
1141 // LED D9
1142 GPIO_setMode(obj->gpioHandle,GPIO_Number_34,GPIO_34_Mode_GeneralPurpose);
1143 GPIO_setLow(obj->gpioHandle,GPIO_Number_34);
1144 GPIO_setDirection(obj->gpioHandle,GPIO_Number_34,GPIO_Direction_Output);
1145
1146 // JTAG
1147 GPIO_setMode(obj->gpioHandle,GPIO_Number_35,GPIO_35_Mode_JTAG_TDI);
1148 GPIO_setMode(obj->gpioHandle,GPIO_Number_36,GPIO_36_Mode_JTAG_TMS);
1149 GPIO_setMode(obj->gpioHandle,GPIO_Number_37,GPIO_37_Mode_JTAG_TDO);
1150 GPIO_setMode(obj->gpioHandle,GPIO_Number_38,GPIO_38_Mode_JTAG_TCK);
1151
1152 // LED D10
1153 GPIO_setMode(obj->gpioHandle,GPIO_Number_39,GPIO_39_Mode_GeneralPurpose);
1154 GPIO_setLow(obj->gpioHandle,GPIO_Number_39);
1155 GPIO_setDirection(obj->gpioHandle,GPIO_Number_39,GPIO_Direction_Output);
1156
1157 // DAC1
1158 GPIO_setMode(obj->gpioHandle,GPIO_Number_40,GPIO_40_Mode_EPWM7A);
1159
1160 // DAC2
1161 GPIO_setMode(obj->gpioHandle,GPIO_Number_41,GPIO_41_Mode_EPWM7B);
1162
1163 // DAC3
1164 GPIO_setMode(obj->gpioHandle,GPIO_Number_42,GPIO_42_Mode_EPWM8A);
1165
1166 // DAC4
1167 GPIO_setMode(obj->gpioHandle,GPIO_Number_43,GPIO_43_Mode_EPWM8B);
1168
1169 // GPIO
1170 GPIO_setMode(obj->gpioHandle,GPIO_Number_44,GPIO_44_Mode_GeneralPurpose);
1171
1172 // DRV8301 Enable Gate
1173 GPIO_setMode(obj->gpioHandle,GPIO_Number_50,GPIO_50_Mode_GeneralPurpose);
1174 GPIO_setLow(obj->gpioHandle,GPIO_Number_50);
1175 GPIO_setDirection(obj->gpioHandle,GPIO_Number_50,GPIO_Direction_Output);
1176
1177 // DRV8301 DC Calibration
1178 GPIO_setMode(obj->gpioHandle,GPIO_Number_51,GPIO_51_Mode_GeneralPurpose);
1179 GPIO_setLow(obj->gpioHandle,GPIO_Number_51);
1180 GPIO_setDirection(obj->gpioHandle,GPIO_Number_51,GPIO_Direction_Output);
1181
1182 // DRV8301 Enable Gate
1183 GPIO_setMode(obj->gpioHandle,GPIO_Number_52,GPIO_52_Mode_GeneralPurpose);
1184 GPIO_setLow(obj->gpioHandle,GPIO_Number_52);
1185 GPIO_setDirection(obj->gpioHandle,GPIO_Number_52,GPIO_Direction_Output);
1186
1187 // DRV8301 Device Calibration
1188 GPIO_setMode(obj->gpioHandle,GPIO_Number_53,GPIO_53_Mode_GeneralPurpose);
1189 GPIO_setLow(obj->gpioHandle,GPIO_Number_53);
1190 GPIO_setDirection(obj->gpioHandle,GPIO_Number_53,GPIO_Direction_Output);
1191
1192 #ifdef QEP
1193 // EQEP2A
1194 GPIO_setMode(obj->gpioHandle,GPIO_Number_54,GPIO_54_Mode_EQEP2A);
1195
1196 // EQEP2B
1197 GPIO_setMode(obj->gpioHandle,GPIO_Number_55,GPIO_55_Mode_EQEP2B);
1198
1199 // EQEP2I
1200 GPIO_setMode(obj->gpioHandle,GPIO_Number_56,GPIO_56_Mode_EQEP2I);
1201 #else
1202 // GPIO
1203 GPIO_setMode(obj->gpioHandle,GPIO_Number_54,GPIO_54_Mode_GeneralPurpose);
1204
1205 // GPIO
1206 GPIO_setMode(obj->gpioHandle,GPIO_Number_55,GPIO_55_Mode_GeneralPurpose);
1207
1208 // GPIO
1209 GPIO_setMode(obj->gpioHandle,GPIO_Number_56,GPIO_56_Mode_GeneralPurpose);
1210 #endif
1211
1212 // No Connection
1213 GPIO_setMode(obj->gpioHandle,GPIO_Number_57,GPIO_57_Mode_GeneralPurpose);
1214
1215 // UARTB TX
1216 GPIO_setMode(obj->gpioHandle,GPIO_Number_58,GPIO_58_Mode_SCITXDB);
1217
1218 return;
1219 } // end of HAL_setupGpios() function
1220
1221
1222 void HAL_setupPie(HAL_Handle handle)
1223 {
1224 HAL_Obj *obj = (HAL_Obj *)handle;
1225
1226
1227 PIE_disable(obj->pieHandle);
1228
1229 PIE_disableAllInts(obj->pieHandle);
1230
1231 PIE_clearAllInts(obj->pieHandle);
1232
1233 PIE_clearAllFlags(obj->pieHandle);
1234
1235 PIE_setDefaultIntVectorTable(obj->pieHandle);
1236
1237 PIE_enable(obj->pieHandle);
1238
1239 return;
1240 } // end of HAL_setupPie() function
1241
1242
1243 void HAL_setupPeripheralClks(HAL_Handle handle)
1244 {
1245 HAL_Obj *obj = (HAL_Obj *)handle;
1246
1247
1248 CLK_enableAdcClock(obj->clkHandle);
1249
1250 CLK_enableCompClock(obj->clkHandle,CLK_CompNumber_1);
1251 CLK_enableCompClock(obj->clkHandle,CLK_CompNumber_2);
1252 CLK_enableCompClock(obj->clkHandle,CLK_CompNumber_3);
1253
1254 CLK_disableEcap1Clock(obj->clkHandle);
1255
1256 CLK_enableEcanaClock(obj->clkHandle);
1257
1258 #ifdef QEP
1259 CLK_enableEqep1Clock(obj->clkHandle);
1260 CLK_enableEqep2Clock(obj->clkHandle);
1261 #endif
1262
1263 CLK_enablePwmClock(obj->clkHandle,PWM_Number_1);
1264 CLK_enablePwmClock(obj->clkHandle,PWM_Number_2);
1265 CLK_enablePwmClock(obj->clkHandle,PWM_Number_3);
1266 CLK_enablePwmClock(obj->clkHandle,PWM_Number_4);
1267 CLK_enablePwmClock(obj->clkHandle,PWM_Number_5);
1268 CLK_enablePwmClock(obj->clkHandle,PWM_Number_6);
1269 CLK_enablePwmClock(obj->clkHandle,PWM_Number_7);
1270 CLK_enablePwmClock(obj->clkHandle,PWM_Number_8);
1271
1272 CLK_disableHrPwmClock(obj->clkHandle);
1273
1274 CLK_enableI2cClock(obj->clkHandle);
1275
1276 CLK_disableLinAClock(obj->clkHandle);
1277
1278 CLK_disableClaClock(obj->clkHandle);
1279
1280 CLK_disableSciaClock(obj->clkHandle);
1281 CLK_enableScibClock(obj->clkHandle);
1282
1283 CLK_enableSpiaClock(obj->clkHandle);
1284 CLK_enableSpibClock(obj->clkHandle);
1285
1286 CLK_enableTbClockSync(obj->clkHandle);
1287
1288 return;
1289 } // end of HAL_setupPeripheralClks() function
1290
1291
1292 void HAL_setupPll(HAL_Handle handle,const PLL_ClkFreq_e clkFreq)
1293 {
1294 HAL_Obj *obj = (HAL_Obj *)handle;
1295
1296
1297 // make sure PLL is not running in limp mode
1298 if(PLL_getClkStatus(obj->pllHandle) != PLL_ClkStatus_Normal)
1299 {
1300 // reset the clock detect
1301 PLL_resetClkDetect(obj->pllHandle);
1302
1303 // ???????
1304 asm(" ESTOP0");
1305 }
1306
1307
1308 // Divide Select must be ClkIn/4 before the clock rate can be changed
1309 if(PLL_getDivideSelect(obj->pllHandle) != PLL_DivideSelect_ClkIn_by_4)
1310 {
1311 PLL_setDivideSelect(obj->pllHandle,PLL_DivideSelect_ClkIn_by_4);
1312 }
1313
1314
1315 if(PLL_getClkFreq(obj->pllHandle) != clkFreq)
1316 {
1317 // disable the clock detect
1318 PLL_disableClkDetect(obj->pllHandle);
1319
1320 // set the clock rate
1321 PLL_setClkFreq(obj->pllHandle,clkFreq);
1322 }
1323
1324
1325 // wait until locked
1326 while(PLL_getLockStatus(obj->pllHandle) != PLL_LockStatus_Done) {}
1327
1328
1329 // enable the clock detect
1330 PLL_enableClkDetect(obj->pllHandle);
1331
1332
1333 // set divide select to ClkIn/2 to get desired clock rate
1334 // NOTE: clock must be locked before setting this register
1335 PLL_setDivideSelect(obj->pllHandle,PLL_DivideSelect_ClkIn_by_2);
1336
1337 return;
1338 } // end of HAL_setupPll() function
1339
1340
1341 void HAL_setupPwms(HAL_Handle handle,
1342 const float_t systemFreq_MHz,
1343 const float_t pwmPeriod_usec,
1344 const uint_least16_t numPwmTicksPerIsrTick)
1345 {
1346 HAL_Obj *obj = (HAL_Obj *)handle;
1347 uint16_t halfPeriod_cycles = (uint16_t)(systemFreq_MHz*pwmPeriod_usec) >> 1;
1348 uint_least8_t cnt;
1349
1350
1351 // turns off the outputs of the EPWM peripherals which will put the power switches
1352 // into a high impedance state.
1353 PWM_setOneShotTrip(obj->pwmHandle[PWM_Number_1]);
1354 PWM_setOneShotTrip(obj->pwmHandle[PWM_Number_2]);
1355 PWM_setOneShotTrip(obj->pwmHandle[PWM_Number_3]);
1356
1357 for(cnt=0;cnt<3;cnt++)
1358 {
1359 // setup the Time-Base Control Register (TBCTL)
1360 PWM_setCounterMode(obj->pwmHandle[cnt],PWM_CounterMode_UpDown);
1361 PWM_disableCounterLoad(obj->pwmHandle[cnt]);
1362 PWM_setPeriodLoad(obj->pwmHandle[cnt],PWM_PeriodLoad_Immediate);
1363 PWM_setSyncMode(obj->pwmHandle[cnt],PWM_SyncMode_EPWMxSYNC);
1364 PWM_setHighSpeedClkDiv(obj->pwmHandle[cnt],PWM_HspClkDiv_by_1);
1365 PWM_setClkDiv(obj->pwmHandle[cnt],PWM_ClkDiv_by_1);
1366 PWM_setPhaseDir(obj->pwmHandle[cnt],PWM_PhaseDir_CountUp);
1367 PWM_setRunMode(obj->pwmHandle[cnt],PWM_RunMode_FreeRun);
1368
1369 // setup the Timer-Based Phase Register (TBPHS)
1370 PWM_setPhase(obj->pwmHandle[cnt],0);
1371
1372 // setup the Time-Base Counter Register (TBCTR)
1373 PWM_setCount(obj->pwmHandle[cnt],0);
1374
1375 // setup the Time-Base Period Register (TBPRD)
1376 // set to zero initially
1377 PWM_setPeriod(obj->pwmHandle[cnt],0);
1378
1379 // setup the Counter-Compare Control Register (CMPCTL)
1380 PWM_setLoadMode_CmpA(obj->pwmHandle[cnt],PWM_LoadMode_Zero);
1381 PWM_setLoadMode_CmpB(obj->pwmHandle[cnt],PWM_LoadMode_Zero);
1382 PWM_setShadowMode_CmpA(obj->pwmHandle[cnt],PWM_ShadowMode_Shadow);
1383 PWM_setShadowMode_CmpB(obj->pwmHandle[cnt],PWM_ShadowMode_Immediate);
1384
1385 // setup the Action-Qualifier Output A Register (AQCTLA)
1386 PWM_setActionQual_CntUp_CmpA_PwmA(obj->pwmHandle[cnt],PWM_ActionQual_Set);
1387 PWM_setActionQual_CntDown_CmpA_PwmA(obj->pwmHandle[cnt],PWM_ActionQual_Clear);
1388
1389 // setup the Dead-Band Generator Control Register (DBCTL)
1390 PWM_setDeadBandOutputMode(obj->pwmHandle[cnt],PWM_DeadBandOutputMode_EPWMxA_Rising_EPWMxB_Falling);
1391 PWM_setDeadBandPolarity(obj->pwmHandle[cnt],PWM_DeadBandPolarity_EPWMxB_Inverted);
1392
1393 // setup the Dead-Band Rising Edge Delay Register (DBRED)
1394 PWM_setDeadBandRisingEdgeDelay(obj->pwmHandle[cnt],HAL_PWM_DBRED_CNT);
1395
1396 // setup the Dead-Band Falling Edge Delay Register (DBFED)
1397 PWM_setDeadBandFallingEdgeDelay(obj->pwmHandle[cnt],HAL_PWM_DBFED_CNT);
1398 // setup the PWM-Chopper Control Register (PCCTL)
1399 PWM_disableChopping(obj->pwmHandle[cnt]);
1400
1401 // setup the Trip Zone Select Register (TZSEL)
1402 PWM_disableTripZones(obj->pwmHandle[cnt]);
1403 }
1404
1405
1406 // setup the Event Trigger Selection Register (ETSEL)
1407 PWM_disableInt(obj->pwmHandle[PWM_Number_1]);
1408 PWM_setSocAPulseSrc(obj->pwmHandle[PWM_Number_1],PWM_SocPulseSrc_CounterEqualZero);
1409 PWM_enableSocAPulse(obj->pwmHandle[PWM_Number_1]);
1410
1411
1412 // setup the Event Trigger Prescale Register (ETPS)
1413 if(numPwmTicksPerIsrTick == 3)
1414 {
1415 PWM_setIntPeriod(obj->pwmHandle[PWM_Number_1],PWM_IntPeriod_ThirdEvent);
1416 PWM_setSocAPeriod(obj->pwmHandle[PWM_Number_1],PWM_SocPeriod_ThirdEvent);
1417 }
1418 else if(numPwmTicksPerIsrTick == 2)
1419 {
1420 PWM_setIntPeriod(obj->pwmHandle[PWM_Number_1],PWM_IntPeriod_SecondEvent);
1421 PWM_setSocAPeriod(obj->pwmHandle[PWM_Number_1],PWM_SocPeriod_SecondEvent);
1422 }
1423 else
1424 {
1425 PWM_setIntPeriod(obj->pwmHandle[PWM_Number_1],PWM_IntPeriod_FirstEvent);
1426 PWM_setSocAPeriod(obj->pwmHandle[PWM_Number_1],PWM_SocPeriod_FirstEvent);
1427 }
1428
1429
1430 // setup the Event Trigger Clear Register (ETCLR)
1431 PWM_clearIntFlag(obj->pwmHandle[PWM_Number_1]);
1432 PWM_clearSocAFlag(obj->pwmHandle[PWM_Number_1]);
1433
1434 // first step to synchronize the pwms
1435 CLK_disableTbClockSync(obj->clkHandle);
1436
1437 // since the PWM is configured as an up/down counter, the period register is set to one-half
1438 // of the desired PWM period
1439 PWM_setPeriod(obj->pwmHandle[PWM_Number_1],halfPeriod_cycles);
1440 PWM_setPeriod(obj->pwmHandle[PWM_Number_2],halfPeriod_cycles);
1441 PWM_setPeriod(obj->pwmHandle[PWM_Number_3],halfPeriod_cycles);
1442
1443 // last step to synchronize the pwms
1444 CLK_enableTbClockSync(obj->clkHandle);
1445
1446 return;
1447 } // end of HAL_setupPwms() function
1448
1449
1450 void HAL_setupSpiA(HAL_Handle handle)
1451 {
1452 HAL_Obj *obj = (HAL_Obj *)handle;
1453
1454 SPI_reset(obj->spiAHandle);
1455 SPI_setMode(obj->spiAHandle,SPI_Mode_Master);
1456 SPI_setClkPolarity(obj->spiAHandle,SPI_ClkPolarity_OutputRisingEdge_InputFallingEdge);
1457 SPI_enableTx(obj->spiAHandle);
1458 SPI_enableTxFifoEnh(obj->spiAHandle);
1459 SPI_enableTxFifo(obj->spiAHandle);
1460 SPI_setTxDelay(obj->spiAHandle,0x0018);
1461 SPI_setBaudRate(obj->spiAHandle,(SPI_BaudRate_e)(0x000d));
1462 SPI_setCharLength(obj->spiAHandle,SPI_CharLength_16_Bits);
1463 SPI_setSuspend(obj->spiAHandle,SPI_TxSuspend_free);
1464 SPI_enable(obj->spiAHandle);
1465
1466 return;
1467 } // end of HAL_setupSpiA() function
1468
1469
1470 void HAL_setupSpiB(HAL_Handle handle)
1471 {
1472 HAL_Obj *obj = (HAL_Obj *)handle;
1473
1474 SPI_reset(obj->spiBHandle);
1475 SPI_setMode(obj->spiBHandle,SPI_Mode_Master);
1476 SPI_setClkPolarity(obj->spiBHandle,SPI_ClkPolarity_OutputRisingEdge_InputFallingEdge);
1477 SPI_enableTx(obj->spiBHandle);
1478 SPI_enableTxFifoEnh(obj->spiBHandle);
1479 SPI_enableTxFifo(obj->spiBHandle);
1480 SPI_setTxDelay(obj->spiBHandle,0x0018);
1481 SPI_setBaudRate(obj->spiBHandle,(SPI_BaudRate_e)(0x000d));
1482 SPI_setCharLength(obj->spiBHandle,SPI_CharLength_16_Bits);
1483 SPI_setSuspend(obj->spiBHandle,SPI_TxSuspend_free);
1484 SPI_enable(obj->spiBHandle);
1485
1486 return;
1487 } // end of HAL_setupSpiB() function
1488
1489
1490 void HAL_setupPwmDacs(HAL_Handle handle)
1491 {
1492 HAL_Obj *obj = (HAL_Obj *)handle;
1493 uint16_t halfPeriod_cycles = 512; // 3000->10kHz, 1500->20kHz, 1000-> 30kHz, 500->60kHz
1494 uint_least8_t cnt;
1495
1496
1497 for(cnt=0;cnt<2;cnt++)
1498 {
1499 // initialize the Time-Base Control Register (TBCTL)
1500 PWMDAC_setCounterMode(obj->pwmDacHandle[cnt],PWM_CounterMode_UpDown);
1501 PWMDAC_disableCounterLoad(obj->pwmDacHandle[cnt]);
1502 PWMDAC_setPeriodLoad(obj->pwmDacHandle[cnt],PWM_PeriodLoad_Immediate);
1503 PWMDAC_setSyncMode(obj->pwmDacHandle[cnt],PWM_SyncMode_EPWMxSYNC);
1504 PWMDAC_setHighSpeedClkDiv(obj->pwmDacHandle[cnt],PWM_HspClkDiv_by_1);
1505 PWMDAC_setClkDiv(obj->pwmDacHandle[cnt],PWM_ClkDiv_by_1);
1506 PWMDAC_setPhaseDir(obj->pwmDacHandle[cnt],PWM_PhaseDir_CountUp);
1507 PWMDAC_setRunMode(obj->pwmDacHandle[cnt],PWM_RunMode_FreeRun);
1508
1509 // initialize the Timer-Based Phase Register (TBPHS)
1510 PWMDAC_setPhase(obj->pwmDacHandle[cnt],0);
1511
1512 // setup the Time-Base Counter Register (TBCTR)
1513 PWMDAC_setCount(obj->pwmDacHandle[cnt],0);
1514
1515 // Initialize the Time-Base Period Register (TBPRD)
1516 // set to zero initially
1517 PWMDAC_setPeriod(obj->pwmDacHandle[cnt],0);
1518
1519 // initialize the Counter-Compare Control Register (CMPCTL)
1520 PWMDAC_setLoadMode_CmpA(obj->pwmDacHandle[cnt],PWM_LoadMode_Zero);
1521 PWMDAC_setLoadMode_CmpB(obj->pwmDacHandle[cnt],PWM_LoadMode_Zero);
1522 PWMDAC_setShadowMode_CmpA(obj->pwmDacHandle[cnt],PWM_ShadowMode_Shadow);
1523 PWMDAC_setShadowMode_CmpB(obj->pwmDacHandle[cnt],PWM_ShadowMode_Shadow);
1524
1525 // Initialize the Action-Qualifier Output A Register (AQCTLA)
1526 PWMDAC_setActionQual_CntUp_CmpA_PwmA(obj->pwmDacHandle[cnt],PWM_ActionQual_Clear);
1527 PWMDAC_setActionQual_CntDown_CmpA_PwmA(obj->pwmDacHandle[cnt],PWM_ActionQual_Set);
1528 PWMDAC_setActionQual_CntUp_CmpB_PwmB(obj->pwmDacHandle[cnt],PWM_ActionQual_Clear);
1529 PWMDAC_setActionQual_CntDown_CmpB_PwmB(obj->pwmDacHandle[cnt],PWM_ActionQual_Set);
1530
1531 // Initialize the Dead-Band Control Register (DBCTL)
1532 PWMDAC_disableDeadBand(obj->pwmDacHandle[cnt]);
1533
1534 // Initialize the PWM-Chopper Control Register (PCCTL)
1535 PWMDAC_disableChopping(obj->pwmDacHandle[cnt]);
1536
1537 // Initialize the Trip-Zone Control Register (TZSEL)
1538 PWMDAC_disableTripZones(obj->pwmDacHandle[cnt]);
1539
1540 // Initialize the Trip-Zone Control Register (TZCTL)
1541 PWMDAC_setTripZoneState_TZA(obj->pwmDacHandle[cnt],PWM_TripZoneState_HighImp);
1542 PWMDAC_setTripZoneState_TZB(obj->pwmDacHandle[cnt],PWM_TripZoneState_HighImp);
1543 PWMDAC_setTripZoneState_DCAEVT1(obj->pwmDacHandle[cnt],PWM_TripZoneState_HighImp);
1544 PWMDAC_setTripZoneState_DCAEVT2(obj->pwmDacHandle[cnt],PWM_TripZoneState_HighImp);
1545 PWMDAC_setTripZoneState_DCBEVT1(obj->pwmDacHandle[cnt],PWM_TripZoneState_HighImp);
1546 }
1547
1548 // since the PWM is configured as an up/down counter, the period register is set to one-half
1549 // of the desired PWM period
1550 PWMDAC_setPeriod(obj->pwmDacHandle[PWMDAC_Number_1],halfPeriod_cycles);
1551 PWMDAC_setPeriod(obj->pwmDacHandle[PWMDAC_Number_2],halfPeriod_cycles);
1552
1553 return;
1554 } // end of HAL_setupPwmDacs() function
1555
1556
1557 void HAL_setupTimers(HAL_Handle handle,const float_t systemFreq_MHz)
1558 {
1559 HAL_Obj *obj = (HAL_Obj *)handle;
1560 uint32_t timerPeriod_cnts = (uint32_t)(systemFreq_MHz * (float_t)1000000.0) - 1;
1561
1562 // use timer 0 for frequency diagnostics
1563 TIMER_setDecimationFactor(obj->timerHandle[0],0);
1564 TIMER_setEmulationMode(obj->timerHandle[0],TIMER_EmulationMode_RunFree);
1565 TIMER_setPeriod(obj->timerHandle[0],timerPeriod_cnts);
1566 TIMER_setPreScaler(obj->timerHandle[0],0);
1567
1568 // use timer 1 for CPU usage diagnostics
1569 TIMER_setDecimationFactor(obj->timerHandle[1],0);
1570 TIMER_setEmulationMode(obj->timerHandle[1],TIMER_EmulationMode_RunFree);
1571 TIMER_setPeriod(obj->timerHandle[1],timerPeriod_cnts);
1572 TIMER_setPreScaler(obj->timerHandle[1],0);
1573
1574 return;
1575 } // end of HAL_setupTimers() function
1576
1577 #error fix the DRV8301 interface functions
1578 void HAL_writeDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
1579 {
1580 HAL_Obj *obj = (HAL_Obj *)handle;
1581
1582 DRV8301_writeData(obj->drv8301Handle,Spi_8301_Vars);
1583
1584 return;
1585 } // end of HAL_writeDrvData() function
1586
1587
1588 void HAL_readDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
1589 {
1590 HAL_Obj *obj = (HAL_Obj *)handle;
1591
1592 DRV8301_readData(obj->drv8301Handle,Spi_8301_Vars);
1593
1594 return;
1595 } // end of HAL_readDrvData() function
1596
1597
1598 void HAL_setupDrvSpi(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
1599 {
1600 HAL_Obj *obj = (HAL_Obj *)handle;
1601
1602 DRV8301_setupSpi(obj->drv8301Handle,Spi_8301_Vars);
1603
1604 return;
1605 } // end of HAL_setupDrvSpi() function
1606
1607
1608 // 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_::offsetHandle_I
OFFSET_Handle offsetHandle_I[3]
the handles for the current offset estimators
Definition: boostxldrv8301_revB/f28x/f2806x/src/hal_obj.h:140
HAL_enableGlobalInts
void HAL_enableGlobalInts(HAL_Handle handle)
Enables global interrupts.
Definition: hal_both.c:519
HAL_enableAdcInts
void HAL_enableAdcInts(HAL_Handle handle)
Enables the ADC interrupts.
Definition: hal_both.c:478
_HAL_Obj_::offset_V
OFFSET_Obj offset_V[3]
the voltage offset objects
Definition: boostxldrv8301_revB/f28x/f2806x/src/hal_obj.h:144
HAL_disableGlobalInts
void HAL_disableGlobalInts(HAL_Handle handle)
Disables global interrupts.
Definition: hal_both.c:467
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
_IQ
#define _IQ(A)
Definition: 32b/IQmathLib.h:319
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_Obj_::spiBHandle
SPI_Handle spiBHandle
the SPI handle
Definition: boostxldrv8301_revB/f28x/f2806x/src/hal_obj.h:172
HAL_OscTempComp
void HAL_OscTempComp(HAL_Handle handle)
Executes the oscillator 1 and 2 calibration functions.
Definition: hal_both.c:100
getOsc1FineTrimOffset
#define getOsc1FineTrimOffset()
Defines the oscillator 1 fine trim at high temp.
Definition: boostxldrv8301_revB/f28x/f2806x/src/hal.h:93
HAL_setOffsetValue
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.
Definition: boostxldrv8301_revB/f28x/f2806x/src/hal.h:918
_HAL_Obj_::clkHandle
CLK_Handle clkHandle
the clock handle
Definition: boostxldrv8301_revB/f28x/f2806x/src/hal_obj.h:132
HAL_writeDrvData
void HAL_writeDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
Writes data to the driver.
Definition: hal_both.c:1578
_HAL_Obj_::drv8301
DRV8301_Obj drv8301
the drv8301 interface object
Definition: boostxldrv8301_revB/f28x/f2806x/src/hal_obj.h:175
HAL_setOffsetInitCond
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.
Definition: boostxldrv8301_revB/f28x/f2806x/src/hal.h:893
_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: hal_both.c:294
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: hal_both.c:1243
HAL_setupTimers
void HAL_setupTimers(HAL_Handle handle, const float_t systemFreq_MHz)
Sets up the timers.
Definition: hal_both.c:1557
_iq
long _iq
Definition: 32b/IQmathLib.h:223
HAL_osc2Comp
void HAL_osc2Comp(HAL_Handle handle, const int16_t sensorSample)
Executes the oscillator 2 calibration based on input sample.
Definition: hal_both.c:193
HAL_setupPll
void HAL_setupPll(HAL_Handle handle, const PLL_ClkFreq_e clkFreq)
Sets up the PLL (Phase Lock Loop)
Definition: hal_both.c:1292
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: hal_both.c:1020
HAL_setOffsetBeta_lp_pu
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.
Definition: boostxldrv8301_revB/f28x/f2806x/src/hal.h:868
HAL_setupFlash
void HAL_setupFlash(HAL_Handle handle)
Sets up the FLASH.
Definition: hal_both.c:983
HAL_enablePwmInt
void HAL_enablePwmInt(HAL_Handle handle)
Enables the PWM interrupt.
Definition: hal_both.c:530
HAL_setupClks
void HAL_setupClks(HAL_Handle handle)
Sets up the clocks.
Definition: hal_both.c:953
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: hal_both.c:568
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
_IQ12mpy
#define _IQ12mpy(A, B)
Definition: 32b/IQmathLib.h:828
HAL_Handle
struct _HAL_Obj_ * HAL_Handle
Defines the HAL handle.
Definition: boostxldrv8301_revB/f28x/f2806x/src/hal_obj.h:189
HAL_enableDrv
void HAL_enableDrv(HAL_Handle handle)
Enables the 8301 device.
Definition: hal_both.c:509
HAL_osc1Comp
void HAL_osc1Comp(HAL_Handle handle, const int16_t sensorSample)
Executes the oscillator 1 calibration based on input sample.
Definition: hal_both.c:166
_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.
HAL_setupDrvSpi
void HAL_setupDrvSpi(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
Sets up the SPI interface for the driver.
Definition: hal_both.c:1598
_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: hal_both.c:1341
HAL_setupPie
void HAL_setupPie(HAL_Handle handle)
Sets up the PIE (Peripheral Interrupt Expansion)
Definition: hal_both.c:1222
HAL_enableDebugInt
void HAL_enableDebugInt(HAL_Handle handle)
Enables the debug interrupt.
Definition: hal_both.c:498
_HAL_Obj_::spiAHandle
SPI_Handle spiAHandle
the SPI handle
Definition: boostxldrv8301_revB/f28x/f2806x/src/hal_obj.h:171
_USER_Params_::offsetPole_rps
float_t offsetPole_rps
Defines the pole location for the voltage and current offset estimation, rad/s.
Definition: fast/src/32b/userParams.h:207
hal.h
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_setupSpiB
void HAL_setupSpiB(HAL_Handle handle)
Sets up the spiB peripheral.
Definition: hal_both.c:1470
_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: hal_both.c:246
FP_SCALE
#define FP_SCALE
Defines used in oscillator calibration functions.
Definition: boostxldrv8301_revB/f28x/f2806x/src/hal.h:76
hal_obj.h
_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: hal_both.c:598
_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
_USER_Params_::ctrlFreq_Hz
uint_least32_t ctrlFreq_Hz
Defines the controller frequency, Hz.
Definition: fast/src/32b/userParams.h:253
HAL_cal
void HAL_cal(HAL_Handle handle)
Executes calibration routines.
Definition: hal_both.c:67
HAL_setupGate
void HAL_setupGate(HAL_Handle handle)
Sets up the GATE object.
Definition: hal_both.c:1004
hal
HAL_Obj hal
Defines the HAL object.
Definition: hal_both.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: hal_both.c:319
HAL_setupPwmDacs
void HAL_setupPwmDacs(HAL_Handle handle)
Sets up the PWM DACs (Pulse Width Modulator Digital to Analof Converters)
Definition: hal_both.c:1490
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_getOscTrimValue
uint16_t HAL_getOscTrimValue(int16_t coarse, int16_t fine)
Converts coarse and fine oscillator trim values into a single 16bit word value.
Definition: hal_both.c:220
_HAL_Obj_::offset_I
OFFSET_Obj offset_I[3]
the current offset objects
Definition: boostxldrv8301_revB/f28x/f2806x/src/hal_obj.h:141
_HAL_Obj_::pwrHandle
PWR_Handle pwrHandle
Definition: boostxldrv8301_revB/f28x/f2806x/src/hal_obj.h:156
OFFSET_init
OFFSET_Handle OFFSET_init(void *pMemory, const size_t numBytes)
Initializes the offset.
Definition: 32b/offset.c:70
_HAL_Obj_::pllHandle
PLL_Handle pllHandle
the PLL handle
Definition: boostxldrv8301_revB/f28x/f2806x/src/hal_obj.h:150
HAL_setupSpiA
void HAL_setupSpiA(HAL_Handle handle)
Sets up the spiA peripheral.
Definition: hal_both.c:1450
HAL_setParams
void HAL_setParams(HAL_Handle handle, const USER_Params *pUserParams)
Sets the hardware abstraction layer parameters.
Definition: hal_both.c:718
HAL_readDrvData
void HAL_readDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
Reads data from the driver.
Definition: hal_both.c:1588
_HAL_Obj_::drv8301Handle
DRV8301_Handle drv8301Handle
the drv8301 interface handle
Definition: boostxldrv8301_revB/f28x/f2806x/src/hal_obj.h:174
HAL_setupAdcs
void HAL_setupAdcs(HAL_Handle handle)
Sets up the ADCs (Analog to Digital Converters)
Definition: hal_both.c:860
HAL_enableTimer0Int
void HAL_enableTimer0Int(HAL_Handle handle)
Enables the Timer 0 interrupt.
Definition: hal_both.c:549
HAL_disableWdog
void HAL_disableWdog(HAL_Handle halHandle)
Disables the watch dog.
Definition: hal_both.c:455
_HAL_Obj_::offsetHandle_V
OFFSET_Handle offsetHandle_V[3]
the handles for the voltage offset estimators
Definition: boostxldrv8301_revB/f28x/f2806x/src/hal_obj.h:143
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
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