Digital Power Starter Kit 3 Firmware
dsPIC33C Buck Converter Voltage Mode Control Example
dpsk3_hwdescr.h
1 /* Microchip Technology Inc. and its subsidiaries. You may use this software
2  * and any derivatives exclusively with Microchip products.
3  *
4  * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
5  * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
6  * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
7  * PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
8  * WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
9  *
10  * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
11  * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
12  * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
13  * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
14  * FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS
15  * IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF
16  * ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
17  *
18  * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
19  * TERMS.
20  */
21 
22 /*
23  * @file dpsk3_hwdescr.h
24  * Author: M91406
25  * @brief DPSK3 Hardware Descriptor header file
26  * Revision history:
27  */
28 
29 // This is a guard condition so that contents of this file are not included
30 // more than once.
31 #ifndef DPSK3_HARDWARE_DESCRIPTOR_H
32 #define DPSK3_HARDWARE_DESCRIPTOR_H
33 
34 #include <xc.h> // include processor files - each processor file is guarded.
35 #include <stdint.h> // include standard integer data types
36 #include <stdbool.h> // include standard boolean data types
37 #include <stddef.h> // include standard definition data types
38 #include <math.h> // include standard math functions library
39 
40 
41 /* DPSK3 BOARD CIRCUIT SEGMENTS */
42 
43 #define INCLUDE_BUCK true // Include buck converter declarations
44 #define INCLUDE_BOOST false // Include boost converter declarations
45 #define INCLUDE_LCD true // Include LCD declarations
46 
47 
58 #ifndef __DPSK3_R30__
59  #define __DPSK3_R30__
60 #endif
61 
62  // end of group hardware-id-macro
64 
65 
76 /* CUSTOM RUNTIME OPTIONS */
77 #define PLANT_MEASUREMENT false
78 
79 #define DBGPIN1_ENABLE true
80 #define DBGPIN2_ENABLE true
81 
82 #define DBGDAC_ENABLE true
83 
84  // end of group special-options
85 
86 
97 #define CPU_FREQUENCY (float)100000000.0
98 
99 // ADC/DAC Reference and Resolution Settings
100 #define ADC_REFERENCE (float)3.300
101 #define ADC_RESOLUTION (float)12.0
102 
103 // PWM/ADC Clock Settings
104 #define PWM_CLOCK_HIGH_RESOLUTION true
105 
106 #if (PWM_CLOCK_HIGH_RESOLUTION)
107 #define PWM_CLOCK_FREQUENCY (float)4.0e+9
108 #else
109 #define PWM_CLOCK_FREQUENCY (float)500.0e+6
110 #endif
111  // end of group device-abstraction-settings
113 
125 #define CPU_TCY (float)(1.0/CPU_FREQUENCY)
126 #define ADC_GRANULARITY (float)(ADC_REFERENCE / pow(2.0, ADC_RESOLUTION))
127 #define ADC_VALUE_MAX (uint16_t) (pow(2.0, ADC_RESOLUTION) - 1.0) // DO NOT CHANGE
128 #define PWM_CLOCK_PERIOD (float)(1.0/PWM_CLOCK_FREQUENCY)
129 
130  // end of group device-abstraction-macros
131 
132 
145 #define MAIN_EXECUTION_PERIOD (float)100.0e-6
146 
147  // end of group state-machine-settings ~~~~~~~~~~
148 
160 #define MAIN_EXEC_PER (uint16_t)((CPU_FREQUENCY * MAIN_EXECUTION_PERIOD)-1) // DO NOT CHANGE
161  // end of group state-machine-macros ~~~~~~~~~~
163 
174 #define _OsTimerInterrupt _T1Interrupt
175 #define _OSTIMER_IP _T1IP
176 #define _OSTIMER_IE _T1IE
177 #define _OSTIMER_IF _T1IF
178 #define _OSTIMER_PRIORITY 2
179 
180  // end of group state-machine-mcal ~~~~~~~~~~
181 
182 
195 #if (DBGPIN1_ENABLE == true)
196 #define DBGPIN1_PORT 1
197 #define DBGPIN1_PIN 5
198 #define DBGPIN1_Get() _RB5
199 #define DBGPIN1_Set() { _LATB5 = 1; }
200 #define DBGPIN1_Clear() { _LATB5 = 0; }
201 #define DBGPIN1_Toggle() { _LATB5 ^= 1; }
202 #define DBGPIN1_Init() { _LATB5 = 0; _TRISB5 = 0; }
203 #define DBGPIN1_Dispose() { _LATB5 = 1; _TRISB5 = 1; }
204 #endif
205 
206 #if (DBGPIN2_ENABLE == true)
207 #define DBGPIN2_PORT 1
208 #define DBGPIN2_PIN 11
209 #define DBGPIN2_Get() _RB11
210 #define DBGPIN2_Set() { _LATB11 = 1; }
211 #define DBGPIN2_Clear() { _LATB11 = 0; }
212 #define DBGPIN2_Toggle() { _LATB11 ^= 1; }
213 #define DBGPIN2_Init() { _LATB11 = 0; _TRISB11 = 0; }
214 #define DBGPIN2_Dispose() { _LATB11 = 1; _TRISB11 = 1; }
215 #endif
216 
217 // Ref LED on DPSK3 (TP51)
218 #define DBGLED_PORT 1
219 #define DBGLED_PIN 6
220 #define DBGLED_Get() _RB6
221 #define DBGLED_Set() { _LATB6 = 1; }
222 #define DBGLED_Clear() { _LATB6 = 0; }
223 #define DBGLED_Toggle() { _LATB6 ^= 1; }
224 #define DBGLED_Init() { _LATB6 = 0; _TRISB6 = 0; }
225 #define DBGLED_Dispose() { _LATB6 = 1; _TRISB6 = 1; }
226 
227 // Power Good Output
228 #define PWRGOOD_PORT 1
229 #define PWRGOOD_PIN 12
230 #define PWRGOOD_Get() { _RB12; }
231 #define PWRGOOD_Set() { _LATB12 = 1; }
232 #define PWRGOOD_Clear() { _LATB12 = 0; }
233 #define PWRGOOD_Toggle() { _LATB12 ^= 1; }
234 #define PWRGOOD_Init() { _LATB12 = 0; _TRISB12 = 0; }
235 #define PWRGOOD_Dispose() { _LATB12 = 1; _TRISB12 = 1; }
236 
237 // User Switch Input
238 #define SW_USER_PORT 3
239 #define SW_USER_PIN 1
240 #define SW_USER_Get() _RD1
241 #define SW_USER_Set() { _LATD1 = 1; }
242 #define SW_USER_Clear() { _LATD1 = 0; }
243 #define SW_USER_Toggle() { _LATD1 ^= 1; }
244 #define SW_USER_Init() { _LATD1 = 1; _TRISD1 = 1; }
245 #define SW_USER_Dispose() { _LATD1 = 1; _TRISD1 = 1; }
246 
247  // end of group circuit-gpio-mcal
249 
250 
264 #define DAC_OUTPUT_INSTANCE 1U
265 #define DAC_BUFFER_OPA_INSTANCE 3U
266 #define DAC_OUTPUT_INIT_VALUE 0U
267 
268 
269 #if (DAC_OUTPUT_INSTANCE == 1U)
270  #define DACOUT_Set(x) { DAC1DATH=x; }
271  #define DACOUT_Get() DAC1DATH
272 #elif (DAC_OUTPUT_INSTANCE == 2U)
273  #define DACOUT_Set(x) { DAC2DATH=x; }
274  #define DACOUT_Get() DAC2DATH
275 #elif (DAC_OUTPUT_INSTANCE == 3U)
276  #define DACOUT_Set(x) { DAC3DATH=x; }
277  #define DACOUT_Get() DAC3DATH
278 #endif
279  // end of group circuit-peripheral-mcal
281 
282 
283 #if (INCLUDE_BUCK == true)
284 
286 
299 #define BUCK_NO_OF_PHASES 1U
300 
301 #define BUCK_SWITCHING_FREQUENCY (float)500.0e+3
302 #define BUCK_PWM_DUTY_CYCLE_MIN (float) 0.010
303 #define BUCK_PWM_DUTY_CYCLE_MAX (float) 0.900
304 #define BUCK_LEADING_EDGE_BLANKING (float)120.0e-9
305 #define BUCK_DEAD_TIME_LEADING_EDGE (float) 20.0e-9
306 #define BUCK_DEAD_TIME_FALLING_EDGE (float) 60.0e-9
307 
308  // end of group pwm-settings-buck ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
309 
324 #define BUCK_PWM_CHANNEL 1U
325 #define BUCK_PWM_GPIO_INSTANCE 1U
326 #define BUCK_PWM_GPIO_PORT_PINH 14U
327 #define BUCK_PWM_GPIO_PORT_PINL 15U
328 #define BUCK_PWM_OUTPUT_SWAP false
329 
330 #define BUCK_PWM_PDC PG1DC
331 #define BUCK_PWMH_TRIS _TRISB14
332 #define BUCK_PWMH_WR _LATB14
333 #define BUCK_PWMH_RD _RB14
334 #define BUCK_PWMH_RPx (uint8_t)46
335 #define BUCK_PWML_TRIS _TRISB15
336 #define BUCK_PWML_WR _LATB15
337 #define BUCK_PWML_RD _RB15
338 #define BUCK_PWML_RPx (uint8_t)47
339 
340 #define _BUCK_PWM_Interrupt _PWM1Interrupt
341 #define BUCK_PWM_IF _PWM1IF
342 #define BUCK_PWM_IE _PWM1IE
343 #define BUCK_PWM_IP _PWM1IP
344 #define BUCK_PWM_TRGSRC_TRG1 0b00100
345 #define BUCK_PWM_TRGSRC_TRG2 0b00101
346 #define BUCK_PWM_PGxTRIGA PG1TRIGA
347 #define BUCK_PWM_PGxTRIGB PG1TRIGB
348 #define BUCK_PWM_PGxTRIGC PG1TRIGC
349 
350 #define BUCK_PWM_ADTR1OFS 0U
351 #define BUCK_PWM_ADTR1PS 0U
352 
353 #define BUCK_PWM_UPDREQ PG1STATbits.UPDREQ
354  // end of group pwm-mcal-buck ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
356 
357 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
369 // Conversion Macros
370 #define BUCK_SWITCHING_PERIOD (float)(1.0/BUCK_SWITCHING_FREQUENCY)
371 #define BUCK_PWM_PERIOD (uint16_t)(float)(BUCK_SWITCHING_PERIOD / PWM_CLOCK_PERIOD)
372 #define BUCK_PWM_PHASE_SHIFT (uint16_t)((float)BUCK_PWM_PERIOD / (float)BUCK_NO_OF_PHASES)
373 #define BUCK_PWM_DC_MIN (uint16_t)(BUCK_PWM_DUTY_CYCLE_MIN * (float)BUCK_PWM_PERIOD)
374 #define BUCK_PWM_DC_MAX (uint16_t)(BUCK_PWM_DUTY_CYCLE_MAX * (float)BUCK_PWM_PERIOD)
375 #define BUCK_LEB_PERIOD (uint16_t)(BUCK_LEADING_EDGE_BLANKING / (float)PWM_CLOCK_PERIOD)
376 #define BUCK_PWM_DEAD_TIME_LE (uint16_t)(BUCK_DEAD_TIME_LEADING_EDGE / (float)PWM_CLOCK_PERIOD)
377 #define BUCK_PWM_DEAD_TIME_FE (uint16_t)(BUCK_DEAD_TIME_FALLING_EDGE / (float)PWM_CLOCK_PERIOD)
378 
379  // end of group pwm-macros-buck ~~~~~~~~~~~~~~~~~
380 
381 
382 
393 // Feedback Declarations
394 #define BUCK_VIN_MINIMUM (float) 6.500
395 #define BUCK_VIN_NOMINAL (float) 9.000
396 #define BUCK_VIN_MAXIMUM (float)13.800
397 
398 #define BUCK_VIN_UNDER_VOLTAGE (float) 6.000
399 #define BUCK_VIN_OVER_VOLTAGE (float)14.300
400 #define BUCK_VIN_HYSTERESIS (float) 1.000
401 
402 #define BUCK_VIN_R1 (float) 6.980
403 #define BUCK_VIN_R2 (float) 1.000
404 
405 #define BUCK_VIN_FEEDBACK_OFFSET (float) 0.0000
406 #define BUCK_VIN_ADC_TRG_DELAY (float) 20.0e-9
407 
408  // end of group input-voltage-feedback-settings-buck ~~~~~~~~~~~~~~~~
409 
410 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
422 // Peripheral Assignments
423 #define _BUCK_VIN_ADCInterrupt _ADCAN12Interrupt
424 #define _BUCK_VIN_ADCISR_IF _ADCAN12IF
425 
426 #define BUCK_VIN_ANSEL _ANSELC0
427 #define BUCK_VIN_ADCCORE 8
428 #define BUCK_VIN_ADCIN 12
429 #define BUCK_VIN_ADCBUF ADCBUF12
430 #define BUCK_VIN_ADCTRIG PG1TRIGB
431 #define BUCK_VIN_TRGSRC BUCK_PWM_TRGSRC_TRG2
432 
433  // end of group input-voltage-feedback-mcal-buck ~~~~~~~~~~~~~~~~~~~~
434 
435 
436 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
448 #define BUCK_VIN_FEEDBACK_GAIN (float)((BUCK_VIN_R2) / (BUCK_VIN_R1 + BUCK_VIN_R2)) // DO NOT CHANGE
449 #define BUCK_VIN_MIN (uint16_t)(BUCK_VIN_MINIMUM * BUCK_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
450 #define BUCK_VIN_NOM (uint16_t)(BUCK_VIN_NOMINAL * BUCK_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
451 #define BUCK_VIN_MAX (uint16_t)(BUCK_VIN_MAXIMUM * BUCK_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
452 #define BUCK_VIN_HYST (uint16_t)(BUCK_VIN_HYSTERESIS * BUCK_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
453 #define BUCK_VIN_UVLO_TRIP (uint16_t)(BUCK_VIN_UNDER_VOLTAGE * BUCK_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
454 #define BUCK_VIN_UVLO_RELEASE (uint16_t)((BUCK_VIN_UNDER_VOLTAGE + BUCK_VIN_HYSTERESIS) * BUCK_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
455 #define BUCK_VIN_OVLO_TRIP (uint16_t)(BUCK_VIN_OVER_VOLTAGE * BUCK_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
456 #define BUCK_VIN_OVLO_RELEASE (uint16_t)((BUCK_VIN_OVER_VOLTAGE - BUCK_VIN_HYSTERESIS) * BUCK_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
457 #define BUCK_VIN_ADC_TRGDLY (uint16_t)(BUCK_VIN_ADC_TRG_DELAY / PWM_CLOCK_PERIOD)
458 #define BUCK_VIN_OFFSET (uint16_t)(BUCK_VIN_FEEDBACK_OFFSET / ADC_GRANULARITY)
459 
460 #define BUCK_VIN_NORM_INV_G (float)(1.0/BUCK_VIN_FEEDBACK_GAIN)
461 #define BUCK_VIN_NORM_SCALER (int16_t)(ceil(log(BUCK_VIN_NORM_INV_G)/log(2)))
462 #define BUCK_VIN_NORM_FACTOR (int16_t)((BUCK_VIN_NORM_INV_G / pow(2.0, BUCK_VIN_NORM_SCALER)) * (pow(2.0, 15)-1))
463 
464 #define BUCK_VIN_RANGE_MAX (float)(ADC_REFERENCE * BUCK_VIN_NORM_INV_G)
465  // end of group input-voltage-feedback-macros-buck ~~~~~~~~~~~~~~~~~~
467 
468 
479 // Feedback Declarations
480 #define BUCK_VOUT_MINIMUM (float) 0.000
481 #define BUCK_VOUT_NOMINAL (float) 3.300
482 #define BUCK_VOUT_MAXIMUM (float) 4.000
483 #define BUCK_VOUT_HYSTERESIS (float) 0.500
484 
485 #define BUCK_VOUT_TOLERANCE_MAX (float) 0.200
486 #define BUCK_VOUT_TOLERANCE_MIN (float) 0.100
487 
488 #define BUCK_VOUT_DIV_R1 (float) 1.000
489 #define BUCK_VOUT_DIV_R2 (float) 1.000
490 #define BUCK_VOUT_FEEDBACK_OFFSET (float) 0.000
491 #define BUCK_VOUT_ADC_TRG_DELAY (float)20.0e-9
492 
493  // end of group output-voltage-feedback-settings-buck ~~~~~~~~~~~~~~~
494 
495 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
507 // Peripheral Assignments
508 #define BUCK_VOUT_ANSEL _ANSELC1
509 #define BUCK_VOUT_ADCCORE 8
510 #define BUCK_VOUT_ADCIN 13
511 #define BUCK_VOUT_ADCBUF ADCBUF13
512 #define BUCK_VOUT_ADCTRIG PG1TRIGA
513 #define BUCK_VOUT_TRGSRC BUCK_PWM_TRGSRC_TRG1
514 
515  // end of group output-voltage-feedback-mcal-buck ~~~~~~~~~~~~~~~~~~~
516 
517 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
529 #define BUCK_VOUT_FEEDBACK_GAIN (float)((BUCK_VOUT_DIV_R2) / (BUCK_VOUT_DIV_R1 + BUCK_VOUT_DIV_R2))
530 
531 #define BUCK_VOUT_REF (uint16_t)(BUCK_VOUT_NOMINAL * BUCK_VOUT_FEEDBACK_GAIN / ADC_GRANULARITY)
532 #define BUCK_VOUT_NOM (uint16_t) BUCK_VOUT_REF
533 #define BUCK_VOUT_DEV_TRIP (uint16_t)((BUCK_VOUT_TOLERANCE_MAX * BUCK_VOUT_FEEDBACK_GAIN) / ADC_GRANULARITY)
534 #define BUCK_VOUT_DEV_RELEASE (uint16_t)((BUCK_VOUT_TOLERANCE_MIN * BUCK_VOUT_FEEDBACK_GAIN) / ADC_GRANULARITY)
535 #define BUCK_VOUT_OVP_TRIP (uint16_t)((BUCK_VOUT_MAXIMUM * BUCK_VOUT_FEEDBACK_GAIN) / ADC_GRANULARITY)
536 #define BUCK_VOUT_OVP_RELEASE (uint16_t)((BUCK_VOUT_MAXIMUM - BUCK_VOUT_HYSTERESIS) * BUCK_VOUT_FEEDBACK_GAIN / ADC_GRANULARITY)
537 #define BUCK_VOUT_OFFSET (uint16_t)(BUCK_VOUT_FEEDBACK_OFFSET / ADC_GRANULARITY)
538 #define BUCK_VOUT_ADC_TRGDLY (uint16_t)(BUCK_VOUT_ADC_TRG_DELAY / PWM_CLOCK_PERIOD)
539 
540 #define BUCK_VOUT_NORM_INV_G (float)(1.0/BUCK_VOUT_FEEDBACK_GAIN)
541 #define BUCK_VOUT_NORM_SCALER (int16_t)(ceil(log(BUCK_VOUT_NORM_INV_G)/log(2)))
542 #define BUCK_VOUT_NORM_FACTOR (int16_t)((BUCK_VOUT_NORM_INV_G / pow(2.0, BUCK_VOUT_NORM_SCALER)) * (pow(2.0, 15)-1))
543 
544 #define BUCK_VOUT_RANGE_MAX (float)(ADC_REFERENCE * BUCK_VOUT_NORM_INV_G)
545 
546  // end of group output-voltage-feedback-macros-buck ~~~~~~~~~~~~~~~~~
547 
548 
568 // Feedback Declarations
569 #define BUCK_ISNS_CT 0
570 #define BUCK_ISNS_AMP 1
571 
572 #define BUCK_ISNS_OPTION BUCK_ISNS_CT
573 
574 // Settings based on the selection made above
575 #if (BUCK_ISNS_OPTION == BUCK_ISNS_CT)
576 
577  #define BUCK_ISNS_FEEDBACK_GAIN (float) 1.000
578  #define BUCK_ISNS_MINIMUM (float)-1.000
579  #define BUCK_ISNS_MAXIMUM (float) 2.500
580  #define BUCK_ISNS_RELEASE (float) 2.000
581  #define BUCK_ISNS_REFERENCE (float) 2.000
582  #define BUCK_ISNS_ADC_TRG_DELAY (float) 80.0e-9
583  #define BUCK_ISNS_FEEDBACK_OFFSET (float) 0.000
584 
585  #define BUCK_ISNS_OFFSET_CALIBRATION_ENABLE false
586 
587 #elif (BUCK_ISNS_OPTION == BUCK_ISNS_AMP)
588 
589  #define BUCK_ISNS_FEEDBACK_GAIN (float) 0.600
590  #define BUCK_ISNS_MINIMUM (float) 0.000
591  #define BUCK_ISNS_MAXIMUM (float) 2.500
592  #define BUCK_ISNS_RELEASE (float) 2.500
593  #define BUCK_ISNS_REFERENCE (float) 2.500
594  #define BUCK_ISNS_ADC_TRG_DELAY (float) 240.0e-9
595  #define BUCK_ISNS_FEEDBACK_OFFSET (float) 1.650
596 
597  #define BUCK_ISNS_OFFSET_CALIBRATION_ENABLE true
598 
599 #endif
600  // end of group phase-current-feedback-settings-buck ~~~~~~~~~~~~~~~~
602 
603 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
615 // Phase Current Feedback Settings Conversion Macros
616 #define BUCK_ISNS_MIN (uint16_t)(int16_t)(((BUCK_ISNS_MINIMUM-BUCK_ISNS_FEEDBACK_OFFSET) * BUCK_ISNS_FEEDBACK_GAIN) / ADC_GRANULARITY)
617 #define BUCK_ISNS_OCL (uint16_t)(((BUCK_ISNS_MAXIMUM-BUCK_ISNS_FEEDBACK_OFFSET) * BUCK_ISNS_FEEDBACK_GAIN) / ADC_GRANULARITY)
618 #define BUCK_ISNS_OCL_RELEASE (uint16_t)(((BUCK_ISNS_RELEASE-BUCK_ISNS_FEEDBACK_OFFSET) * BUCK_ISNS_FEEDBACK_GAIN) / ADC_GRANULARITY)
619 #define BUCK_ISNS_REF (uint16_t)((BUCK_ISNS_REFERENCE * BUCK_ISNS_FEEDBACK_GAIN) / ADC_GRANULARITY)
620 #define BUCK_ISNS_FB_OFFSET (uint16_t)(BUCK_ISNS_FEEDBACK_OFFSET / ADC_GRANULARITY)
621 #define BUCK_ISNS_ADC_TRGDLY (uint16_t)(BUCK_ISNS_ADC_TRG_DELAY / PWM_CLOCK_PERIOD)
622 
623 #define BUCK_ISNS_NORM_INV_G (float)(1.0/BUCK_ISNS_FEEDBACK_GAIN)
624 #define BUCK_ISNS_NORM_SCALER (int16_t)(ceil(log(BUCK_ISNS_NORM_INV_G)/log(2)))
625 #define BUCK_ISNS_NORM_FACTOR (int16_t)((BUCK_ISNS_NORM_INV_G / pow(2.0, BUCK_ISNS_NORM_SCALER)) * (pow(2.0, 15)-1))
626 
627  // end of group phase-current-feedback-macros ~~~~~~~~~~~~~~~~~~~~~~~
628 
629 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
641 // Peripheral Assignments
642 #if (BUCK_ISNS_OPTION == BUCK_ISNS_CT)
643 
644  #define _BUCK_ISNS_ADCInterrupt _ADCAN0Interrupt
645  #define _BUCK_ISNS_ADCISR_IF _ADCAN0IF
646 
647  #define BUCK_ISNS_ANSEL _ANSELA0
648  #define BUCK_ISNS_ADCCORE 0
649  #define BUCK_ISNS_ADCIN 0
650  #define BUCK_ISNS_ALT_IN_SELECT 0b00
651  #define BUCK_ISNS_ADCBUF ADCBUF0
652  #define BUCK_ISNS_ADCTRIG PG1TRIGB
653  #define BUCK_ISNS_TRGSRC BUCK_PWM_TRGSRC_TRG2
654 
655 #elif (BUCK_ISNS_OPTION == BUCK_ISNS_AMP)
656 
657  #define _BUCK_ISNS_ADCInterrupt _ADCAN1Interrupt
658  #define _BUCK_ISNS_ADCISR_IF _ADCAN1IF
659 
660  #define BUCK_ISNS_ANSEL _ANSELA1
661  #define BUCK_ISNS_ADCCORE 1
662  #define BUCK_ISNS_ADCIN 1
663  #define BUCK_ISNS_ALT_IN_SELECT 0b01
664  #define BUCK_ISNS_ADCBUF ADCBUF1
665  #define BUCK_ISNS_ADCTRIG PG1TRIGB
666  #define BUCK_ISNS_TRGSRC BUCK_PWM_TRGSRC_TRG2
667 
668 #else
669  #pragma message "hardware abstraction layer warning: no current sense feedback selected."
670 #endif
671  // end of group phase-current-feedback-mcal-buck ~~~~~~~~~~~~~~~~~~~~
673 
674 
686 #define BUCK_AGC_EXECUTION_DELAY (float)(370.0e-9)
687 
688  // end of group adaptive-gain-control-settings-buck ~~~~~~~~~~~~~~~~~
689 
690 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
702 #define BUCK_VL_MINIMUM (float)(BUCK_VIN_UNDER_VOLTAGE - BUCK_VOUT_MAXIMUM)
703 #define BUCK_VL_NOMINAL (float)(BUCK_VIN_NOMINAL - BUCK_VOUT_NOMINAL)
704 #define BUCK_VL_MAXIMUM (float)(BUCK_VIN_RANGE_MAX - 0)
705 
706 // The AGC compare value is defined at nominal input voltage and output voltage
707 // The maximum modulation factor is normalized to fractional '1' to prevent number overruns
708 #define BUCK_AGC_FACTOR_MAX (float)(BUCK_VL_NOMINAL / BUCK_VL_MINIMUM)
709 #define BUCK_AGC_NOM_SCALER (uint16_t)(ceil(log(BUCK_AGC_FACTOR_MAX)/log(2)))
710 #define BUCK_AGC_NOM_FACTOR (uint16_t)(0x7FFF >> BUCK_AGC_NOM_SCALER)
711 #define BUCK_AGC_MEDIAN (int16_t)(((int16_t)(((float)BUCK_VIN_NOM * BUCK_VIN_NORM_FCT) - BUCK_VOUT_NOM))>>BUCK_AGC_NOM_SCALER)
712 
713 // To calculate the voltage across the inductor, input and output voltage ADC results need to be normalized. The normalization factor is determined here
714 // Each input voltage sample has to be multiplied with this scaling factor to allow the calculation of the instantaneous voltage across the inductor
715 #define BUCK_VIN_NORM_FCT (float)(BUCK_VOUT_FEEDBACK_GAIN / BUCK_VIN_FEEDBACK_GAIN)
716 #define BUCK_AGC_IO_NORM_SCALER (int16_t)(ceil(log(BUCK_VIN_NORM_FCT)/log(2)))
717 #define BUCK_AGC_IO_NORM_FACTOR (int16_t)((BUCK_VIN_NORM_FCT / pow(2.0, BUCK_AGC_IO_NORM_SCALER)) * (pow(2.0, 15)-1))
718 
719 // Additional execution time calculation to be considered in trigger delay and overall control timing
720 #define BUCK_AGC_EXEC_DLY (uint16_t)(BUCK_AGC_EXECUTION_DELAY / PWM_CLOCK_PERIOD)
721 
722  // end of group adaptive-gain-control-macros-buck ~~~~~~~~~~~~~~~~~~~
723 
724 
737 // Hardware-dependent defines
738 #define BUCK_VOUT_TRIG_PWM 0
739 #define BUCK_VOUT_TRIG_ADC 1
740 
741 #define BUCK_VOUT_TRIGGER_MODE BUCK_VOUT_TRIG_PWM
742 #define BUCK_VOUT_ISR_PRIORITY 5
743 
744 #if (BUCK_VOUT_TRIGGER_MODE == BUCK_VOUT_TRIG_ADC)
745 
746  #define _BUCK_VLOOP_Interrupt _ADCAN13Interrupt
747  #define _BUCK_VLOOP_ISR_IP _ADCAN13IP
748  #define _BUCK_VLOOP_ISR_IF _ADCAN13IF
749  #define _BUCK_VLOOP_ISR_IE _ADCAN13IE
750 
751 #elif (BUCK_VOUT_TRIGGER_MODE == BUCK_VOUT_TRIG_PWM)
752 
753  #define _BUCK_VLOOP_Interrupt _PWM1Interrupt
754  #define _BUCK_VLOOP_ISR_IP _PWM1IP
755  #define _BUCK_VLOOP_ISR_IF _PWM1IF
756  #define _BUCK_VLOOP_ISR_IE _PWM1IE
757 
758 #endif
759  // end of group isr-settings-buck ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
761 
762 
799 #define BUCK_POWER_ON_DELAY (float) 200e-3
800 #define BUCK_VRAMP_PERIOD (float) 100e-3
801 #define BUCK_IRAMP_PERIOD (float) 100e-3
802 #define BUCK_POWER_GOOD_DELAY (float) 200e-3
803 
804  // end of group startup-timing-settings ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
805 
806 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
818 #define BUCK_POD (uint16_t)(((float)BUCK_POWER_ON_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
819 #define BUCK_VRAMP_PER (uint16_t)(((float)BUCK_VRAMP_PERIOD / (float)MAIN_EXECUTION_PERIOD)-1.0)
820 #define BUCK_VREF_STEP (uint16_t)((float)BUCK_VOUT_REF / (float)(BUCK_VRAMP_PER + 1.0))
821 #define BUCK_IRAMP_PER (uint16_t)(((float)BUCK_IRAMP_PERIOD / (float)MAIN_EXECUTION_PERIOD)-1.0)
822 #define BUCK_IREF_STEP (uint16_t)((float)BUCK_ISNS_REF / (float)(BUCK_VRAMP_PER + 1.0))
823 #define BUCK_PGD (uint16_t)(((float)BUCK_POWER_GOOD_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
824  // end of group startup-timing-macros-buck ~~~~~~~~~~~~~~~~~~~~~~~~~~
826 
827 
854 #define BUCK_UVLO_TRIP_DELAY (float) 5e-3
855 #define BUCK_UVLO_RECOVERY_DELAY (float) 500e-3
856 #define BUCK_OVLO_TRIP_DELAY (float) 5e-3
857 #define BUCK_OVLO_RECOVERY_DELAY (float) 500e-3
858 #define BUCK_REGERR_TRIP_DELAY (float) 25e-3
859 #define BUCK_REGERR_RECOVERY_DELAY (float) 2000e-3
860 #define BUCK_OCP_TRIP_DELAY (float) 2e-3
861 #define BUCK_OCP_RECOVERY_DELAY (float) 2000e-3
862 
863 #define BUCK_FAULT_RESTART_CYCLES 10
864 
865  // end of group fault-response-settings-buck ~~~~~~~~~~~~~~~~~~~~~~~~
866 
867 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
879 #define BUCK_UVLO_TDLY (uint16_t)(((float) BUCK_UVLO_TRIP_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
880 #define BUCK_UVLO_RDLY (uint16_t)(((float) BUCK_UVLO_RECOVERY_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
881 #define BUCK_OVLO_TDLY (uint16_t)(((float) BUCK_OVLO_TRIP_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
882 #define BUCK_OVLO_RDLY (uint16_t)(((float) BUCK_OVLO_RECOVERY_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
883 #define BUCK_REGERR_TDLY (uint16_t)(((float) BUCK_REGERR_TRIP_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
884 #define BUCK_REGERR_RDLY (uint16_t)(((float)BUCK_REGERR_RECOVERY_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
885 #define BUCK_OCP_TDLY (uint16_t)(((float) BUCK_OCP_TRIP_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
886 #define BUCK_OCP_RDLY (uint16_t)(((float) BUCK_OCP_RECOVERY_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
887 
888  // end of group fault-response-macros-buck ~~~~~~~~~~~~~~~~~~~~~~~~~~
889  // Doxygen section
891 #endif /* INCLUDE_BUCK */
892 
893 #if (INCLUDE_BOOST == true)
894 
896 
909 #define BOOST_NO_OF_PHASES 1U
910 
911 #define BOOST_SWITCHING_FREQUENCY (float)500.0e+3
912 #define BOOST_PWM_DUTY_CYCLE_MIN (float) 0.030
913 #define BOOST_PWM_DUTY_CYCLE_MAX (float) 0.900
914 #define BOOST_LEADING_EDGE_BLANKING (float)120.0e-9
915 #define BOOST_DEAD_TIME_LEADING_EDGE (float) 0.0e-9
916 #define BOOST_DEAD_TIME_FALLING_EDGE (float) 0.0e-9
917 
918  // end of group pwm-settings-boost ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
919 
934 #define BOOST_PWM_CHANNEL 2U
935 #define BOOST_PWM_GPIO_INSTANCE 1U
936 #define BOOST_PWM_GPIO_PORT_PINH 13U
937 #define BOOST_PWM_GPIO_PORT_PINL 12U
938 #define BOOST_PWM_OUTPUT_SWAP true
939 
940 #define BOOST_PWM_PDC PG2DC
941 #define BOOST_PWMH_TRIS _TRISB12
942 #define BOOST_PWMH_WR _LATB12
943 #define BOOST_PWMH_RD _RB12
944 #define BOOST_PWMH_RPx (uint8_t)44
945 #define BOOST_PWML_TRIS _TRISB13
946 #define BOOST_PWML_WR _LATB13
947 #define BOOST_PWML_RD _RB13
948 #define BOOST_PWML_RPx (uint8_t)45
949 
950 #define _BOOST_PWM_Interrupt _PWM2Interrupt
951 #define BOOST_PWM_IF _PWM2IF
952 #define BOOST_PWM_IE _PWM2IE
953 #define BOOST_PWM_IP _PWM2IP
954 #define BOOST_PWM_TRGSRC_TRG1 0b00110
955 #define BOOST_PWM_TRGSRC_TRG2 0b00111
956 #define BOOST_PWM_PGxTRIGA PG2TRIGA
957 #define BOOST_PWM_PGxTRIGB PG2TRIGB
958 #define BOOST_PWM_PGxTRIGC PG2TRIGC
959 
960 #define BOOST_PWM_ADTR1OFS 0U
961 #define BOOST_PWM_ADTR1PS 0U
962 
963 #define BOOST_PWM_UPDREQ PG2STATbits.UPDREQ
964  // end of group pwm-mcal-boost ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
966 
967 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
979 // Conversion Macros
980 #define BOOST_SWITCHING_PERIOD (float)(1.0/BOOST_SWITCHING_FREQUENCY)
981 #define BOOST_PWM_PERIOD (uint16_t)(float)(BOOST_SWITCHING_PERIOD / PWM_CLOCK_PERIOD)
982 #define BOOST_PWM_PHASE_SHIFT (uint16_t)((float)BOOST_PWM_PERIOD / (float)BOOST_NO_OF_PHASES)
983 #define BOOST_PWM_DC_MIN (uint16_t)(BOOST_PWM_DUTY_CYCLE_MIN * (float)BOOST_PWM_PERIOD)
984 #define BOOST_PWM_DC_MAX (uint16_t)(BOOST_PWM_DUTY_CYCLE_MAX * (float)BOOST_PWM_PERIOD)
985 #define BOOST_LEB_PERIOD (uint16_t)(BOOST_LEADING_EDGE_BLANKING / (float)PWM_CLOCK_PERIOD)
986 #define BOOST_PWM_DEAD_TIME_LE (uint16_t)(BOOST_DEAD_TIME_LEADING_EDGE / (float)PWM_CLOCK_PERIOD)
987 #define BOOST_PWM_DEAD_TIME_FE (uint16_t)(BOOST_DEAD_TIME_FALLING_EDGE / (float)PWM_CLOCK_PERIOD)
988 
989  // end of group pwm-macros-boost ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
990 
991 
992 
1003 // Feedback Declarations
1004 #define BOOST_VIN_MINIMUM (float) 6.500
1005 #define BOOST_VIN_NOMINAL (float) 9.000
1006 #define BOOST_VIN_MAXIMUM (float)13.800
1007 
1008 #define BOOST_VIN_UNDER_VOLTAGE (float) 6.000
1009 #define BOOST_VIN_OVER_VOLTAGE (float)14.300
1010 #define BOOST_VIN_HYSTERESIS (float) 1.000
1011 
1012 #define BOOST_VIN_R1 (float) 6.980
1013 #define BOOST_VIN_R2 (float) 1.000
1014 
1015 #define BOOST_VIN_FEEDBACK_OFFSET (float) 0.0000
1016 #define BOOST_VIN_ADC_TRG_DELAY (float)20.0e-9
1017 
1018  // end of group input-voltage-feedback-settings-boost ~~~~~~~~~~~~~~~
1019 
1020 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1032 // Peripheral Assignments
1033 #define _BOOST_VIN_ADCInterrupt _ADCAN12Interrupt
1034 #define _BOOST_VIN_ADCISR_IF _ADCAN12IF
1035 
1036 #define BOOST_VIN_ANSEL _ANSELC0
1037 #define BOOST_VIN_ADCCORE 8
1038 #define BOOST_VIN_ADCIN 12
1039 #define BOOST_VIN_ADCBUF ADCBUF12
1040 #define BOOST_VIN_ADCTRIG PG2TRIGB
1041 #define BOOST_VIN_TRGSRC BOOST_PWM_TRGSRC_TRG2
1042 
1043  // end of group input-voltage-feedback-mcal-boost ~~~~~~~~~~~~~~~~~~~
1044 
1045 
1046 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1058 #define BOOST_VIN_FEEDBACK_GAIN (float)((BOOST_VIN_R2) / (BOOST_VIN_R1 + BOOST_VIN_R2)) // DO NOT CHANGE
1059 #define BOOST_VIN_MIN (uint16_t)(BOOST_VIN_MINIMUM * BOOST_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
1060 #define BOOST_VIN_NOM (uint16_t)(BOOST_VIN_NOMINAL * BOOST_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
1061 #define BOOST_VIN_MAX (uint16_t)(BOOST_VIN_MAXIMUM * BOOST_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
1062 #define BOOST_VIN_HYST (uint16_t)(BOOST_VIN_HYSTERESIS * BOOST_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
1063 #define BOOST_VIN_UVLO_TRIP (uint16_t)(BOOST_VIN_UNDER_VOLTAGE * BOOST_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
1064 #define BOOST_VIN_UVLO_RELEASE (uint16_t)((BOOST_VIN_UNDER_VOLTAGE + BOOST_VIN_HYSTERESIS) * BOOST_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
1065 #define BOOST_VIN_OVLO_TRIP (uint16_t)(BOOST_VIN_OVER_VOLTAGE * BOOST_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
1066 #define BOOST_VIN_OVLO_RELEASE (uint16_t)((BOOST_VIN_OVER_VOLTAGE - BOOST_VIN_HYSTERESIS) * BOOST_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
1067 #define BOOST_VIN_ADC_TRGDLY (uint16_t)(BOOST_VIN_ADC_TRG_DELAY / PWM_CLOCK_PERIOD)
1068 #define BOOST_VIN_OFFSET (uint16_t)(BOOST_VIN_FEEDBACK_OFFSET / ADC_GRANULARITY)
1069 
1070 #define BOOST_VIN_NORM_INV_G (float)(1.0/BOOST_VIN_FEEDBACK_GAIN)
1071 #define BOOST_VIN_NORM_SCALER (int16_t)(ceil(log(BOOST_VIN_NORM_INV_G)/log(2)))
1072 #define BOOST_VIN_NORM_FACTOR (int16_t)((BOOST_VIN_NORM_INV_G / pow(2.0, BOOST_VIN_NORM_SCALER)) * (pow(2.0, 15)-1))
1073 
1074 #define BOOST_VIN_RANGE_MAX (float)(ADC_REFERENCE * BOOST_VIN_NORM_INV_G)
1075  // end of group input-voltage-feedback-macros-boost ~~~~~~~~~~~~~~~~~
1077 
1078 
1089 // Feedback Declarations
1090 #define BOOST_VOUT_MINIMUM (float)14.00
1091 #define BOOST_VOUT_NOMINAL (float)15.00
1092 #define BOOST_VOUT_MAXIMUM (float)16.00
1093 #define BOOST_VOUT_HYSTERESIS (float)0.500
1094 
1095 #define BOOST_VOUT_TOLERANCE_MAX (float)0.500
1096 #define BOOST_VOUT_TOLERANCE_MIN (float)0.100
1097 #define BOOST_VOUT_VFWD_DROP_MAX (float)0.400
1098 
1099 #define BOOST_VOUT_DIV_R1 (float) 6.980
1100 #define BOOST_VOUT_DIV_R2 (float) 1.000
1101 #define BOOST_VOUT_FEEDBACK_OFFSET (float) 0.000
1102 #define BOOST_VOUT_ADC_TRG_DELAY (float)20.0e-9
1103 
1104  // end of group output-voltage-feedback-settings-boost ~~~~~~~~~~~~~~~
1105 
1106 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1118 // Peripheral Assignments
1119 #define BOOST_VOUT_ANSEL _ANSELD10
1120 #define BOOST_VOUT_ADCCORE 8
1121 #define BOOST_VOUT_ADCIN 18
1122 #define BOOST_VOUT_ADCBUF ADCBUF18
1123 #define BOOST_VOUT_ADCTRIG PG2TRIGA
1124 #define BOOST_VOUT_TRGSRC BOOST_PWM_TRGSRC_TRG1
1125 
1126  // end of group output-voltage-feedback-mcal-boost ~~~~~~~~~~~~~~~~~~
1127 
1128 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1140 #define BOOST_VOUT_FEEDBACK_GAIN (float)((BOOST_VOUT_DIV_R2) / (BOOST_VOUT_DIV_R1 + BOOST_VOUT_DIV_R2))
1141 
1142 #define BOOST_VOUT_REF (uint16_t)(BOOST_VOUT_NOMINAL * BOOST_VOUT_FEEDBACK_GAIN / ADC_GRANULARITY)
1143 #define BOOST_VOUT_NOM BOOST_VOUT_REF
1144 #define BOOST_VOUT_DEV_TRIP (uint16_t)(BOOST_VOUT_TOLERANCE_MAX * BOOST_VOUT_FEEDBACK_GAIN / ADC_GRANULARITY)
1145 #define BOOST_VOUT_DEV_RELEASE (uint16_t)(BOOST_VOUT_TOLERANCE_MIN * BOOST_VOUT_FEEDBACK_GAIN / ADC_GRANULARITY)
1146 #define BOOST_VOUT_OVP_TRIP (uint16_t)((BOOST_VOUT_MAXIMUM * BOOST_VOUT_FEEDBACK_GAIN) / ADC_GRANULARITY)
1147 #define BOOST_VOUT_OVP_RELEASE (uint16_t)((BOOST_VOUT_MAXIMUM - BOOST_VOUT_HYSTERESIS) * BOOST_VOUT_FEEDBACK_GAIN / ADC_GRANULARITY)
1148 #define BOOST_VOUT_OFFSET (uint16_t)(BOOST_VOUT_FEEDBACK_OFFSET / ADC_GRANULARITY)
1149 #define BOOST_VOUT_ADC_TRGDLY (uint16_t)(BOOST_VOUT_ADC_TRG_DELAY / PWM_CLOCK_PERIOD)
1150 #define BOOST_VOUT_VFWD_DROP (uint16_t)(BOOST_VOUT_VFWD_DROP_MAX / ADC_GRANULARITY)
1151 
1152 #define BOOST_VOUT_NORM_INV_G (float)(1.0/BOOST_VOUT_FEEDBACK_GAIN)
1153 #define BOOST_VOUT_NORM_SCALER (int16_t)(ceil(log(BOOST_VOUT_NORM_INV_G)/log(2)))
1154 #define BOOST_VOUT_NORM_FACTOR (int16_t)((BOOST_VOUT_NORM_INV_G / pow(2.0, BOOST_VOUT_NORM_SCALER)) * (pow(2.0, 15)-1))
1155 
1156 #define BOOST_VOUT_RANGE_MAX (float)(ADC_REFERENCE * BOOST_VOUT_NORM_INV_G)
1157 
1158  // end of group output-voltage-feedback-macros-boost ~~~~~~~~~~~~~~~~
1159 
1160 
1180 // Feedback Declarations
1181 #define BOOST_ISNS_LSCS 0
1182 #define BOOST_ISNS_AMP 1
1183 
1184 #define BOOST_ISNS_OPTION BOOST_ISNS_LSCS
1185 
1186 // Settings based on the selection made above
1187 #if (BOOST_ISNS_OPTION == BOOST_ISNS_LSCS)
1188 
1189  #define BOOST_ISNS_FEEDBACK_GAIN (float) 1.000
1190  #define BOOST_ISNS_MINIMUM (float)-1.000
1191  #define BOOST_ISNS_MAXIMUM (float) 2.500
1192  #define BOOST_ISNS_RELEASE (float) 1.500
1193  #define BOOST_ISNS_REFERENCE (float) 2.500
1194  #define BOOST_ISNS_REFERENCE_STARTUP (float) 2.500
1195  #define BOOST_ISNS_ADC_TRG_DELAY (float)80.0e-9
1196  #define BOOST_ISNS_FEEDBACK_OFFSET (float) 1.125
1197 
1198  #define BOOST_ISNS_OFFSET_CALIBRATION_ENABLE true
1199 
1200 #elif (BOOST_ISNS_OPTION == BOOST_ISNS_AMP)
1201 
1202  #define BOOST_ISNS_FEEDBACK_GAIN (float) 0.600
1203  #define BOOST_ISNS_MINIMUM (float) 0.000
1204  #define BOOST_ISNS_MAXIMUM (float) 2.500
1205  #define BOOST_ISNS_RELEASE (float) 2.500
1206  #define BOOST_ISNS_REFERENCE (float) 2.500
1207  #define BOOST_ISNS_REFERENCE_STARTUP (float) 2.500
1208  #define BOOST_ISNS_ADC_TRG_DELAY (float) 240.0e-9
1209  #define BOOST_ISNS_FEEDBACK_OFFSET (float) 1.650
1210 
1211  #define BOOST_ISNS_OFFSET_CALIBRATION_ENABLE true
1212 
1213 #endif
1214  // end of group phase-current-feedback-settings-boost ~~~~~~~~~~~~~~~
1216 
1217 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1229 // Phase Current Feedback Settings Conversion Macros
1230 #define BOOST_ISNS_MIN (uint16_t)(int16_t)(((BOOST_ISNS_MINIMUM-BOOST_ISNS_FEEDBACK_OFFSET) * BOOST_ISNS_FEEDBACK_GAIN) / ADC_GRANULARITY)
1231 #define BOOST_ISNS_OCL (uint16_t)(((BOOST_ISNS_MAXIMUM-BOOST_ISNS_FEEDBACK_OFFSET) * BOOST_ISNS_FEEDBACK_GAIN) / ADC_GRANULARITY)
1232 #define BOOST_ISNS_OCL_RELEASE (uint16_t)(((BOOST_ISNS_RELEASE-BOOST_ISNS_FEEDBACK_OFFSET) * BOOST_ISNS_FEEDBACK_GAIN) / ADC_GRANULARITY)
1233 #define BOOST_ISNS_REF (uint16_t)((BOOST_ISNS_REFERENCE * BOOST_ISNS_FEEDBACK_GAIN) / ADC_GRANULARITY)
1234 #define BOOST_ISNS_REF_STARTUP (uint16_t)((BOOST_ISNS_REFERENCE_STARTUP * BOOST_ISNS_FEEDBACK_GAIN) / ADC_GRANULARITY)
1235 #define BOOST_ISNS_FB_OFFSET (uint16_t)(BOOST_ISNS_FEEDBACK_OFFSET / ADC_GRANULARITY)
1236 #define BOOST_ISNS_ADC_TRGDLY (uint16_t)(BOOST_ISNS_ADC_TRG_DELAY / PWM_CLOCK_PERIOD)
1237 
1238 #define BOOST_ISNS_NORM_INV_G (float)(1.0/BOOST_ISNS_FEEDBACK_GAIN)
1239 #define BOOST_ISNS_NORM_SCALER (int16_t)(ceil(log(BOOST_ISNS_NORM_INV_G)/log(2)))
1240 #define BOOST_ISNS_NORM_FACTOR (int16_t)((BOOST_ISNS_NORM_INV_G / pow(2.0, BOOST_ISNS_NORM_SCALER)) * (pow(2.0, 15)-1))
1241 
1242  // end of group phase-current-feedback-macros-boost ~~~~~~~~~~~~~~~~~
1243 
1244 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1256 // Peripheral Assignments
1257 #if (BOOST_ISNS_OPTION == BOOST_ISNS_LSCS)
1258 
1259  #define _BOOST_ISNS_ADCInterrupt _ADCAN1Interrupt
1260  #define _BOOST_ISNS_ADCISR_IF _ADCAN1IF
1261 
1262  #define BOOST_ISNS_ANSEL _ANSELA1
1263  #define BOOST_ISNS_ADCCORE 1
1264  #define BOOST_ISNS_ADCIN 1
1265  #define BOOST_ISNS_ALT_IN_SELECT 0b00
1266  #define BOOST_ISNS_ADCBUF ADCBUF1
1267  #define BOOST_ISNS_ADCTRIG PG2TRIGB
1268  #define BOOST_ISNS_TRGSRC BOOST_PWM_TRGSRC_TRG2
1269 
1270  #define BOOST_ISNS_OPA_INSTANCE 2U
1271 
1272 #elif (BOOST_ISNS_OPTION == BOOST_ISNS_AMP)
1273 
1274  #define _BOOST_ISNS_ADCInterrupt _ADCAN1Interrupt
1275  #define _BOOST_ISNS_ADCISR_IF _ADCAN1IF
1276 
1277  #define BOOST_ISNS_ANSEL _ANSELA1
1278  #define BOOST_ISNS_ADCCORE 1
1279  #define BOOST_ISNS_ADCIN 1
1280  #define BOOST_ISNS_ALT_IN_SELECT 0b00
1281  #define BOOST_ISNS_ADCBUF ADCBUF1
1282  #define BOOST_ISNS_ADCTRIG PG2TRIGB
1283  #define BOOST_ISNS_TRGSRC BOOST_PWM_TRGSRC_TRG2
1284 
1285  #define BOOST_ISNS_OPA_INSTANCE 0U
1286 
1287 #else
1288  #pragma message "hardware abstraction layer warning: no current sense feedback selected."
1289 #endif
1290  // end of group phase-current-feedback-mcal-boost ~~~~~~~~~~~~~~~~~~~
1292 
1293 
1305 #define BOOST_AGC_EXECUTION_DELAY (float)(400.0e-9)
1306 
1307  // end of group adaptive-gain-control-settings-boost ~~~~~~~~~~~~~~~~
1308 
1309 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1320 /* ToDo: AGC is temporarily disabled for the boost converter and requires further verification
1321 
1322 #define BOOST_VL_MINIMUM (float)(BOOST_VIN_UNDER_VOLTAGE) ///< Minimum input voltage - maximum output voltage
1323 #define BOOST_VL_NOMINAL (float)(BOOST_VIN_NOMINAL) ///< Nominal input voltage - nominal output voltage
1324 #define BOOST_VL_MAXIMUM (float)(BOOST_VIN_RANGE_MAX) ///< Maximum input voltage - output voltage = 0V
1325 
1326 // The AGC compare value is defined at nominal input voltage and output voltage
1327 // The maximum modulation factor is normalized to fractional '1' to prevent number overruns
1328 #define BOOST_AGC_FACTOR_MAX (float)(BOOST_VL_NOMINAL / BOOST_VL_MINIMUM) ///< Floating point number of the maximumm limit of the adaptive gain modulation factor (float)
1329 #define BOOST_AGC_NOM_SCALER (uint16_t)(ceil(log(BOOST_AGC_FACTOR_MAX)/log(2))) ///< Bit-shift scaler of the floating point number of the maimum limit of the adaptive gain modulation factor
1330 #define BOOST_AGC_NOM_FACTOR (uint16_t)(0x7FFF >> BOOST_AGC_NOM_SCALER) ///< Fractional of the floating point number of the maimum limit of the adaptive gain modulation factor
1331 #define BOOST_AGC_MEDIAN (int16_t)(((int16_t)(((float)BOOST_VIN_NOM * BOOST_VIN_NORM_FCT) - BOOST_VOUT_NOM))>>BOOST_AGC_NOM_SCALER) ///< Adaptive gain modulation factor at nominal operating point
1332 
1333 // To calculate the voltage across the inductor, input and output voltage ADC results need to be normalized. The normalization factor is determined here
1334 // Each input voltage sample has to be multiplied with this scaling factor to allow the calculation of the instantaneous voltage across the inductor
1335 #define BOOST_VIN_NORM_FCT (float)(BOOST_VOUT_FEEDBACK_GAIN / BOOST_VIN_FEEDBACK_GAIN) ///< VIN-2-VOUT Normalization Factor
1336 #define BOOST_AGC_IO_NORM_SCALER (int16_t)(ceil(log(BOOST_VIN_NORM_FCT)/log(2))) ///< Nominal VL Q15 scaler
1337 #define BOOST_AGC_IO_NORM_FACTOR (int16_t)((BOOST_VIN_NORM_FCT / pow(2.0, BOOST_AGC_IO_NORM_SCALER)) * (pow(2.0, 15)-1)) ///< Nominal VL Q15 factor
1338 
1339 // Additional execution time calculation to be considered in trigger delay and overall control timing
1340 #define BOOST_AGC_EXEC_DLY (uint16_t)(BOOST_AGC_EXECUTION_DELAY / PWM_CLOCK_PERIOD) ///< Macro calculating the integer number equivalent of the AGC algorithm computation time
1341 
1342 */ // end of group adaptive-gain-control-macros-boost ~~~~~~~~~~~~~~~~~~
1344 
1345 
1358 // Hardware-dependent defines
1359 #define BOOST_VOUT_TRIG_PWM 0
1360 #define BOOST_VOUT_TRIG_ADC 1
1361 
1362 #define BOOST_VOUT_TRIGGER_MODE BOOST_VOUT_TRIG_PWM
1363 #define BOOST_VOUT_ISR_PRIORITY 5
1364 
1365 #if (BOOST_VOUT_TRIGGER_MODE == BOOST_VOUT_TRIG_ADC)
1366 
1367  #define _BOOST_VLOOP_Interrupt _ADCAN18Interrupt
1368  #define _BOOST_VLOOP_ISR_IP _ADCAN18IP
1369  #define _BOOST_VLOOP_ISR_IF _ADCAN18IF
1370  #define _BOOST_VLOOP_ISR_IE _ADCAN18IE
1371 
1372 #elif (BOOST_VOUT_TRIGGER_MODE == BOOST_VOUT_TRIG_PWM)
1373 
1374  #define _BOOST_VLOOP_Interrupt _PWM2Interrupt
1375  #define _BOOST_VLOOP_ISR_IP _PWM2IP
1376  #define _BOOST_VLOOP_ISR_IF _PWM2IF
1377  #define _BOOST_VLOOP_ISR_IE _PWM2IE
1378 
1379 #endif
1380  // end of group isr-settings-boost ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1382 
1383 
1420 #define BOOST_POWER_ON_DELAY (float) 200e-3
1421 #define BOOST_VRAMP_PERIOD (float) 100e-3
1422 #define BOOST_IRAMP_PERIOD (float) 100e-3
1423 #define BOOST_POWER_GOOD_DELAY (float) 200e-3
1424 
1425 #define BOOST_CHARGEUP_PERIOD (float) 50e-3
1426 #define BOOST_CHARGEUP_TIMEOUT (float) 200e-3
1427 
1428  // end of group startup-timing-settings-boost ~~~~~~~~~~~~~~~~~~~~~~~
1429 
1430 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1442 #define BOOST_POD (uint16_t)(((float)BOOST_POWER_ON_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
1443 #define BOOST_VRAMP_PER (uint16_t)(((float)BOOST_VRAMP_PERIOD / (float)MAIN_EXECUTION_PERIOD)-1.0)
1444 #define BOOST_VREF_STEP (uint16_t)((float)BOOST_VOUT_REF / (float)(BOOST_VRAMP_PER + 1.0))
1445 #define BOOST_IRAMP_PER (uint16_t)(((float)BOOST_IRAMP_PERIOD / (float)MAIN_EXECUTION_PERIOD)-1.0)
1446 #define BOOST_IREF_STEP (uint16_t)((float)BOOST_ISNS_REF / (float)(BOOST_VRAMP_PER + 1.0))
1447 #define BOOST_PGD (uint16_t)(((float)BOOST_POWER_GOOD_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
1448 #define BOOST_CHRG_PER (uint16_t)(((float)BOOST_CHARGEUP_PERIOD / (float)MAIN_EXECUTION_PERIOD)-1.0)
1449 #define BOOST_CHRG_TOUT (uint16_t)(((float)BOOST_CHARGEUP_TIMEOUT / (float)MAIN_EXECUTION_PERIOD)-1.0)
1450  // end of group startup-timing-macros-boost ~~~~~~~~~~~~~~~~~~~~~~~~~
1452 
1453 
1480 #define BOOST_UVLO_TRIP_DELAY (float) 5e-3
1481 #define BOOST_UVLO_RECOVERY_DELAY (float) 500e-3
1482 #define BOOST_OVLO_TRIP_DELAY (float) 5e-3
1483 #define BOOST_OVLO_RECOVERY_DELAY (float) 500e-3
1484 #define BOOST_REGERR_TRIP_DELAY (float) 25e-3
1485 #define BOOST_REGERR_RECOVERY_DELAY (float)2000e-3
1486 #define BOOST_OCP_TRIP_DELAY (float) 2e-3
1487 #define BOOST_OCP_RECOVERY_DELAY (float)2000e-3
1488 
1489 #define BOOST_FAULT_RESTART_CYCLES 10
1490 
1491  // end of group fault-response-settings-boost ~~~~~~~~~~~~~~~~~~~~~~~
1492 
1493 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1505 #define BOOST_UVLO_TDLY (uint16_t)(((float) BOOST_UVLO_TRIP_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
1506 #define BOOST_UVLO_RDLY (uint16_t)(((float) BOOST_UVLO_RECOVERY_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
1507 #define BOOST_OVLO_TDLY (uint16_t)(((float) BOOST_OVLO_TRIP_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
1508 #define BOOST_OVLO_RDLY (uint16_t)(((float) BOOST_OVLO_RECOVERY_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
1509 #define BOOST_REGERR_TDLY (uint16_t)(((float) BOOST_REGERR_TRIP_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
1510 #define BOOST_REGERR_RDLY (uint16_t)(((float)BOOST_REGERR_RECOVERY_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
1511 #define BOOST_OCP_TDLY (uint16_t)(((float) BOOST_OCP_TRIP_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
1512 #define BOOST_OCP_RDLY (uint16_t)(((float) BOOST_OCP_RECOVERY_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
1513 
1514  // end of group fault-response-macros-boost ~~~~~~~~~~~~~~~~~~~~~~~~~
1515 
1516 
1518 #endif /* INCLUDE_BOOST */
1519 
1520 
1521 
1539 #define TEMP_CAL_ZERO (float) 0.500 // Temperature sense signal zero point voltage in [V]
1540 #define TEMP_CAL_SLOPE (float) 0.010 // Temperature sense signal slope in [V/K]
1541  // end of group temperature-feedback-settings
1543 
1544 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1556 #define TEMP_FB_ZERO (uint16_t)(TEMP_CAL_ZERO / ADC_GRANULARITY)
1557 #define TEMP_FB_SLOPE (float)(TEMP_CAL_SLOPE / ADC_GRANULARITY)
1558  // end of group temperature-feedback-macros
1560 
1561 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1573 #define _TEMP_ADCInterrupt _ADCAN2Interrupt
1574 #define _TEMP_ADCISR_IF _ADCAN2IF
1575 
1576 #define TEMP_ANSEL _ANSELB7
1577 #define TEMP_ADCCORE 8 // 0=Dedicated Core #0, 1=Dedicated Core #1, 8=Shared ADC Core
1578 #define TEMP_ADCIN 2 // Analog input number (e.g. '5' for 'AN5')
1579 #define TEMP_ADCBUF ADCBUF2
1580 #define TEMP_ADCTRIG BUCK_PWM_PGxTRIGB
1581 #define TEMP_TRGSRC BUCK_PWM_TRGSRC_TRG2 // PWM2 Trigger 2 via PG1TRIGB
1582  // end of group temperature-feedback-mcal
1584 
1585 
1586 #if (INCLUDE_LCD == true)
1587 
1589 
1599 #define LCD_SCL_SetHigh() _LATC5 = 1
1600 #define LCD_SCL_SetLow() _LATC5 = 0
1601 #define LCD_SCL_Toggle() _LATC5 ^= 1
1602 #define LCD_SCL_GetValue() _RC5
1603 #define LCD_SCL_SetDigitalInput() _TRISC5 = 1
1604 #define LCD_SCL_SetDigitalOutput() _TRISC5 = 0
1605 
1606 #define LCD_SDI_SetHigh() _LATC4 = 1
1607 #define LCD_SDI_SetLow() _LATC4 = 0
1608 #define LCD_SDI_Toggle() _LATC4 ^= 1
1609 #define LCD_SDI_GetValue() _RC4
1610 #define LCD_SDI_SetDigitalInput() _TRISC4 = 1
1611 #define LCD_SDI_SetDigitalOutput() _TRISC4 = 0
1612 
1613 #define LCD_CS_SetHigh() _LATD8 = 1
1614 #define LCD_CS_SetLow() _LATD8 = 0
1615 #define LCD_CS_Toggle() _LATD8 ^= 1
1616 #define LCD_CS_GetValue() _RD8
1617 #define LCD_CS_SetDigitalInput() _TRISD8 = 1
1618 #define LCD_CS_SetDigitalOutput() _TRISD8 = 0
1619 
1620 #define LCD_RST_SetHigh() _LATC8 = 1
1621 #define LCD_RST_SetLow() _LATC8 = 0
1622 #define LCD_RST_Toggle() _LATC8 ^= 1
1623 #define LCD_RST_GetValue() _RC8
1624 #define LCD_RST_SetDigitalInput() _TRISC8 = 1
1625 #define LCD_RST_SetDigitalOutput() _TRISC8 = 0
1626 
1627 #define LCD_RS_SetHigh() _LATC9 = 1
1628 #define LCD_RS_SetLow() _LATC9 = 0
1629 #define LCD_RS_Toggle() _LATC9 ^= 1
1630 #define LCD_RS_GetValue() _RC9
1631 #define LCD_RS_SetDigitalInput() _TRISC9 = 1
1632 #define LCD_RS_SetDigitalOutput() _TRISC9 = 0
1633  // end of group lcd-interface-declarations
1635  // Doxygen section
1637 #endif /* INCLUDE_LCD */
1638 
1639 #endif /* DPSK3_HARDWARE_DESCRIPTOR_H */
1640 
1641 // end of file