Digital Power Starter Kit 3 Firmware
dsPIC33C Boost 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 #include "config/mcal.h"
40 
41 /* DPSK3 BOARD CIRCUIT SEGMENTS */
42 
43 #define INCLUDE_BUCK false // Include buck converter declarations
44 #define INCLUDE_BOOST true // Include boost converter declarations
45 #define INCLUDE_LCD true // Include LCD declarations
46 
47 /**************************************************************************************************
48  * @ingroup hardware-id-macro
49  * @{
50  * @brief Global macro identifying the hardware version supported by
51  *
52  * @details
53  * This global macro is used to identify the hardware version supported by this hardware
54  * abstraction layer header file.
55  *
56  **************************************************************************************************/
57 
58 #ifndef __DPSK3_R30__
59  #define __DPSK3_R30__
60 #endif
61 
62  // end of group hardware-id-macro
64 
65 /**************************************************************************************************
66  * @ingroup special-options
67  * @{
68  * @brief Global defines used to enable/disable special firmware options
69  *
70  * @details
71  * This section is used to enable/disable special options useful during development, debugging,
72  * troubleshooting the recent firmware or to tailor special functions of this application.
73  *
74  **************************************************************************************************/
75 
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 /**************************************************************************************************
87  * @ingroup device-abstraction-settings
88  * @{
89  * @brief Fundamental microcontroller device settings
90  *
91  * @details
92  * This section is used to define device specific parameters like ADC reference and
93  * resolution, main execution clock frequency and peripheral time base settings.
94  * All parameters are defined using physical quantities.
95  *
96  **************************************************************************************************/
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) ///< Instruction period
126 //#define ADC_GRANULARITY (float)(ADC_REFERENCE / pow(2.0, ADC_RESOLUTION)) ///< ADC granularity in [V/tick]
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) ///< PWM Clock Period in [sec]
129  // end of group device-abstraction-macros
131 
132 /**************************************************************************************************
133  * @ingroup state-machine-settings
134  * @{
135  * @brief Global state-machine user-settings
136  *
137  * @details
138  * This section is used to set, modify, enable or disable common state machine parameters
139  * and features.
140  *
141  * (Please see individual settings description for detail)
142  *
143  **************************************************************************************************/
144 
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 /***************************************************************************************************
183  * @ingroup circuit-gpio-mcal
184  * @{
185  * @brief Global abstraction labels of special circuit signal device pin assignments
186  *
187  * @details
188  * This section is used to define labels of hardware specific signals, which are directly
189  * assigned to specific device pins. These labels will be used throughout the code and remain
190  * unchanged even if this firmware is migrated to another device or pin-out changes between
191  * hardware revisions.
192  *
193  **************************************************************************************************/
194 
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 #define DBGLED_ON 1U
228 #define DBGLED_OFF 0U
229 
230 // Power Good Output
231 #define PWRGOOD_PORT 1
232 #define PWRGOOD_PIN 12
233 #define PWRGOOD_Get() { _RB12; }
234 #define PWRGOOD_Set() { _LATB12 = 1; }
235 #define PWRGOOD_Clear() { _LATB12 = 0; }
236 #define PWRGOOD_Toggle() { _LATB12 ^= 1; }
237 #define PWRGOOD_Init() { _LATB12 = 0; _TRISB12 = 0; }
238 #define PWRGOOD_Dispose() { _LATB12 = 1; _TRISB12 = 1; }
239 
240 // User Switch Input
241 #define SW_USER_PORT 3
242 #define SW_USER_PIN 1
243 #define SW_USER_Get() _RD1
244 #define SW_USER_Set() { _LATD1 = 1; }
245 #define SW_USER_Clear() { _LATD1 = 0; }
246 #define SW_USER_Toggle() { _LATD1 ^= 1; }
247 #define SW_USER_Init() { _LATD1 = 1; _TRISD1 = 1; }
248 #define SW_USER_Dispose() { _LATD1 = 1; _TRISD1 = 1; }
249 
250  // end of group circuit-gpio-mcal
252 
253 /**************************************************************************************************
254  * @ingroup circuit-peripheral-mcal
255  * @{
256  * @brief Special Function chip resources declarations
257  *
258  * @details
259  * Some applications may require additional chip resources, which are not supported by
260  * default library modules used in this project. For static configurations, these chip
261  * resources are initialized in function \ref sysUserPeriperhals_Initialize during system
262  * startup. Any specific declarations required for abstracting hardware or microcontroller
263  * features is placed in this section
264  *
265  **************************************************************************************************/
266 
267 #define DAC_OUTPUT_INSTANCE 1U
268 #define DAC_BUFFER_OPA_INSTANCE 3U
269 #define DAC_OUTPUT_INIT_VALUE 0U
270 
271 
272 #if (DAC_OUTPUT_INSTANCE == 1U)
273  #define DACOUT_Set(x) { DAC1DATH=x; }
274  #define DACOUT_Get() DAC1DATH
275 #elif (DAC_OUTPUT_INSTANCE == 2U)
276  #define DACOUT_Set(x) { DAC2DATH=x; }
277  #define DACOUT_Get() DAC2DATH
278 #elif (DAC_OUTPUT_INSTANCE == 3U)
279  #define DACOUT_Set(x) { DAC3DATH=x; }
280  #define DACOUT_Get() DAC3DATH
281 #endif
282  // end of group circuit-peripheral-mcal
284 
285 
286 #if (INCLUDE_BUCK == true)
287 
289 /**************************************************************************************************
290  * @ingroup pwm-settings-buck
291  * @{
292  * @brief User-declaration of global defines for PWM signal generator settings
293  *
294  * @details
295  * This section defines fundamental PWM settings required for the on-board buck converter of DPSK3.
296  * These settings are determined by hardware and defined using physical quantities. Pre-compiler
297  * macros are used to convert physical values into binary (integer) numbers to be written to
298  * Special Function Registers (SFR).
299  *
300  **************************************************************************************************/
301 
302 #define BUCK_NO_OF_PHASES 1U
303 
304 #define BUCK_SWITCHING_FREQUENCY (float)500.0e+3
305 #define BUCK_PWM_DUTY_CYCLE_MIN (float) 0.010
306 #define BUCK_PWM_DUTY_CYCLE_MAX (float) 0.900
307 #define BUCK_LEADING_EDGE_BLANKING (float)120.0e-9
308 #define BUCK_DEAD_TIME_LEADING_EDGE (float) 20.0e-9
309 #define BUCK_DEAD_TIME_FALLING_EDGE (float) 60.0e-9
310 
311  // end of group pwm-settings-buck ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
312 
327 #define BUCK_PWM_CHANNEL 1U
328 #define BUCK_PWM_GPIO_INSTANCE 1U
329 #define BUCK_PWM_GPIO_PORT_PINH 14U
330 #define BUCK_PWM_GPIO_PORT_PINL 15U
331 #define BUCK_PWM_OUTPUT_SWAP false
332 
333 #define BUCK_PWM_PDC PG1DC
334 #define BUCK_PWMH_TRIS _TRISB14
335 #define BUCK_PWMH_WR _LATB14
336 #define BUCK_PWMH_RD _RB14
337 #define BUCK_PWMH_RPx (uint8_t)46
338 #define BUCK_PWML_TRIS _TRISB15
339 #define BUCK_PWML_WR _LATB15
340 #define BUCK_PWML_RD _RB15
341 #define BUCK_PWML_RPx (uint8_t)47
342 
343 #define _BUCK_PWM_Interrupt _PWM1Interrupt
344 #define BUCK_PWM_IF _PWM1IF
345 #define BUCK_PWM_IE _PWM1IE
346 #define BUCK_PWM_IP _PWM1IP
347 #define BUCK_PWM_TRGSRC_TRG1 0b00100
348 #define BUCK_PWM_TRGSRC_TRG2 0b00101
349 #define BUCK_PWM_PGxTRIGA PG1TRIGA
350 #define BUCK_PWM_PGxTRIGB PG1TRIGB
351 #define BUCK_PWM_PGxTRIGC PG1TRIGC
352 
353 #define BUCK_PWM_ADTR1OFS 0U
354 #define BUCK_PWM_ADTR1PS 0U
355 
356 #define BUCK_PWM_UPDREQ PG1STATbits.UPDREQ
357  // end of group pwm-mcal-buck ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
359 
360 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
372 // Conversion Macros
373 #define BUCK_SWITCHING_PERIOD (float)(1.0/BUCK_SWITCHING_FREQUENCY)
374 #define BUCK_PWM_PERIOD (uint16_t)(float)(BUCK_SWITCHING_PERIOD / PWM_CLOCK_PERIOD)
375 #define BUCK_PWM_PHASE_SHIFT (uint16_t)((float)BUCK_PWM_PERIOD / (float)BUCK_NO_OF_PHASES)
376 #define BUCK_PWM_DC_MIN (uint16_t)(BUCK_PWM_DUTY_CYCLE_MIN * (float)BUCK_PWM_PERIOD)
377 #define BUCK_PWM_DC_MAX (uint16_t)(BUCK_PWM_DUTY_CYCLE_MAX * (float)BUCK_PWM_PERIOD)
378 #define BUCK_LEB_PERIOD (uint16_t)(BUCK_LEADING_EDGE_BLANKING / (float)PWM_CLOCK_PERIOD)
379 #define BUCK_PWM_DEAD_TIME_LE (uint16_t)(BUCK_DEAD_TIME_LEADING_EDGE / (float)PWM_CLOCK_PERIOD)
380 #define BUCK_PWM_DEAD_TIME_FE (uint16_t)(BUCK_DEAD_TIME_FALLING_EDGE / (float)PWM_CLOCK_PERIOD)
381 
382  // end of group pwm-macros-buck ~~~~~~~~~~~~~~~~~
383 
384 
385 /**************************************************************************************************
386  * @ingroup input-voltage-feedback-settings-buck
387  * @{
388  * @brief Declaration of input voltage feedback properties
389  *
390  * @details
391  * In this section the output voltage feedback signal scaling, gain, valid signal limits and nominal
392  * operating point is specified. Physical quantities are used to define values. Macros are used to
393  * convert given physical values into binary (integer) number to be written into SFRs and variables.
394  * *************************************************************************************************/
395 
396 // Feedback Declarations
397 #define BUCK_VIN_MINIMUM (float) 6.500
398 #define BUCK_VIN_NOMINAL (float) 9.000
399 #define BUCK_VIN_MAXIMUM (float)13.800
400 
401 #define BUCK_VIN_UNDER_VOLTAGE (float) 6.000
402 #define BUCK_VIN_OVER_VOLTAGE (float)14.300
403 #define BUCK_VIN_HYSTERESIS (float) 1.000
404 
405 #define BUCK_VIN_R1 (float) 6.980
406 #define BUCK_VIN_R2 (float) 1.000
407 
408 #define BUCK_VIN_FEEDBACK_OFFSET (float) 0.0000
409 #define BUCK_VIN_ADC_TRG_DELAY (float) 20.0e-9
410 
411  // end of group input-voltage-feedback-settings-buck ~~~~~~~~~~~~~~~~
412 
413 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
425 // Peripheral Assignments
426 #define _BUCK_VIN_ADCInterrupt _ADCAN12Interrupt
427 #define _BUCK_VIN_ADCISR_IF _ADCAN12IF
428 
429 #define BUCK_VIN_ANSEL _ANSELC0
430 #define BUCK_VIN_ADCCORE 8
431 #define BUCK_VIN_ADCIN 12
432 #define BUCK_VIN_ADCBUF ADCBUF12
433 #define BUCK_VIN_ADCTRIG PG1TRIGB
434 #define BUCK_VIN_TRGSRC BUCK_PWM_TRGSRC_TRG2
435 
436  // end of group input-voltage-feedback-mcal-buck ~~~~~~~~~~~~~~~~~~~~
437 
438 
439 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
451 #define BUCK_VIN_FEEDBACK_GAIN (float)((BUCK_VIN_R2) / (BUCK_VIN_R1 + BUCK_VIN_R2)) // DO NOT CHANGE
452 #define BUCK_VIN_MIN (uint16_t)(BUCK_VIN_MINIMUM * BUCK_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
453 #define BUCK_VIN_NOM (uint16_t)(BUCK_VIN_NOMINAL * BUCK_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
454 #define BUCK_VIN_MAX (uint16_t)(BUCK_VIN_MAXIMUM * BUCK_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
455 #define BUCK_VIN_HYST (uint16_t)(BUCK_VIN_HYSTERESIS * BUCK_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
456 #define BUCK_VIN_UVLO_TRIP (uint16_t)(BUCK_VIN_UNDER_VOLTAGE * BUCK_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
457 #define BUCK_VIN_UVLO_RELEASE (uint16_t)((BUCK_VIN_UNDER_VOLTAGE + BUCK_VIN_HYSTERESIS) * BUCK_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
458 #define BUCK_VIN_OVLO_TRIP (uint16_t)(BUCK_VIN_OVER_VOLTAGE * BUCK_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
459 #define BUCK_VIN_OVLO_RELEASE (uint16_t)((BUCK_VIN_OVER_VOLTAGE - BUCK_VIN_HYSTERESIS) * BUCK_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
460 #define BUCK_VIN_ADC_TRGDLY (uint16_t)(BUCK_VIN_ADC_TRG_DELAY / PWM_CLOCK_PERIOD)
461 #define BUCK_VIN_OFFSET (uint16_t)(BUCK_VIN_FEEDBACK_OFFSET / ADC_GRANULARITY)
462 
463 #define BUCK_VIN_NORM_INV_G (float)(1.0/BUCK_VIN_FEEDBACK_GAIN)
464 #define BUCK_VIN_NORM_SCALER (int16_t)(ceil(log(BUCK_VIN_NORM_INV_G)/log(2)))
465 #define BUCK_VIN_NORM_FACTOR (int16_t)((BUCK_VIN_NORM_INV_G / pow(2.0, BUCK_VIN_NORM_SCALER)) * (pow(2.0, 15)-1))
466 
467 #define BUCK_VIN_RANGE_MAX (float)(ADC_REFERENCE * BUCK_VIN_NORM_INV_G)
468  // end of group input-voltage-feedback-macros-buck ~~~~~~~~~~~~~~~~~~
470 
471 /**************************************************************************************************
472  * @ingroup output-voltage-feedback-settings-buck
473  * @{
474  * @brief Declaration of output voltage feedback properties
475  *
476  * @details
477  * In this section the output voltage feedback signal scaling, gain, valid signal limits and nominal
478  * operating point is specified. Physical quantities are used to define values. Macros are used to
479  * convert given physical values into binary (integer) number to be written into SFRs and variables.
480  * *************************************************************************************************/
481 
482 // Feedback Declarations
483 #define BUCK_VOUT_MINIMUM (float) 0.000
484 #define BUCK_VOUT_NOMINAL (float) 3.300
485 #define BUCK_VOUT_MAXIMUM (float) 4.000
486 #define BUCK_VOUT_HYSTERESIS (float) 0.500
487 
488 #define BUCK_VOUT_TOLERANCE_MAX (float) 0.200
489 #define BUCK_VOUT_TOLERANCE_MIN (float) 0.100
490 
491 #define BUCK_VOUT_DIV_R1 (float) 1.000
492 #define BUCK_VOUT_DIV_R2 (float) 1.000
493 #define BUCK_VOUT_FEEDBACK_OFFSET (float) 0.000
494 #define BUCK_VOUT_ADC_TRG_DELAY (float)20.0e-9
495 
496  // end of group output-voltage-feedback-settings-buck ~~~~~~~~~~~~~~~
497 
498 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
510 // Peripheral Assignments
511 #define BUCK_VOUT_ANSEL _ANSELC1
512 #define BUCK_VOUT_ADCCORE 8
513 #define BUCK_VOUT_ADCIN 13
514 #define BUCK_VOUT_ADCBUF ADCBUF13
515 #define BUCK_VOUT_ADCTRIG PG1TRIGA
516 #define BUCK_VOUT_TRGSRC BUCK_PWM_TRGSRC_TRG1
517 
518  // end of group output-voltage-feedback-mcal-buck ~~~~~~~~~~~~~~~~~~~
519 
520 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
532 #define BUCK_VOUT_FEEDBACK_GAIN (float)((BUCK_VOUT_DIV_R2) / (BUCK_VOUT_DIV_R1 + BUCK_VOUT_DIV_R2))
533 
534 #define BUCK_VOUT_REF (uint16_t)(BUCK_VOUT_NOMINAL * BUCK_VOUT_FEEDBACK_GAIN / ADC_GRANULARITY)
535 #define BUCK_VOUT_NOM (uint16_t) BUCK_VOUT_REF
536 #define BUCK_VOUT_DEV_TRIP (uint16_t)((BUCK_VOUT_TOLERANCE_MAX * BUCK_VOUT_FEEDBACK_GAIN) / ADC_GRANULARITY)
537 #define BUCK_VOUT_DEV_RELEASE (uint16_t)((BUCK_VOUT_TOLERANCE_MIN * BUCK_VOUT_FEEDBACK_GAIN) / ADC_GRANULARITY)
538 #define BUCK_VOUT_OVP_TRIP (uint16_t)((BUCK_VOUT_MAXIMUM * BUCK_VOUT_FEEDBACK_GAIN) / ADC_GRANULARITY)
539 #define BUCK_VOUT_OVP_RELEASE (uint16_t)((BUCK_VOUT_MAXIMUM - BUCK_VOUT_HYSTERESIS) * BUCK_VOUT_FEEDBACK_GAIN / ADC_GRANULARITY)
540 #define BUCK_VOUT_OFFSET (uint16_t)(BUCK_VOUT_FEEDBACK_OFFSET / ADC_GRANULARITY)
541 #define BUCK_VOUT_ADC_TRGDLY (uint16_t)(BUCK_VOUT_ADC_TRG_DELAY / PWM_CLOCK_PERIOD)
542 
543 #define BUCK_VOUT_NORM_INV_G (float)(1.0/BUCK_VOUT_FEEDBACK_GAIN)
544 #define BUCK_VOUT_NORM_SCALER (int16_t)(ceil(log(BUCK_VOUT_NORM_INV_G)/log(2)))
545 #define BUCK_VOUT_NORM_FACTOR (int16_t)((BUCK_VOUT_NORM_INV_G / pow(2.0, BUCK_VOUT_NORM_SCALER)) * (pow(2.0, 15)-1))
546 
547 #define BUCK_VOUT_RANGE_MAX (float)(ADC_REFERENCE * BUCK_VOUT_NORM_INV_G)
548 
549  // end of group output-voltage-feedback-macros-buck ~~~~~~~~~~~~~~~~~
550 
551 /**************************************************************************************************
552  * @ingroup phase-current-feedback-settings-buck
553  * @{
554  * @brief Declaration of phase-current feedback properties
555  *
556  * @details
557  * In this section the phase-current feedback signal scaling, gain, valid signal limits and nominal
558  * operating point is specified. Physical quantities are used to define parameter values to ease
559  * the system configuration.
560  *
561  * As DPSK3 supports two different current sense devices (current sense transformers and shunt
562  * amplifier devices) users can select which one should be used for regulating the output current.
563  * Based on the selection made, the appropriate feedback channels and signal scaling values will be
564  * used by the firmware.
565  *
566  * Macros are used to convert given physical values into binary (integer) number to be written
567  * into SFRs and variables and being used in runtime calculations.
568  * (see \ref phase-current-feedback-macros-buck for details)
569  * *************************************************************************************************/
570 
571 // Feedback Declarations
572 #define BUCK_ISNS_CT 0
573 #define BUCK_ISNS_AMP 1
574 
575 #define BUCK_ISNS_OPTION BUCK_ISNS_CT
576 
577 // Settings based on the selection made above
578 #if (BUCK_ISNS_OPTION == BUCK_ISNS_CT)
579 
580  #define BUCK_ISNS_FEEDBACK_GAIN (float) 1.000
581  #define BUCK_ISNS_MINIMUM (float)-1.000
582  #define BUCK_ISNS_MAXIMUM (float) 2.500
583  #define BUCK_ISNS_RELEASE (float) 2.000
584  #define BUCK_ISNS_REFERENCE (float) 2.000
585  #define BUCK_ISNS_ADC_TRG_DELAY (float) 80.0e-9
586  #define BUCK_ISNS_FEEDBACK_OFFSET (float) 0.000
587 
588  #define BUCK_ISNS_OFFSET_CALIBRATION_ENABLE false
589 
590 #elif (BUCK_ISNS_OPTION == BUCK_ISNS_AMP)
591 
592  #define BUCK_ISNS_FEEDBACK_GAIN (float) 0.600
593  #define BUCK_ISNS_MINIMUM (float) 0.000
594  #define BUCK_ISNS_MAXIMUM (float) 2.500
595  #define BUCK_ISNS_RELEASE (float) 2.500
596  #define BUCK_ISNS_REFERENCE (float) 2.500
597  #define BUCK_ISNS_ADC_TRG_DELAY (float) 240.0e-9
598  #define BUCK_ISNS_FEEDBACK_OFFSET (float) 1.650
599 
600  #define BUCK_ISNS_OFFSET_CALIBRATION_ENABLE true
601 
602 #endif
603  // end of group phase-current-feedback-settings-buck ~~~~~~~~~~~~~~~~
605 
606 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
618 // Phase Current Feedback Settings Conversion Macros
619 #define BUCK_ISNS_MIN (uint16_t)(int16_t)(((BUCK_ISNS_MINIMUM-BUCK_ISNS_FEEDBACK_OFFSET) * BUCK_ISNS_FEEDBACK_GAIN) / ADC_GRANULARITY)
620 #define BUCK_ISNS_OCL (uint16_t)(((BUCK_ISNS_MAXIMUM-BUCK_ISNS_FEEDBACK_OFFSET) * BUCK_ISNS_FEEDBACK_GAIN) / ADC_GRANULARITY)
621 #define BUCK_ISNS_OCL_RELEASE (uint16_t)(((BUCK_ISNS_RELEASE-BUCK_ISNS_FEEDBACK_OFFSET) * BUCK_ISNS_FEEDBACK_GAIN) / ADC_GRANULARITY)
622 #define BUCK_ISNS_REF (uint16_t)((BUCK_ISNS_REFERENCE * BUCK_ISNS_FEEDBACK_GAIN) / ADC_GRANULARITY)
623 #define BUCK_ISNS_FB_OFFSET (uint16_t)(BUCK_ISNS_FEEDBACK_OFFSET / ADC_GRANULARITY)
624 #define BUCK_ISNS_ADC_TRGDLY (uint16_t)(BUCK_ISNS_ADC_TRG_DELAY / PWM_CLOCK_PERIOD)
625 
626 #define BUCK_ISNS_NORM_INV_G (float)(1.0/BUCK_ISNS_FEEDBACK_GAIN)
627 #define BUCK_ISNS_NORM_SCALER (int16_t)(ceil(log(BUCK_ISNS_NORM_INV_G)/log(2)))
628 #define BUCK_ISNS_NORM_FACTOR (int16_t)((BUCK_ISNS_NORM_INV_G / pow(2.0, BUCK_ISNS_NORM_SCALER)) * (pow(2.0, 15)-1))
629 
630  // end of group phase-current-feedback-macros ~~~~~~~~~~~~~~~~~~~~~~~
631 
632 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
644 // Peripheral Assignments
645 #if (BUCK_ISNS_OPTION == BUCK_ISNS_CT)
646 
647  #define _BUCK_ISNS_ADCInterrupt _ADCAN0Interrupt
648  #define _BUCK_ISNS_ADCISR_IF _ADCAN0IF
649 
650  #define BUCK_ISNS_ANSEL _ANSELA0
651  #define BUCK_ISNS_ADCCORE 0
652  #define BUCK_ISNS_ADCIN 0
653  #define BUCK_ISNS_ALT_IN_SELECT 0b00
654  #define BUCK_ISNS_ADCBUF ADCBUF0
655  #define BUCK_ISNS_ADCTRIG PG1TRIGB
656  #define BUCK_ISNS_TRGSRC BUCK_PWM_TRGSRC_TRG2
657 
658 #elif (BUCK_ISNS_OPTION == BUCK_ISNS_AMP)
659 
660  #define _BUCK_ISNS_ADCInterrupt _ADCAN1Interrupt
661  #define _BUCK_ISNS_ADCISR_IF _ADCAN1IF
662 
663  #define BUCK_ISNS_ANSEL _ANSELA1
664  #define BUCK_ISNS_ADCCORE 1
665  #define BUCK_ISNS_ADCIN 1
666  #define BUCK_ISNS_ALT_IN_SELECT 0b01
667  #define BUCK_ISNS_ADCBUF ADCBUF1
668  #define BUCK_ISNS_ADCTRIG PG1TRIGB
669  #define BUCK_ISNS_TRGSRC BUCK_PWM_TRGSRC_TRG2
670 
671 #else
672  #pragma message "hardware abstraction layer warning: no current sense feedback selected."
673 #endif
674  // end of group phase-current-feedback-mcal-buck ~~~~~~~~~~~~~~~~~~~~
676 
677 /**************************************************************************************************
678  * @ingroup adaptive-gain-control-settings-buck
679  * @{
680  * @brief Declaration of additional hardware-specific defines required for adaptive gain control
681  *
682  * @details
683  * In this section additional macros are defined to calculate constant parameters for the
684  * adaptive gain modulation algorithm using user defined settings declared in their respective
685  * sections. Any change of these parameters will also result in a change of the values of the
686  * gain modulation parameters of this section.
687  * *************************************************************************************************/
688 
689 #define BUCK_AGC_EXECUTION_DELAY (float)(370.0e-9)
690 
691  // end of group adaptive-gain-control-settings-buck ~~~~~~~~~~~~~~~~~
692 
693 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
705 #define BUCK_VL_MINIMUM (float)(BUCK_VIN_UNDER_VOLTAGE - BUCK_VOUT_MAXIMUM)
706 #define BUCK_VL_NOMINAL (float)(BUCK_VIN_NOMINAL - BUCK_VOUT_NOMINAL)
707 #define BUCK_VL_MAXIMUM (float)(BUCK_VIN_RANGE_MAX - 0)
708 
709 // The AGC compare value is defined at nominal input voltage and output voltage
710 // The maximum modulation factor is normalized to fractional '1' to prevent number overruns
711 #define BUCK_AGC_FACTOR_MAX (float)(BUCK_VL_NOMINAL / BUCK_VL_MINIMUM)
712 #define BUCK_AGC_NOM_SCALER (uint16_t)(ceil(log(BUCK_AGC_FACTOR_MAX)/log(2)))
713 #define BUCK_AGC_NOM_FACTOR (uint16_t)(0x7FFF >> BUCK_AGC_NOM_SCALER)
714 #define BUCK_AGC_MEDIAN (int16_t)(((int16_t)(((float)BUCK_VIN_NOM * BUCK_VIN_NORM_FCT) - BUCK_VOUT_NOM))>>BUCK_AGC_NOM_SCALER)
715 
716 // To calculate the voltage across the inductor, input and output voltage ADC results need to be normalized. The normalization factor is determined here
717 // Each input voltage sample has to be multiplied with this scaling factor to allow the calculation of the instantaneous voltage across the inductor
718 #define BUCK_VIN_NORM_FCT (float)(BUCK_VOUT_FEEDBACK_GAIN / BUCK_VIN_FEEDBACK_GAIN)
719 #define BUCK_AGC_IO_NORM_SCALER (int16_t)(ceil(log(BUCK_VIN_NORM_FCT)/log(2)))
720 #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))
721 
722 // Additional execution time calculation to be considered in trigger delay and overall control timing
723 #define BUCK_AGC_EXEC_DLY (uint16_t)(BUCK_AGC_EXECUTION_DELAY / PWM_CLOCK_PERIOD)
724 
725  // end of group adaptive-gain-control-macros-buck ~~~~~~~~~~~~~~~~~~~
726 
727 /**************************************************************************************************
728  * @ingroup isr-settings-buck
729  * @{
730  * @brief Control loop Interrupt Vector Settings
731  *
732  * @details
733  * Control loops are called in dedicated interrupt service routines of PWM events, ADC events
734  * or triggered by timers. This section allows users to set and modify the interrupt service
735  * routine triggers and their priority to set up and optimize the control system interrupt
736  * structure.
737  *
738  * *************************************************************************************************/
739 
740 // Hardware-dependent defines
741 #define BUCK_VOUT_TRIG_PWM 0
742 #define BUCK_VOUT_TRIG_ADC 1
743 
744 #define BUCK_VOUT_TRIGGER_MODE BUCK_VOUT_TRIG_PWM
745 #define BUCK_VOUT_ISR_PRIORITY 5
746 
747 #if (BUCK_VOUT_TRIGGER_MODE == BUCK_VOUT_TRIG_ADC)
748 
749  #define _BUCK_VLOOP_Interrupt _ADCAN13Interrupt
750  #define _BUCK_VLOOP_ISR_IP _ADCAN13IP
751  #define _BUCK_VLOOP_ISR_IF _ADCAN13IF
752  #define _BUCK_VLOOP_ISR_IE _ADCAN13IE
753 
754 #elif (BUCK_VOUT_TRIGGER_MODE == BUCK_VOUT_TRIG_PWM)
755 
756  #define _BUCK_VLOOP_Interrupt _PWM1Interrupt
757  #define _BUCK_VLOOP_ISR_IP _PWM1IP
758  #define _BUCK_VLOOP_ISR_IF _PWM1IF
759  #define _BUCK_VLOOP_ISR_IE _PWM1IE
760 
761 #endif
762  // end of group isr-settings-buck ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
764 
765 /**************************************************************************************************
766  * @ingroup startup-timing-settings-buck
767  * @{
768  * @brief Global defines for soft-start specific parameters
769  *
770  * @details
771  * This section is used to define power supply startup timing settings. The soft-start sequence
772  * is part of the power controller. It allows to program specific timings for
773  * - Power On Delay
774  * - Ramp Period
775  * - Power Good Delay
776  *
777  * After the startup has passed these three timing periods, the power supply is ending up in
778  * "normal" operation, continuously regulating the output until a fault is detected or the
779  * operating state is changed for any other reason. When the output voltage reference is changed,
780  * the power control state machine will use the voltage ramp slope defined here to tune from the
781  * recent voltage reference to the new reference value. During this period the BUSY-bit of the
782  * power controller (status word, bit #7) will be set. This status bit will be cleared automatically
783  * by the power controller state machine once the new reference value has been applied and the
784  * converter is back in constant regulation mode.
785  *
786  * Pre-compiler macros are used to translate physical values into binary (integer) numbers to
787  * be written to SFRs and variables.
788  * (see \ref startup-timing-macros-buck for details)
789  *
790  * @note
791  * On DPSK3 it takes roughly 500 ms until the auxiliary power has been started, the
792  * PIC24 housekeeping controller on the bottom side of the board resets the protection
793  * logic and allows the dsPIC to run. After this period the dsPIC controller starts to
794  * execute its firmware.
795  *
796  * This additional startup delay of ~500 ms is not considered in the settings below and
797  * needs to be taken into account when adjusting startup timing. Use an independent debugging
798  * pin toggle at the beginning of the firmware to verify the specified startup timing is
799  * applied as desired.
800  **************************************************************************************************/
801 
802 #define BUCK_POWER_ON_DELAY (float) 200e-3
803 #define BUCK_VRAMP_PERIOD (float) 100e-3
804 #define BUCK_IRAMP_PERIOD (float) 100e-3
805 #define BUCK_POWER_GOOD_DELAY (float) 200e-3
806 
807  // end of group startup-timing-settings ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
808 
809 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
821 #define BUCK_POD (uint16_t)(((float)BUCK_POWER_ON_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
822 #define BUCK_VRAMP_PER (uint16_t)(((float)BUCK_VRAMP_PERIOD / (float)MAIN_EXECUTION_PERIOD)-1.0)
823 #define BUCK_VREF_STEP (uint16_t)((float)BUCK_VOUT_REF / (float)(BUCK_VRAMP_PER + 1.0))
824 #define BUCK_IRAMP_PER (uint16_t)(((float)BUCK_IRAMP_PERIOD / (float)MAIN_EXECUTION_PERIOD)-1.0)
825 #define BUCK_IREF_STEP (uint16_t)((float)BUCK_ISNS_REF / (float)(BUCK_VRAMP_PER + 1.0))
826 #define BUCK_PGD (uint16_t)(((float)BUCK_POWER_GOOD_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
827  // end of group startup-timing-macros-buck ~~~~~~~~~~~~~~~~~~~~~~~~~~
829 
830 /**************************************************************************************************
831  * @ingroup fault-response-settings-buck
832  * @{
833  * @brief Global defines for fault-monitor related parameters
834  *
835  * @details
836  * This section is used to define power supply fault object timing settings. The fault monitor
837  * is continuously monitoring declared data objects at the high-priority task frequency defined by
838  * \ref MAIN_EXECUTION_PERIOD. Based on this known interval, filtering delays for fault trip and
839  * fault recovery events to allow users to adjust the fault detection sensitivity.
840  *
841  * - Fault Trip Event Delay
842  * This setting defines for how long a fault condition has to be continuously active before the
843  * effective fault trip status/event will be triggered.
844  *
845  * - Fault Recovery Event Delay
846  * This setting defines for how long a fault condition has to be continuously cleared before the
847  * effective fault recovery status/event will be triggered.
848  *
849  * - Restart Cycle Limit
850  * In case of a persistent fault condition (e.g continuous short circuit or unstable feedback loop)
851  * the fault monitor will limit the number of restart attempts specified by FAULT_RESTART_CYCLES.
852  * When this threshold is exceeded, the power supply will latch in save state (off) and a CPU or
853  * power cycle is required to start-up the power supply again.
854  *
855  *************************************************************************************************/
856 
857 #define BUCK_UVLO_TRIP_DELAY (float) 5e-3
858 #define BUCK_UVLO_RECOVERY_DELAY (float) 500e-3
859 #define BUCK_OVLO_TRIP_DELAY (float) 5e-3
860 #define BUCK_OVLO_RECOVERY_DELAY (float) 500e-3
861 #define BUCK_REGERR_TRIP_DELAY (float) 25e-3
862 #define BUCK_REGERR_RECOVERY_DELAY (float) 2000e-3
863 #define BUCK_OCP_TRIP_DELAY (float) 2e-3
864 #define BUCK_OCP_RECOVERY_DELAY (float) 2000e-3
865 
866 #define BUCK_FAULT_RESTART_CYCLES 10
867 
868  // end of group fault-response-settings-buck ~~~~~~~~~~~~~~~~~~~~~~~~
869 
870 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
882 #define BUCK_UVLO_TDLY (uint16_t)(((float) BUCK_UVLO_TRIP_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
883 #define BUCK_UVLO_RDLY (uint16_t)(((float) BUCK_UVLO_RECOVERY_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
884 #define BUCK_OVLO_TDLY (uint16_t)(((float) BUCK_OVLO_TRIP_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
885 #define BUCK_OVLO_RDLY (uint16_t)(((float) BUCK_OVLO_RECOVERY_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
886 #define BUCK_REGERR_TDLY (uint16_t)(((float) BUCK_REGERR_TRIP_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
887 #define BUCK_REGERR_RDLY (uint16_t)(((float)BUCK_REGERR_RECOVERY_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
888 #define BUCK_OCP_TDLY (uint16_t)(((float) BUCK_OCP_TRIP_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
889 #define BUCK_OCP_RDLY (uint16_t)(((float) BUCK_OCP_RECOVERY_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
890 
891  // end of group fault-response-macros-buck ~~~~~~~~~~~~~~~~~~~~~~~~~~
892  // Doxygen section
894 #endif /* INCLUDE_BUCK */
895 
896 #if (INCLUDE_BOOST == true)
897 
899 /**************************************************************************************************
900  * @ingroup pwm-settings-boost
901  * @{
902  * @brief User-declaration of global defines for PWM signal generator settings
903  *
904  * @details
905  * This section defines fundamental PWM settings required for the on-board boost converter of DPSK3.
906  * These settings are determined by hardware and defined using physical quantities. Pre-compiler
907  * macros are used to convert physical values into binary (integer) numbers to be written to
908  * Special Function Registers (SFR).
909  *
910  **************************************************************************************************/
911 
912 #define BOOST_NO_OF_PHASES 1U
913 
914 #define BOOST_SWITCHING_FREQUENCY (float)500.0e+3
915 #define BOOST_PWM_DUTY_CYCLE_MIN (float) 0.030
916 #define BOOST_PWM_DUTY_CYCLE_MAX (float) 0.900
917 #define BOOST_LEADING_EDGE_BLANKING (float)120.0e-9
918 #define BOOST_DEAD_TIME_LEADING_EDGE (float) 0.0e-9
919 #define BOOST_DEAD_TIME_FALLING_EDGE (float) 0.0e-9
920 
921  // end of group pwm-settings-boost ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
922 
937 #define BOOST_PWM_CHANNEL 2U
938 #define BOOST_PWM_GPIO_INSTANCE 1U
939 #define BOOST_PWM_GPIO_PORT_PINH 13U
940 #define BOOST_PWM_GPIO_PORT_PINL 12U
941 #define BOOST_PWM_OUTPUT_SWAP true
942 
943 #define BOOST_PWM_PDC PG2DC
944 #define BOOST_PWMH_TRIS _TRISB12
945 #define BOOST_PWMH_WR _LATB12
946 #define BOOST_PWMH_RD _RB12
947 #define BOOST_PWMH_RPx (uint8_t)44
948 #define BOOST_PWML_TRIS _TRISB13
949 #define BOOST_PWML_WR _LATB13
950 #define BOOST_PWML_RD _RB13
951 #define BOOST_PWML_RPx (uint8_t)45
952 
953 #define _BOOST_PWM_Interrupt _PWM2Interrupt
954 #define BOOST_PWM_IF _PWM2IF
955 #define BOOST_PWM_IE _PWM2IE
956 #define BOOST_PWM_IP _PWM2IP
957 #define BOOST_PWM_TRGSRC_TRG1 0b00110
958 #define BOOST_PWM_TRGSRC_TRG2 0b00111
959 #define BOOST_PWM_PGxTRIGA PG2TRIGA
960 #define BOOST_PWM_PGxTRIGB PG2TRIGB
961 #define BOOST_PWM_PGxTRIGC PG2TRIGC
962 
963 #define BOOST_PWM_ADTR1OFS 0U
964 #define BOOST_PWM_ADTR1PS 0U
965 
966 #define BOOST_PWM_UPDREQ PG2STATbits.UPDREQ
967  // end of group pwm-mcal-boost ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
969 
970 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
982 // Conversion Macros
983 #define BOOST_SWITCHING_PERIOD (float)(1.0/BOOST_SWITCHING_FREQUENCY)
984 #define BOOST_PWM_PERIOD (uint16_t)(float)(BOOST_SWITCHING_PERIOD / PWM_CLOCK_PERIOD)
985 #define BOOST_PWM_PHASE_SHIFT (uint16_t)((float)BOOST_PWM_PERIOD / (float)BOOST_NO_OF_PHASES)
986 #define BOOST_PWM_DC_MIN (uint16_t)(BOOST_PWM_DUTY_CYCLE_MIN * (float)BOOST_PWM_PERIOD)
987 #define BOOST_PWM_DC_MAX (uint16_t)(BOOST_PWM_DUTY_CYCLE_MAX * (float)BOOST_PWM_PERIOD)
988 #define BOOST_LEB_PERIOD (uint16_t)(BOOST_LEADING_EDGE_BLANKING / (float)PWM_CLOCK_PERIOD)
989 #define BOOST_PWM_DEAD_TIME_LE (uint16_t)(BOOST_DEAD_TIME_LEADING_EDGE / (float)PWM_CLOCK_PERIOD)
990 #define BOOST_PWM_DEAD_TIME_FE (uint16_t)(BOOST_DEAD_TIME_FALLING_EDGE / (float)PWM_CLOCK_PERIOD)
991 
992  // end of group pwm-macros-boost ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
993 
994 
995 /**************************************************************************************************
996  * @ingroup input-voltage-feedback-settings-boost
997  * @{
998  * @brief Declaration of input voltage feedback properties
999  *
1000  * @details
1001  * In this section the output voltage feedback signal scaling, gain, valid signal limits and nominal
1002  * operating point is specified. Physical quantities are used to define values. Macros are used to
1003  * convert given physical values into binary (integer) number to be written into SFRs and variables.
1004  * *************************************************************************************************/
1005 
1006 // Feedback Declarations
1007 #define BOOST_VIN_MINIMUM (float) 6.500
1008 #define BOOST_VIN_NOMINAL (float) 9.000
1009 #define BOOST_VIN_MAXIMUM (float)13.800
1010 
1011 #define BOOST_VIN_UNDER_VOLTAGE (float) 6.000
1012 #define BOOST_VIN_OVER_VOLTAGE (float)14.300
1013 #define BOOST_VIN_HYSTERESIS (float) 1.000
1014 
1015 #define BOOST_VIN_R1 (float) 6.980
1016 #define BOOST_VIN_R2 (float) 1.000
1017 
1018 #define BOOST_VIN_FEEDBACK_OFFSET (float) 0.0000
1019 #define BOOST_VIN_ADC_TRG_DELAY (float)20.0e-9
1020 
1021  // end of group input-voltage-feedback-settings-boost ~~~~~~~~~~~~~~~
1022 
1023 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1035 // Peripheral Assignments
1036 #define _BOOST_VIN_ADCInterrupt _ADCAN12Interrupt
1037 #define _BOOST_VIN_ADCISR_IF _ADCAN12IF
1038 
1039 #define BOOST_VIN_ANSEL _ANSELC0
1040 #define BOOST_VIN_ADCCORE 8
1041 #define BOOST_VIN_ADCIN 12
1042 #define BOOST_VIN_ADCBUF ADCBUF12
1043 #define BOOST_VIN_ADCTRIG PG2TRIGB
1044 #define BOOST_VIN_TRGSRC BOOST_PWM_TRGSRC_TRG2
1045 
1046  // end of group input-voltage-feedback-mcal-boost ~~~~~~~~~~~~~~~~~~~
1047 
1048 
1049 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1061 #define BOOST_VIN_FEEDBACK_GAIN (float)((BOOST_VIN_R2) / (BOOST_VIN_R1 + BOOST_VIN_R2)) // DO NOT CHANGE
1062 #define BOOST_VIN_MIN (uint16_t)(BOOST_VIN_MINIMUM * BOOST_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
1063 #define BOOST_VIN_NOM (uint16_t)(BOOST_VIN_NOMINAL * BOOST_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
1064 #define BOOST_VIN_MAX (uint16_t)(BOOST_VIN_MAXIMUM * BOOST_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
1065 #define BOOST_VIN_HYST (uint16_t)(BOOST_VIN_HYSTERESIS * BOOST_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
1066 #define BOOST_VIN_UVLO_TRIP (uint16_t)(BOOST_VIN_UNDER_VOLTAGE * BOOST_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
1067 #define BOOST_VIN_UVLO_RELEASE (uint16_t)((BOOST_VIN_UNDER_VOLTAGE + BOOST_VIN_HYSTERESIS) * BOOST_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
1068 #define BOOST_VIN_OVLO_TRIP (uint16_t)(BOOST_VIN_OVER_VOLTAGE * BOOST_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
1069 #define BOOST_VIN_OVLO_RELEASE (uint16_t)((BOOST_VIN_OVER_VOLTAGE - BOOST_VIN_HYSTERESIS) * BOOST_VIN_FEEDBACK_GAIN / ADC_GRANULARITY)
1070 #define BOOST_VIN_ADC_TRGDLY (uint16_t)(BOOST_VIN_ADC_TRG_DELAY / PWM_CLOCK_PERIOD)
1071 #define BOOST_VIN_OFFSET (uint16_t)(BOOST_VIN_FEEDBACK_OFFSET / ADC_GRANULARITY)
1072 
1073 #define BOOST_VIN_NORM_INV_G (float)(1.0/BOOST_VIN_FEEDBACK_GAIN)
1074 #define BOOST_VIN_NORM_SCALER (int16_t)(ceil(log(BOOST_VIN_NORM_INV_G)/log(2)))
1075 #define BOOST_VIN_NORM_FACTOR (int16_t)((BOOST_VIN_NORM_INV_G / pow(2.0, BOOST_VIN_NORM_SCALER)) * (pow(2.0, 15)-1))
1076 
1077 #define BOOST_VIN_RANGE_MAX (float)(ADC_REFERENCE * BOOST_VIN_NORM_INV_G)
1078  // end of group input-voltage-feedback-macros-boost ~~~~~~~~~~~~~~~~~
1080 
1081 /**************************************************************************************************
1082  * @ingroup output-voltage-feedback-settings-boost
1083  * @{
1084  * @brief Declaration of output voltage feedback properties
1085  *
1086  * @details
1087  * In this section the output voltage feedback signal scaling, gain, valid signal limits and nominal
1088  * operating point is specified. Physical quantities are used to define values. Macros are used to
1089  * convert given physical values into binary (integer) number to be written into SFRs and variables.
1090  * *************************************************************************************************/
1091 
1092 // Feedback Declarations
1093 #define BOOST_VOUT_MINIMUM (float)14.00
1094 #define BOOST_VOUT_NOMINAL (float)15.00
1095 #define BOOST_VOUT_MAXIMUM (float)16.00
1096 #define BOOST_VOUT_HYSTERESIS (float)0.500
1097 
1098 #define BOOST_VOUT_TOLERANCE_MAX (float)0.300
1099 #define BOOST_VOUT_TOLERANCE_MIN (float)0.100
1100 #define BOOST_VOUT_VFWD_DROP_MAX (float)0.400
1101 
1102 #define BOOST_VOUT_DIV_R1 (float) 6.980
1103 #define BOOST_VOUT_DIV_R2 (float) 1.000
1104 #define BOOST_VOUT_FEEDBACK_OFFSET (float) 0.000
1105 #define BOOST_VOUT_ADC_TRG_DELAY (float)20.0e-9
1106 
1107  // end of group output-voltage-feedback-settings-boost ~~~~~~~~~~~~~~~
1108 
1109 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1121 // Peripheral Assignments
1122 #define BOOST_VOUT_ANSEL _ANSELD10
1123 #define BOOST_VOUT_ADCCORE 8
1124 #define BOOST_VOUT_ADCIN 18
1125 #define BOOST_VOUT_ADCBUF ADCBUF18
1126 #define BOOST_VOUT_ADCTRIG PG2TRIGA
1127 #define BOOST_VOUT_TRGSRC BOOST_PWM_TRGSRC_TRG1
1128 
1129  // end of group output-voltage-feedback-mcal-boost ~~~~~~~~~~~~~~~~~~
1130 
1131 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1143 #define BOOST_VOUT_FEEDBACK_GAIN (float)((BOOST_VOUT_DIV_R2) / (BOOST_VOUT_DIV_R1 + BOOST_VOUT_DIV_R2))
1144 
1145 #define BOOST_VOUT_REF (uint16_t)(BOOST_VOUT_NOMINAL * BOOST_VOUT_FEEDBACK_GAIN / ADC_GRANULARITY)
1146 #define BOOST_VOUT_NOM BOOST_VOUT_REF
1147 #define BOOST_VOUT_DEV_TRIP (uint16_t)(BOOST_VOUT_TOLERANCE_MAX * BOOST_VOUT_FEEDBACK_GAIN / ADC_GRANULARITY)
1148 #define BOOST_VOUT_DEV_RELEASE (uint16_t)(BOOST_VOUT_TOLERANCE_MIN * BOOST_VOUT_FEEDBACK_GAIN / ADC_GRANULARITY)
1149 #define BOOST_VOUT_OVP_TRIP (uint16_t)((BOOST_VOUT_MAXIMUM * BOOST_VOUT_FEEDBACK_GAIN) / ADC_GRANULARITY)
1150 #define BOOST_VOUT_OVP_RELEASE (uint16_t)((BOOST_VOUT_MAXIMUM - BOOST_VOUT_HYSTERESIS) * BOOST_VOUT_FEEDBACK_GAIN / ADC_GRANULARITY)
1151 #define BOOST_VOUT_OFFSET (uint16_t)(BOOST_VOUT_FEEDBACK_OFFSET / ADC_GRANULARITY)
1152 #define BOOST_VOUT_ADC_TRGDLY (uint16_t)(BOOST_VOUT_ADC_TRG_DELAY / PWM_CLOCK_PERIOD)
1153 #define BOOST_VOUT_VFWD_DROP (uint16_t)(BOOST_VOUT_VFWD_DROP_MAX / ADC_GRANULARITY)
1154 
1155 #define BOOST_VOUT_NORM_INV_G (float)(1.0/BOOST_VOUT_FEEDBACK_GAIN)
1156 #define BOOST_VOUT_NORM_SCALER (int16_t)(ceil(log(BOOST_VOUT_NORM_INV_G)/log(2)))
1157 #define BOOST_VOUT_NORM_FACTOR (int16_t)((BOOST_VOUT_NORM_INV_G / pow(2.0, BOOST_VOUT_NORM_SCALER)) * (pow(2.0, 15)-1))
1158 
1159 #define BOOST_VOUT_RANGE_MAX (float)(ADC_REFERENCE * BOOST_VOUT_NORM_INV_G)
1160 
1161  // end of group output-voltage-feedback-macros-boost ~~~~~~~~~~~~~~~~
1162 
1163 /**************************************************************************************************
1164  * @ingroup phase-current-feedback-settings-boost
1165  * @{
1166  * @brief Declaration of phase-current feedback properties
1167  *
1168  * @details
1169  * In this section the phase-current feedback signal scaling, gain, valid signal limits and nominal
1170  * operating point is specified. Physical quantities are used to define parameter values to ease
1171  * the system configuration.
1172  *
1173  * As DPSK3 supports two different current sense devices (current sense transformers and shunt
1174  * amplifier devices) users can select which one should be used for regulating the output current.
1175  * Based on the selection made, the appropriate feedback channels and signal scaling values will be
1176  * used by the firmware.
1177  *
1178  * Macros are used to convert given physical values into binary (integer) number to be written
1179  * into SFRs and variables and being used in runtime calculations.
1180  * (see \ref phase-current-feedback-macros-boost for details)
1181  * *************************************************************************************************/
1182 
1183 // Feedback Declarations
1184 #define BOOST_ISNS_LSCS 0
1185 #define BOOST_ISNS_AMP 1
1186 
1187 #define BOOST_ISNS_OPTION BOOST_ISNS_LSCS
1188 
1189 // Settings based on the selection made above
1190 #if (BOOST_ISNS_OPTION == BOOST_ISNS_LSCS)
1191 
1192  #define BOOST_ISNS_FEEDBACK_GAIN (float) 1.000
1193  #define BOOST_ISNS_MINIMUM (float)-1.000
1194  #define BOOST_ISNS_MAXIMUM (float) 2.500
1195  #define BOOST_ISNS_RELEASE (float) 1.500
1196  #define BOOST_ISNS_REFERENCE (float) 2.500
1197  #define BOOST_ISNS_REFERENCE_STARTUP (float) 2.500
1198  #define BOOST_ISNS_ADC_TRG_DELAY (float)80.0e-9
1199  #define BOOST_ISNS_FEEDBACK_OFFSET (float) 1.125
1200 
1201  #define BOOST_ISNS_OFFSET_CALIBRATION_ENABLE true
1202 
1203 #elif (BOOST_ISNS_OPTION == BOOST_ISNS_AMP)
1204 
1205  #define BOOST_ISNS_FEEDBACK_GAIN (float) 0.600
1206  #define BOOST_ISNS_MINIMUM (float) 0.000
1207  #define BOOST_ISNS_MAXIMUM (float) 2.500
1208  #define BOOST_ISNS_RELEASE (float) 2.500
1209  #define BOOST_ISNS_REFERENCE (float) 2.500
1210  #define BOOST_ISNS_REFERENCE_STARTUP (float) 2.500
1211  #define BOOST_ISNS_ADC_TRG_DELAY (float) 240.0e-9
1212  #define BOOST_ISNS_FEEDBACK_OFFSET (float) 1.650
1213 
1214  #define BOOST_ISNS_OFFSET_CALIBRATION_ENABLE true
1215 
1216 #endif
1217  // end of group phase-current-feedback-settings-boost ~~~~~~~~~~~~~~~
1219 
1220 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1232 // Phase Current Feedback Settings Conversion Macros
1233 #define BOOST_ISNS_MIN (uint16_t)(int16_t)(((BOOST_ISNS_MINIMUM-BOOST_ISNS_FEEDBACK_OFFSET) * BOOST_ISNS_FEEDBACK_GAIN) / ADC_GRANULARITY)
1234 #define BOOST_ISNS_OCL (uint16_t)(((BOOST_ISNS_MAXIMUM-BOOST_ISNS_FEEDBACK_OFFSET) * BOOST_ISNS_FEEDBACK_GAIN) / ADC_GRANULARITY)
1235 #define BOOST_ISNS_OCL_RELEASE (uint16_t)(((BOOST_ISNS_RELEASE-BOOST_ISNS_FEEDBACK_OFFSET) * BOOST_ISNS_FEEDBACK_GAIN) / ADC_GRANULARITY)
1236 #define BOOST_ISNS_REF (uint16_t)((BOOST_ISNS_REFERENCE * BOOST_ISNS_FEEDBACK_GAIN) / ADC_GRANULARITY)
1237 #define BOOST_ISNS_REF_STARTUP (uint16_t)((BOOST_ISNS_REFERENCE_STARTUP * BOOST_ISNS_FEEDBACK_GAIN) / ADC_GRANULARITY)
1238 #define BOOST_ISNS_FB_OFFSET (uint16_t)(BOOST_ISNS_FEEDBACK_OFFSET / ADC_GRANULARITY)
1239 #define BOOST_ISNS_ADC_TRGDLY (uint16_t)(BOOST_ISNS_ADC_TRG_DELAY / PWM_CLOCK_PERIOD)
1240 
1241 #define BOOST_ISNS_NORM_INV_G (float)(1.0/BOOST_ISNS_FEEDBACK_GAIN)
1242 #define BOOST_ISNS_NORM_SCALER (int16_t)(ceil(log(BOOST_ISNS_NORM_INV_G)/log(2)))
1243 #define BOOST_ISNS_NORM_FACTOR (int16_t)((BOOST_ISNS_NORM_INV_G / pow(2.0, BOOST_ISNS_NORM_SCALER)) * (pow(2.0, 15)-1))
1244 
1245  // end of group phase-current-feedback-macros-boost ~~~~~~~~~~~~~~~~~
1246 
1247 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1259 // Peripheral Assignments
1260 #if (BOOST_ISNS_OPTION == BOOST_ISNS_LSCS)
1261 
1262  #define _BOOST_ISNS_ADCInterrupt _ADCAN1Interrupt
1263  #define _BOOST_ISNS_ADCISR_IF _ADCAN1IF
1264 
1265  #define BOOST_ISNS_ANSEL _ANSELA1
1266  #define BOOST_ISNS_ADCCORE 1
1267  #define BOOST_ISNS_ADCIN 1
1268  #define BOOST_ISNS_ALT_IN_SELECT 0b00
1269  #define BOOST_ISNS_ADCBUF ADCBUF1
1270  #define BOOST_ISNS_ADCTRIG PG2TRIGB
1271  #define BOOST_ISNS_TRGSRC BOOST_PWM_TRGSRC_TRG2
1272 
1273  #define BOOST_ISNS_OPA_INSTANCE 2U
1274 
1275 #elif (BOOST_ISNS_OPTION == BOOST_ISNS_AMP)
1276 
1277  #define _BOOST_ISNS_ADCInterrupt _ADCAN1Interrupt
1278  #define _BOOST_ISNS_ADCISR_IF _ADCAN1IF
1279 
1280  #define BOOST_ISNS_ANSEL _ANSELA1
1281  #define BOOST_ISNS_ADCCORE 1
1282  #define BOOST_ISNS_ADCIN 1
1283  #define BOOST_ISNS_ALT_IN_SELECT 0b00
1284  #define BOOST_ISNS_ADCBUF ADCBUF1
1285  #define BOOST_ISNS_ADCTRIG PG2TRIGB
1286  #define BOOST_ISNS_TRGSRC BOOST_PWM_TRGSRC_TRG2
1287 
1288  #define BOOST_ISNS_OPA_INSTANCE 0U
1289 
1290 #else
1291  #pragma message "hardware abstraction layer warning: no current sense feedback selected."
1292 #endif
1293  // end of group phase-current-feedback-mcal-boost ~~~~~~~~~~~~~~~~~~~
1295 
1296 /**************************************************************************************************
1297  * @ingroup adaptive-gain-control-settings-boost
1298  * @{
1299  * @brief Declaration of additional hardware-specific defines required for adaptive gain control
1300  *
1301  * @details
1302  * In this section additional macros are defined to calculate constant parameters for the
1303  * adaptive gain modulation algorithm using user defined settings declared in their respective
1304  * sections. Any change of these parameters will also result in a change of the values of the
1305  * gain modulation parameters of this section.
1306  * *************************************************************************************************/
1307 
1308 #define BOOST_AGC_EXECUTION_DELAY (float)(400.0e-9)
1309 
1310  // end of group adaptive-gain-control-settings-boost ~~~~~~~~~~~~~~~~
1311 
1312 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1323 /* ToDo: AGC is temporarily disabled for the boost converter and requires further verification
1324 
1325 #define BOOST_VL_MINIMUM (float)(BOOST_VIN_UNDER_VOLTAGE) ///< Minimum input voltage - maximum output voltage
1326 #define BOOST_VL_NOMINAL (float)(BOOST_VIN_NOMINAL) ///< Nominal input voltage - nominal output voltage
1327 #define BOOST_VL_MAXIMUM (float)(BOOST_VIN_RANGE_MAX) ///< Maximum input voltage - output voltage = 0V
1328 
1329 // The AGC compare value is defined at nominal input voltage and output voltage
1330 // The maximum modulation factor is normalized to fractional '1' to prevent number overruns
1331 #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)
1332 #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
1333 #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
1334 #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
1335 
1336 // To calculate the voltage across the inductor, input and output voltage ADC results need to be normalized. The normalization factor is determined here
1337 // Each input voltage sample has to be multiplied with this scaling factor to allow the calculation of the instantaneous voltage across the inductor
1338 #define BOOST_VIN_NORM_FCT (float)(BOOST_VOUT_FEEDBACK_GAIN / BOOST_VIN_FEEDBACK_GAIN) ///< VIN-2-VOUT Normalization Factor
1339 #define BOOST_AGC_IO_NORM_SCALER (int16_t)(ceil(log(BOOST_VIN_NORM_FCT)/log(2))) ///< Nominal VL Q15 scaler
1340 #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
1341 
1342 // Additional execution time calculation to be considered in trigger delay and overall control timing
1343 #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
1344 
1345 */ // end of group adaptive-gain-control-macros-boost ~~~~~~~~~~~~~~~~~~
1347 
1348 /**************************************************************************************************
1349  * @ingroup isr-settings-boost
1350  * @{
1351  * @brief Control loop Interrupt Vector Settings
1352  *
1353  * @details
1354  * Control loops are called in dedicated interrupt service routines of PWM events, ADC events
1355  * or triggered by timers. This section allows users to set and modify the interrupt service
1356  * routine triggers and their priority to set up and optimize the control system interrupt
1357  * structure.
1358  *
1359  * *************************************************************************************************/
1360 
1361 // Hardware-dependent defines
1362 #define BOOST_VOUT_TRIG_PWM 0
1363 #define BOOST_VOUT_TRIG_ADC 1
1364 
1365 #define BOOST_VOUT_TRIGGER_MODE BOOST_VOUT_TRIG_PWM
1366 #define BOOST_VOUT_ISR_PRIORITY 5
1367 
1368 #if (BOOST_VOUT_TRIGGER_MODE == BOOST_VOUT_TRIG_ADC)
1369 
1370  #define _BOOST_VLOOP_Interrupt _ADCAN18Interrupt
1371  #define _BOOST_VLOOP_ISR_IP _ADCAN18IP
1372  #define _BOOST_VLOOP_ISR_IF _ADCAN18IF
1373  #define _BOOST_VLOOP_ISR_IE _ADCAN18IE
1374 
1375 #elif (BOOST_VOUT_TRIGGER_MODE == BOOST_VOUT_TRIG_PWM)
1376 
1377  #define _BOOST_VLOOP_Interrupt _PWM2Interrupt
1378  #define _BOOST_VLOOP_ISR_IP _PWM2IP
1379  #define _BOOST_VLOOP_ISR_IF _PWM2IF
1380  #define _BOOST_VLOOP_ISR_IE _PWM2IE
1381 
1382 #endif
1383  // end of group isr-settings-boost ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1385 
1386 /**************************************************************************************************
1387  * @ingroup startup-timing-settings-boost
1388  * @{
1389  * @brief Global defines for soft-start specific parameters
1390  *
1391  * @details
1392  * This section is used to define power supply startup timing settings. The soft-start sequence
1393  * is part of the power controller. It allows to program specific timings for
1394  * - Power On Delay
1395  * - Ramp Period
1396  * - Power Good Delay
1397  *
1398  * After the startup has passed these three timing periods, the power supply is ending up in
1399  * "normal" operation, continuously regulating the output until a fault is detected or the
1400  * operating state is changed for any other reason. When the output voltage reference is changed,
1401  * the power control state machine will use the voltage ramp slope defined here to tune from the
1402  * recent voltage reference to the new reference value. During this period the BUSY-bit of the
1403  * power controller (status word, bit #7) will be set. This status bit will be cleared automatically
1404  * by the power controller state machine once the new reference value has been applied and the
1405  * converter is back in constant regulation mode.
1406  *
1407  * Pre-compiler macros are used to translate physical values into binary (integer) numbers to
1408  * be written to SFRs and variables.
1409  * (see \ref startup-timing-macros-boost for details)
1410  *
1411  * @note
1412  * On DPSK3 it takes roughly 500 ms until the auxiliary power has been started, the
1413  * PIC24 housekeeping controller on the bottom side of the board resets the protection
1414  * logic and allows the dsPIC to run. After this period the dsPIC controller starts to
1415  * execute its firmware.
1416  *
1417  * This additional startup delay of ~500 ms is not considered in the settings below and
1418  * needs to be taken into account when adjusting startup timing. Use an independent debugging
1419  * pin toggle at the beginning of the firmware to verify the specified startup timing is
1420  * applied as desired.
1421  **************************************************************************************************/
1422 
1423 #define BOOST_POWER_ON_DELAY (float) 200e-3
1424 #define BOOST_VRAMP_PERIOD (float) 100e-3
1425 #define BOOST_IRAMP_PERIOD (float) 100e-3
1426 #define BOOST_POWER_GOOD_DELAY (float) 200e-3
1427 
1428 #define BOOST_CHARGEUP_PERIOD (float) 50e-3
1429 #define BOOST_CHARGEUP_TIMEOUT (float) 200e-3
1430 
1431  // end of group startup-timing-settings-boost ~~~~~~~~~~~~~~~~~~~~~~~
1432 
1433 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1445 #define BOOST_POD (uint16_t)(((float)BOOST_POWER_ON_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
1446 #define BOOST_VRAMP_PER (uint16_t)(((float)BOOST_VRAMP_PERIOD / (float)MAIN_EXECUTION_PERIOD)-1.0)
1447 #define BOOST_VREF_STEP (uint16_t)((float)BOOST_VOUT_REF / (float)(BOOST_VRAMP_PER + 1.0))
1448 #define BOOST_IRAMP_PER (uint16_t)(((float)BOOST_IRAMP_PERIOD / (float)MAIN_EXECUTION_PERIOD)-1.0)
1449 #define BOOST_IREF_STEP (uint16_t)((float)BOOST_ISNS_REF / (float)(BOOST_VRAMP_PER + 1.0))
1450 #define BOOST_PGD (uint16_t)(((float)BOOST_POWER_GOOD_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
1451 #define BOOST_CHRG_PER (uint16_t)(((float)BOOST_CHARGEUP_PERIOD / (float)MAIN_EXECUTION_PERIOD)-1.0)
1452 #define BOOST_CHRG_TOUT (uint16_t)(((float)BOOST_CHARGEUP_TIMEOUT / (float)MAIN_EXECUTION_PERIOD)-1.0)
1453  // end of group startup-timing-macros-boost ~~~~~~~~~~~~~~~~~~~~~~~~~
1455 
1456 /**************************************************************************************************
1457  * @ingroup fault-response-settings-boost
1458  * @{
1459  * @brief Global defines for fault-monitor related parameters
1460  *
1461  * @details
1462  * This section is used to define power supply fault object timing settings. The fault monitor
1463  * is continuously monitoring declared data objects at the high-priority task frequency defined by
1464  * \ref MAIN_EXECUTION_PERIOD. Based on this known interval, filtering delays for fault trip and
1465  * fault recovery events to allow users to adjust the fault detection sensitivity.
1466  *
1467  * - Fault Trip Event Delay
1468  * This setting defines for how long a fault condition has to be continuously active before the
1469  * effective fault trip status/event will be triggered.
1470  *
1471  * - Fault Recovery Event Delay
1472  * This setting defines for how long a fault condition has to be continuously cleared before the
1473  * effective fault recovery status/event will be triggered.
1474  *
1475  * - Restart Cycle Limit
1476  * In case of a persistent fault condition (e.g continuous short circuit or unstable feedback loop)
1477  * the fault monitor will limit the number of restart attempts specified by FAULT_RESTART_CYCLES.
1478  * When this threshold is exceeded, the power supply will latch in save state (off) and a CPU or
1479  * power cycle is required to start-up the power supply again.
1480  *
1481  *************************************************************************************************/
1482 
1483 #define BOOST_UVLO_TRIP_DELAY (float) 5e-3
1484 #define BOOST_UVLO_RECOVERY_DELAY (float) 500e-3
1485 #define BOOST_OVLO_TRIP_DELAY (float) 5e-3
1486 #define BOOST_OVLO_RECOVERY_DELAY (float) 500e-3
1487 #define BOOST_REGERR_TRIP_DELAY (float) 25e-3
1488 #define BOOST_REGERR_RECOVERY_DELAY (float)2000e-3
1489 #define BOOST_OCP_TRIP_DELAY (float) 2e-3
1490 #define BOOST_OCP_RECOVERY_DELAY (float)2000e-3
1491 
1492 #define BOOST_FAULT_RESTART_CYCLES 10
1493 
1494  // end of group fault-response-settings-boost ~~~~~~~~~~~~~~~~~~~~~~~
1495 
1496 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1508 #define BOOST_UVLO_TDLY (uint16_t)(((float) BOOST_UVLO_TRIP_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
1509 #define BOOST_UVLO_RDLY (uint16_t)(((float) BOOST_UVLO_RECOVERY_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
1510 #define BOOST_OVLO_TDLY (uint16_t)(((float) BOOST_OVLO_TRIP_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
1511 #define BOOST_OVLO_RDLY (uint16_t)(((float) BOOST_OVLO_RECOVERY_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
1512 #define BOOST_REGERR_TDLY (uint16_t)(((float) BOOST_REGERR_TRIP_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
1513 #define BOOST_REGERR_RDLY (uint16_t)(((float)BOOST_REGERR_RECOVERY_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
1514 #define BOOST_OCP_TDLY (uint16_t)(((float) BOOST_OCP_TRIP_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
1515 #define BOOST_OCP_RDLY (uint16_t)(((float) BOOST_OCP_RECOVERY_DELAY / (float)MAIN_EXECUTION_PERIOD)-1.0)
1516 
1517  // end of group fault-response-macros-boost ~~~~~~~~~~~~~~~~~~~~~~~~~
1518 
1519 
1521 #endif /* INCLUDE_BOOST */
1522 
1523 
1524 /**************************************************************************************************
1525  * @ingroup temperature-feedback-settings
1526  * @{
1527  * @brief Declaration of temperature feedback properties
1528  *
1529  * @details
1530  * In this section the temperature feedback signal scaling, gain and valid signal limits are
1531  * specified. Physical quantities are used to define parameter values to ease the system
1532  * configuration.
1533  *
1534  * As DPSK3 has one, central on-board temperature sensor between the load resistor banks
1535  * indicating the worst case system temperature.
1536  *
1537  * Macros are used to convert given physical values into binary (integer) number to be written
1538  * into SFRs and variables and being used in runtime calculations.
1539  * (see \ref temperature-feedback-macros for details)
1540  * *************************************************************************************************/
1541 
1542 #define TEMP_CAL_ZERO (float) 0.500 // Temperature sense signal zero point voltage in [V]
1543 #define TEMP_CAL_SLOPE (float) 0.010 // Temperature sense signal slope in [V/K]
1544  // end of group temperature-feedback-settings
1546 
1547 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1559 #define TEMP_FB_ZERO (uint16_t)(TEMP_CAL_ZERO / ADC_GRANULARITY)
1560 #define TEMP_FB_SLOPE (float)(TEMP_CAL_SLOPE / ADC_GRANULARITY)
1561  // end of group temperature-feedback-macros
1563 
1564 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1576 #define _TEMP_ADCInterrupt _ADCAN2Interrupt
1577 #define _TEMP_ADCISR_IF _ADCAN2IF
1578 
1579 #define TEMP_ANSEL _ANSELB7
1580 #define TEMP_ADCCORE 8 // 0=Dedicated Core #0, 1=Dedicated Core #1, 8=Shared ADC Core
1581 #define TEMP_ADCIN 2 // Analog input number (e.g. '5' for 'AN5')
1582 #define TEMP_ADCBUF ADCBUF2
1583 #define TEMP_ADCTRIG BOOST_PWM_PGxTRIGB
1584 #define TEMP_TRGSRC BOOST_PWM_TRGSRC_TRG2 // PWM2 Trigger 2 via PG1TRIGB
1585  // end of group temperature-feedback-mcal
1587 
1588 
1589 #if (INCLUDE_LCD == true)
1590 
1592 /**************************************************************************************************
1593  * @ingroup lcd-interface-declarations
1594  * @{
1595  * @brief LC Display Interface Declarations
1596  * @details
1597  * The LCD device driver is controlling the on-board LC display via a SPI interface. The required
1598  * SPI interface device pin assignments are declared here.
1599  *
1600  * *************************************************************************************************/
1601 
1602 #define LCD_SCL_SetHigh() _LATC5 = 1
1603 #define LCD_SCL_SetLow() _LATC5 = 0
1604 #define LCD_SCL_Toggle() _LATC5 ^= 1
1605 #define LCD_SCL_GetValue() _RC5
1606 #define LCD_SCL_SetDigitalInput() _TRISC5 = 1
1607 #define LCD_SCL_SetDigitalOutput() _TRISC5 = 0
1608 
1609 #define LCD_SDI_SetHigh() _LATC4 = 1
1610 #define LCD_SDI_SetLow() _LATC4 = 0
1611 #define LCD_SDI_Toggle() _LATC4 ^= 1
1612 #define LCD_SDI_GetValue() _RC4
1613 #define LCD_SDI_SetDigitalInput() _TRISC4 = 1
1614 #define LCD_SDI_SetDigitalOutput() _TRISC4 = 0
1615 
1616 #define LCD_CS_SetHigh() _LATD8 = 1
1617 #define LCD_CS_SetLow() _LATD8 = 0
1618 #define LCD_CS_Toggle() _LATD8 ^= 1
1619 #define LCD_CS_GetValue() _RD8
1620 #define LCD_CS_SetDigitalInput() _TRISD8 = 1
1621 #define LCD_CS_SetDigitalOutput() _TRISD8 = 0
1622 
1623 #define LCD_RST_SetHigh() _LATC8 = 1
1624 #define LCD_RST_SetLow() _LATC8 = 0
1625 #define LCD_RST_Toggle() _LATC8 ^= 1
1626 #define LCD_RST_GetValue() _RC8
1627 #define LCD_RST_SetDigitalInput() _TRISC8 = 1
1628 #define LCD_RST_SetDigitalOutput() _TRISC8 = 0
1629 
1630 #define LCD_RS_SetHigh() _LATC9 = 1
1631 #define LCD_RS_SetLow() _LATC9 = 0
1632 #define LCD_RS_Toggle() _LATC9 ^= 1
1633 #define LCD_RS_GetValue() _RC9
1634 #define LCD_RS_SetDigitalInput() _TRISC9 = 1
1635 #define LCD_RS_SetDigitalOutput() _TRISC9 = 0
1636  // end of group lcd-interface-declarations
1638  // Doxygen section
1640 #endif /* INCLUDE_LCD */
1641 
1642 #endif /* DPSK3_HARDWARE_DESCRIPTOR_H */
1643 
1644 // end of file