XMC42_800WPSU_LLC
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
init_bckgnd.c
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2017, Infineon Technologies AG
3
* <br>All rights reserved.
4
* <br>Redistribution and use in source and binary forms, with or without
5
* modification,are permitted provided that the following conditions are met:
6
* - Redistributions of source code must retain the above copyright notice,
7
* this list of conditions and the following disclaimer.
8
* - Redistributions in binary form must reproduce the above copyright notice,
9
* this list of conditions and the following disclaimer in the documentation
10
* and/or other materials provided with the distribution.
11
* - Neither the name of the copyright holders nor the names of its contributors
12
* may be used to endorse or promote products derived from this software without
13
* specific prior written permission.
14
* .
15
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23
* CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25
* POSSIBILITY OF SUCH DAMAGE.
26
* <br>To improve the quality of the software, users are encouraged to share
27
* modifications, enhancements or bug fixes with Infineon Technologies AG
28
* dave@infineon.com).
29
*/
30
42
/***********************************************************************************************************************
43
* HEADER FILES
44
**********************************************************************************************************************/
45
46
#include "
init_bckgnd.h
"
47
#include "
interrupts_control.h
"
48
49
/**********************************************************************************************************************
50
* VARAIBLE DEFINITION
51
**********************************************************************************************************************/
52
57
uint8_t
_1ms_count
= 0;
58
uint16_t
_100ms_count
= 0;
59
volatile
uint8_t
time_BOP
= 1;
60
//uint8_t time_V_step = 0;
61
volatile
uint8_t
time_INIT
= 50;
62
static
uint8_t
time_fan_100ms
= 1;
63
static
uint8_t
time_IMON_us
= 3;
64
static
int16_t
fan_pwm_duty
= 0;
65
volatile
uint16_t
time_OCP_M_100ms
= 0;
66
volatile
uint16_t
time_OCP_S_100ms
= 0;
67
volatile
uint8_t
time_send_UART
= 6;
71
static
uint32_t
fan_speed_value
;
72
74
static
int16_t
IMON_DAC_value
= 0;
75
77
__I uint32_t *
Fsw_capture
;
78
80
//__I uint32_t *fan_speed;
81
82
83
/**********************************************************************************************************************
84
* FUNCTIONS
85
**********************************************************************************************************************/
86
87
/*---------------------------------------------------------------------------*/
93
void
time_counter
()
94
{
95
96
/* 100us Timing counting using the 10us (ISR) base */
97
if
(
time_IMON_100kHz
>
LIMIT_100_MICRO_S
)
98
{
99
/* 1ms counter */
100
time_IMON_100kHz
= 0;
101
102
/* Timer used to update the current monitoring */
103
if
((
time_IMON_us
) && (
status_reg
&
ST_RUNNING
))
time_IMON_us
--;
104
105
/* Timer used to send information to primary side */
106
if
((
time_send_UART
) && (
status_reg
& ST_RUNNING))
time_send_UART
--;
107
108
}
109
110
/* 1ms Timing counting using the 10us (ISR) base */
111
if
(
time_count_100kHz
>
LIMIT_1_MILI_S
)
112
{
113
/* 1ms counter */
114
time_count_100kHz
= 0;
115
_1ms_count
++;
116
117
/* Timer used to check the input voltage out of range during operation */
118
if
(
time_BOP
)
time_BOP
--;
119
120
// /* Timer for voltage steps in soft-start */
121
// if(time_V_step) time_V_step--;
122
123
/* Timer to wait before starting or resuming operation */
124
if
(!
status_reg
&&
time_INIT
)
time_INIT
--;
125
126
}
127
128
/* 100ms Timing counting using the 1ms base */
129
if
(
_1ms_count
>
LIMIT_100_MILI_S
)
130
{
131
/* 100ms counter */
132
_1ms_count
= 0;
133
_100ms_count
++;
134
135
// XMC_GPIO_ToggleOutput(P1_1);
136
137
/* Timer for MED over-current protection */
138
if
(
time_OCP_M_100ms
)
time_OCP_M_100ms
--;
139
140
/* Timer for SOFT over-current protection */
141
if
(
time_OCP_S_100ms
)
time_OCP_S_100ms
--;
142
143
/* Timer used in the fan management */
144
if
(
time_fan_100ms
)
time_fan_100ms
--;
145
146
// if(time_V_step) time_V_step--;
147
}
148
// "long-time" counter using the 100ms count
149
}
150
151
/*---------------------------------------------------------------------------*/
158
void
control_loop_init
()
159
{
160
// /* Debug LED1 */
161
// XMC_GPIO_ToggleOutput(P1_1);
162
163
/*--------------------------------------------------------------------------*/
164
/* PARAMETERS OF V-LOOP */
165
/*--------------------------------------------------------------------------*/
166
// 12V reference
167
voltage_int_ctr
.
int_ref_steady
=
VOUT_TARGET
;
168
voltage_int_ctr
.
int_ref
= 0;
//Reference used for soft-start
169
170
// Information to generate the current reference is in "upper" 16bits of the output information during steady state (Q31 --> Q15)
171
voltage_int_ctr
.
output_int_limit
= ((int16_t *)(&
voltage_int_ctr
.
output_int
))+1;
172
// Soft-start path is used to decrease frequency linearly until target voltage is reached
173
voltage_int_ctr
.
output
= (int16_t *)(&
voltage_int_ctr
.
soft_start
);
//voltage_int_ctr.output_int_limit;
174
175
// // Integrator coefficient
176
// voltage_int_ctr.a[0] = 500;//R_GAIN;//500;// 1000 for 3.3V reference
177
178
// PID coefficient
179
voltage_int_ctr
.
a
[0] =
Kp
+
Ki
+
Kd
;
180
voltage_int_ctr
.
a
[1] = -
Kp
-2*
Kd
;
181
voltage_int_ctr
.
a
[2] =
Kd
;
182
183
// Starting soft-start frequency
184
// voltage_int_ctr.soft_start = LLC_PERIOD_MIN;
185
*
voltage_int_ctr
.
output_int_limit
=
LLC_PERIOD_MAX
;
186
// Save state for next calculation
187
voltage_int_ctr
.
state
[0] =
voltage_int_ctr
.
output_int
;
188
189
// Error initialization
190
voltage_int_ctr
.
error
[0] = 0x0;
191
voltage_int_ctr
.
error
[1] = 0x0;
192
voltage_int_ctr
.
error
[2] = 0x0;
193
194
// At start, when oring is closed, voltage before oring is controlled
195
LLC
.
qVout
= (uint16_t *)(&
LLC
.
q12V_oring
);
196
197
// Peaking filter initialization
198
voltage_int_ctr
.
fIn_peak
[0] = 0;
199
voltage_int_ctr
.
fIn_peak
[1] = 0;
200
voltage_int_ctr
.
fIn_peak
[2] = 0;
201
voltage_int_ctr
.
fOut_peak
[0] = 0;
202
voltage_int_ctr
.
fOut_peak
[1] = 0;
203
voltage_int_ctr
.
fOut_peak
[2] = 0;
204
voltage_int_ctr
.
qOut_peak
= 0;
205
206
// Start in normal operation of the converter
207
burst_status
=
FREQ_OPERATION
;
208
209
210
/*-------------------------------------------------------------------------*/
211
/* Capture frequency pointer during start-up initialization */
212
/*-------------------------------------------------------------------------*/
213
Fsw_capture
= &CCU41_CC41->CV[1];
214
215
// /*-------------------------------------------------------------------------*/
216
// /* Capture fan tachometer speed pointer initialization */
217
// /*-------------------------------------------------------------------------*/
218
// fan_speed = &CCU41_CC43->CV[1];
219
220
// /* Debug LED1 */
221
// XMC_GPIO_ToggleOutput(P1_1);
222
223
}
224
225
226
/*---------------------------------------------------------------------------*/
232
//#ifndef DOXYGEN_SKIP
233
//__attribute__((section(".ram_code")))
234
//#endif
235
//__STATIC_INLINE
236
void
fan_temp_control
()
237
{
238
// Check if fan is rotating every 100ms
239
if
(!
time_fan_100ms
)
240
{
241
// /* Debug LED2 */
242
// XMC_GPIO_ToggleOutput(P0_6);
243
244
// Check event counting
245
fan_speed_value
= fan_speed_count.ccu4_handle->slice_ptr->TIMER;
//(*fan_speed & CCU4_CC4_CV_CAPTV_Msk);
246
247
// // If this condition is triggered the fan is not moving or moving slow
248
// if ((fan_speed_value < 5) && (status_reg & ST_RUNNING))
249
// /* Debug LED1 */
250
// XMC_GPIO_SetOutputHigh(P1_1);
251
// else
252
// /* Debug LED1 */
253
// XMC_GPIO_SetOutputLow(P1_1);
254
255
256
// Calculate fan speed, adjusted with the PWM duty
257
fan_pwm_duty
=
T_SLOPE_PWM
* (
Temp_fan
-
T_MIN_PWM
);
//T_SLOPE_PWM * (T_MAX_PWM-Temp[3]);
258
if
(
fan_pwm_duty
< 0)
//160)
259
fan_pwm_duty
= 0;
//160;
260
else
if
(
fan_pwm_duty
> fan_pwm.config_ptr->period_value)
261
fan_pwm_duty
= fan_pwm.config_ptr->period_value;
262
263
// Modify fan PWM duty cycle
264
// fan_duty_set(1200);
265
fan_duty_set
(
fan_pwm_duty
);
266
267
// Reset checking time (updated in time_counter)
268
time_fan_100ms
++;
269
270
// Clears counter value
271
fan_speed_count.ccu4_handle->slice_ptr->TCCLR = CCU4_CC4_TCCLR_TCC_Msk;
272
}
273
}
274
275
/*---------------------------------------------------------------------------*/
281
//#ifndef DOXYGEN_SKIP
282
//__attribute__((section(".ram_code")))
283
//#endif
284
//__STATIC_INLINE
285
void
I_MON_update
()
286
{
287
288
// Check if fan is rotating every 100ms
289
if
(!
time_IMON_us
)
290
{
291
292
// Calculate value to be fed in the DAC
293
IMON_DAC_value
= ((
LLC
.
qIout
*18832) >> 13) - 3483;
294
if
(
IMON_DAC_value
< 0)
IMON_DAC_value
= 0;
295
296
// // Calculate value to be fed in the DAC DEBUGGING
297
// IMON_DAC_value += 1000;
298
// if (IMON_DAC_value < 0) IMON_DAC_value = 0;
299
// else if (IMON_DAC_value > 4100) IMON_DAC_value = 0;
300
301
// Update DAC value
302
DAC_SingleValue_SetValue_u16(&DAC_imon,
IMON_DAC_value
);
303
304
// Reset checking time (updated in time_counter)
305
time_IMON_us
= 3;
306
}
307
}
init_bckgnd.c
Generated on Thu Jun 22 2017 15:13:37 for XMC42_800WPSU_LLC by
1.8.3.1