|  | Dual Active Bridge Development Board (Part-No. ) |
Content |  |  |  |  |  |

Loading...
Searching...
No Matches
macros.h
1
2#ifndef MACROS_H
3#define MACROS_H
4
5#include <xc.h> // include processor files - each processor file is guarded.
6#include <stdint.h> // include standard integer data types
7#include <stdbool.h> // include standard boolean data types
8#include <stddef.h> // include standard definition data types
9#include <math.h> // include standard math functions library
10
11#include "useful_macros.h"
12#include "config.h"
13#include "hardware.h"
14
15
16//device specific setup
17// DO NOT MODIFY
18#define PWM_CLOCK_FREQUENCY (float)4.0e+9
19
20#define ADC_RESOLUTION 4095
21#define ADC_REFERENCE (float)3.3
22#define ADC_SCALER (float)(1.0 / ADC_RESOLUTION)
23//#define PHASE_DEGREES 360U ///< Maximum Phase degree
24#define PHASE_180_SCALER (float)(1.0 / 180)
25
26
37#define PWM_CLOCK_PERIOD (float)(1.0 / PWM_CLOCK_FREQUENCY)
38#define MAX_SWITCHING_PERIOD (float)(1.0/MINIMUM_SWITCHING_FREQUENCY)
39#define MIN_SWITCHING_PERIOD (float)(1.0/MAXIMUM_SWITCHING_FREQUENCY)
40#define MAX_PWM_PERIOD (uint16_t)(float)(MAX_SWITCHING_PERIOD / PWM_CLOCK_PERIOD)
41#define MIN_PWM_PERIOD (uint16_t)(float)(MIN_SWITCHING_PERIOD / PWM_CLOCK_PERIOD)
42#define PERIOD_RANGE (uint16_t)(MAX_PWM_PERIOD - MIN_PWM_PERIOD)
43#define ADC_PERIOD_RANGE (uint16_t)(float)(PERIOD_RANGE / ADC_RESOLUTION)
44
45//#define CONTROL_PHASE_RAD (uint16_t)(float)(PHASE_DEGREES / 180) ///< This sets the maximum PWM phase of the converter
46//#define MIN_PER_CONTROL_PHASE (uint16_t)(float)(MIN_PWM_PERIOD / CONTROL_PHASE_RAD)
47//#define MAX_PER_CONTROL_PHASE (uint16_t)(float)(MAX_PWM_PERIOD / CONTROL_PHASE_RAD)
48
49#define MIN_PWM_DEAD_TIME (uint16_t)(MINIMUM_DEADTIME / (float)PWM_CLOCK_PERIOD)
50#define MAX_PWM_DEAD_TIME (uint16_t)(MAXIMUM_DEADTIME / (float)PWM_CLOCK_PERIOD)
51
52#define MIN_PHASE_SHIFTED_PULSE (uint16_t)(MINIMUM_PHASESHIFTED_PULSE / (float)PWM_CLOCK_PERIOD)
53
54#define DEGREES_PHASE_10x (10u)
55#define DEGREES_PHASE_SCALER (10u)
56#define DEGREES_PHASE_SCALING_10 ((pow(2.0, DEGREES_PHASE_SCALER)) / DEGREES_PHASE_10x)
57#define DEGREES_PHASE_FACTOR ((PRI_TO_SEC_PHASE_DEGREES_LIMIT * ((DEGREES_PHASE_SCALER)* DEGREES_PHASE_10x)))
// end of group pwm-macros ~~~~~~~~~~~~~~~~~~~~
59
60//------------------------------------------------------------------------------
61// fault related
62//------------------------------------------------------------------------------
63// convert a threshold in engineering units (volts,amps etc,) or amps to ADC threshold
64// formula is:
65// integer threshold = (volts or amps threshold)*gain + offset
66// convert fault thresholds and delays into integers that can be used by the firmware
67
71#define ISEC_OC_THRES_TRIG (UNITS_FROM_ENG_TO_ADC(ISEC_OC_THRES_TRIG_AMPS,ISEC_CT_SNS_GAIN,ISEC_CT_SNS_OFS))
72#define ISEC_OC_THRES_CLEAR (UNITS_FROM_ENG_TO_ADC(ISEC_OC_THRES_CLEAR_AMPS,ISEC_CT_SNS_GAIN,ISEC_CT_SNS_OFS))
73#define ISEC_OC_T_BLANK_TRIG ((uint16_t)(_rnd(ISEC_OC_T_BLANK_TRIG_SEC / ISEC_OC_TICK_SEC)))
74#define ISEC_OC_T_BLANK_CLEAR ((uint16_t)(_rnd(ISEC_OC_T_BLANK_CLEAR_SEC / ISEC_OC_TICK_SEC)))
75
76#define ISEC_SC_THRES_TRIG (UNITS_FROM_ENG_TO_ADC(ISEC_SC_THRES_TRIG_AMPS,ISEC_CT_SNS_GAIN,ISEC_CT_SNS_OFS))
77#define ISEC_LOAD_STEP_CLAMP (UNITS_FROM_ENG_TO_ADC(ISEC_LOAD_STEP_CLAMPING_AMPS,ISEC_AVG_SNS_GAIN,0))
78
79//------------------------------------------------------------------------------
80// parameters related to secondary current sensor calibration
81//------------------------------------------------------------------------------
82// allowing for +/-5% from ideal
83#define ISEC_AVG_SENSOR_OFFSET_LIMIT_HIGH (_rnd((ISEC_AVG_SNS_OFS*1.05)/3.3*4096.0))
84#define ISEC_AVG_SENSOR_OFFSET_LIMIT_LOW (_rnd((ISEC_AVG_SNS_OFS*0.95)/3.3*4096.0))
85
// end of group ~~~~~~~~~~~~~~~~~~~~
87
88
92#define IPRI_OC_THRES_TRIG (UNITS_FROM_ENG_TO_ADC(IPRI_OC_THRES_TRIG_AMPS,IPRI_CT_SNS_GAIN,IPRI_CT_SNS_OFS))
93#define IPRI_OC_THRES_CLEAR (UNITS_FROM_ENG_TO_ADC(IPRI_OC_THRES_CLEAR_AMPS,IPRI_CT_SNS_GAIN,IPRI_CT_SNS_OFS))
94#define IPRI_OC_T_BLANK_TRIG ((uint16_t)(_rnd(IPRI_OC_T_BLANK_TRIG_SEC / IPRI_OC_TICK_SEC)))
95#define IPRI_OC_T_BLANK_CLEAR ((uint16_t)(_rnd(IPRI_OC_T_BLANK_CLEAR_SEC / IPRI_OC_TICK_SEC)))
96
97#define IPRI_SC_THRES_TRIG (UNITS_FROM_ENG_TO_ADC(IPRI_SC_THRES_TRIG_AMPS,IPRI_CT_SNS_GAIN,IPRI_CT_SNS_OFS))
98#define I_SC_T_BLANK_CLEAR ((uint16_t)(_rnd(I_SC_T_BLANK_CLEAR_SEC / I_SC_TICK_SEC)))
// end of group ~~~~~~~~~~~~~~~~~~~~
100
101
105#define VSEC_OV_THRES_TRIG (UNITS_FROM_ENG_TO_ADC(VSEC_OV_THRES_TRIG_VOLTS,VSEC_SNS_GAIN,0.0))
106#define VSEC_OV_THRES_CLEAR (UNITS_FROM_ENG_TO_ADC(VSEC_OV_THRES_CLEAR_VOLTS,VSEC_SNS_GAIN,0.0))
107#define VSEC_OV_T_BLANK_TRIG ((uint16_t)(_rnd(VSEC_OV_T_BLANK_TRIG_SEC / VSEC_OV_TICK_SEC)))
108#define VSEC_OV_T_BLANK_CLEAR ((uint16_t)(_rnd(VSEC_OV_T_BLANK_CLEAR_SEC / VSEC_OV_TICK_SEC)))
109
110#define VSEC_UV_THRES_TRIG (UNITS_FROM_ENG_TO_ADC(VSEC_UV_THRES_TRIG_VOLTS,VSEC_SNS_GAIN,0.0))
111#define VSEC_UV_THRES_CLEAR (UNITS_FROM_ENG_TO_ADC(VSEC_UV_THRES_CLEAR_VOLTS,VSEC_SNS_GAIN,0.0))
112#define VSEC_UV_T_BLANK_TRIG ((uint16_t)(_rnd(VSEC_UV_T_BLANK_TRIG_SEC / VSEC_UV_TICK_SEC)))
113#define VSEC_UV_T_BLANK_CLEAR ((uint16_t)(_rnd(VSEC_UV_T_BLANK_CLEAR_SEC / VSEC_UV_TICK_SEC)))
114
115#define VSEC_LOAD_STEP_CLAMP (UNITS_FROM_ENG_TO_ADC(VSEC_LOAD_STEP_CLAMPING_VOLTS,VSEC_SNS_GAIN,0.0))
116#define VPRIM_LOAD_STEP_CLAMP (UNITS_FROM_ENG_TO_ADC( VPRIM_LOAD_STEP_CLAMPING_VOLTS,VPRI_SNS_GAIN,0.0))
// end of group ~~~~~~~~~~~~~~~~~~~~
118
119
123#define VPRI_OV_THRES_TRIG (UNITS_FROM_ENG_TO_ADC(VPRI_OV_THRES_TRIG_VOLTS,VPRI_SNS_GAIN,VPRI_SNS_OFS))
124#define VPRI_OV_THRES_CLEAR (UNITS_FROM_ENG_TO_ADC(VPRI_OV_THRES_CLEAR_VOLTS,VPRI_SNS_GAIN,VPRI_SNS_OFS))
125#define VPRI_OV_T_BLANK_TRIG ((uint16_t)(_rnd(VPRI_OV_T_BLANK_TRIG_SEC / VSEC_OV_TICK_SEC)))
126#define VPRI_OV_T_BLANK_CLEAR ((uint16_t)(_rnd(VPRI_OV_T_BLANK_CLEAR_SEC / VSEC_OV_TICK_SEC)))
127
128#define VPRI_UV_THRES_TRIG (UNITS_FROM_ENG_TO_ADC(VPRI_UV_THRES_TRIG_VOLTS,VPRI_SNS_GAIN,VPRI_SNS_OFS))
129#define VPRI_UV_THRES_CLEAR (UNITS_FROM_ENG_TO_ADC(VPRI_UV_THRES_CLEAR_VOLTS,VPRI_SNS_GAIN,VPRI_SNS_OFS))
130#define VPRI_UV_T_BLANK_TRIG ((uint16_t)(_rnd(VPRI_UV_T_BLANK_TRIG_SEC / VSEC_UV_TICK_SEC)))
131#define VPRI_UV_T_BLANK_CLEAR ((uint16_t)(_rnd(VPRI_UV_T_BLANK_CLEAR_SEC / VSEC_UV_TICK_SEC)))
132
133
134#define VPRI_SCALER (10u)
135#define VPRI_FACTOR (uint16_t)((1 / VPRI_VOLTAGE_GAIN) * VPRI_SCALER)
136
// end of group ~~~~~~~~~~~~~~~~~~~~
138
139
143#define VRAIL_5V_UV_THRES_TRIG (UNITS_FROM_ENG_TO_ADC(VRAIL_5V_UV_THRES_TRIG_VOLTS,VRAIL_5V_SNS_GAIN,0.0))
144#define VRAIL_5V_UV_THRES_CLEAR (UNITS_FROM_ENG_TO_ADC(VRAIL_5V_UV_THRES_CLEAR_VOLTS,VRAIL_5V_SNS_GAIN,0.0))
145#define VRAIL_5V_UV_T_BLANK_TRIG ((uint16_t)(_rnd(VRAIL_5V_UV_T_BLANK_TRIG_SEC / VRAIL_5V_UV_TICK_SEC)))
146#define VRAIL_5V_UV_T_BLANK_CLEAR ((uint16_t)(_rnd(VRAIL_5V_UV_T_BLANK_CLEAR_SEC / VRAIL_5V_UV_TICK_SEC)))
// end of group ~~~~~~~~~~~~~~~~~~~~
148
149
154#define TEMPERATURE_FACTOR (int16_t)(TEMPERATURE_GAIN * pow(2.0, 15))
155
156#define L_TEMPERATURE_THRESHOLD (uint16_t)(NOMINAL_TEMPERATURE_THRESHOLD - TEMPERATURE_HYSTERESIS)
157#define H_TEMPERATURE_THRESHOLD (uint16_t)(NOMINAL_TEMPERATURE_THRESHOLD + TEMPERATURE_HYSTERESIS)
158
// end of group ~~~~~~~~~~~~~~~~~~~~
160
161
165#define POWER_SCALER (14u)
166#define POWER_FACTOR (uint16_t)(((ADC_REFERENCE * ADC_REFERENCE * pow(2.0, POWER_SCALER))) / ((ADC_RESOLUTION * VSEC_SNS_GAIN) * (ADC_RESOLUTION * ISEC_AVG_SNS_GAIN)))
167
168#define AGC_VOLTAGE_FACTOR (uint32_t)(AGC_MINIMUM_VIN_THRESHOLD * pow(2.0, 15))
169#define AGC_MINIMUM_CURRENT_THRESHOLD (UNITS_FROM_ENG_TO_ADC(AGC_MINIMUM_ISEC_THRESHOLD,ISEC_AVG_SNS_GAIN,0.0))
170#define AGC_CURRENT_FACTOR (uint32_t)(AGC_MINIMUM_CURRENT_THRESHOLD * pow(2.0, 15))
// end of group ~~~~~~~~~~~~~~~~~~~~
172
173
174#endif /* MACROS_H */
175