XMC42_800WPSU_LLC
 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 /*---------------------------------------------------------------------------*/
94 {
95 
96  /* 100us Timing counting using the 10us (ISR) base */
98  {
99  /* 1ms counter */
100  time_IMON_100kHz = 0;
101 
102  /* Timer used to update the current monitoring */
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 */
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 */
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 */
139 
140  /* Timer for SOFT over-current protection */
142 
143  /* Timer used in the fan management */
145 
146 // if(time_V_step) time_V_step--;
147  }
148  // "long-time" counter using the 100ms count
149  }
150 
151 /*---------------------------------------------------------------------------*/
159 {
160 // /* Debug LED1 */
161 // XMC_GPIO_ToggleOutput(P1_1);
162 
163  /*--------------------------------------------------------------------------*/
164  /* PARAMETERS OF V-LOOP */
165  /*--------------------------------------------------------------------------*/
166  // 12V reference
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)
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;
186  // Save state for next calculation
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;
205 
206  // Start in normal operation of the converter
208 
209  /*-------------------------------------------------------------------------*/
210  /* Capture frequency pointer during start-up initialization */
211  /*-------------------------------------------------------------------------*/
212  Fsw_capture = &CCU41_CC41->CV[1];
213 
214 // /*-------------------------------------------------------------------------*/
215 // /* Capture fan tachometer speed pointer initialization */
216 // /*-------------------------------------------------------------------------*/
217 // fan_speed = &CCU41_CC43->CV[1];
218 
219 // /* Debug LED1 */
220 // XMC_GPIO_ToggleOutput(P1_1);
221 
222 }
223 
224 
225 /*---------------------------------------------------------------------------*/
231 //#ifndef DOXYGEN_SKIP
232 //__attribute__((section(".ram_code")))
233 //#endif
234 //__STATIC_INLINE
236 {
237  // Check if fan is rotating every 100ms
238  if (!time_fan_100ms)
239  {
240 // /* Debug LED2 */
241 // XMC_GPIO_ToggleOutput(P0_6);
242 
243  // Check event counting
244  fan_speed_value = fan_speed_count.ccu4_handle->slice_ptr->TIMER;//(*fan_speed & CCU4_CC4_CV_CAPTV_Msk);
245 
246 // // If this condition is triggered the fan is not moving or moving slow
247 // if ((fan_speed_value < 5) && (status_reg & ST_RUNNING))
248 // /* Debug LED1 */
249 // XMC_GPIO_SetOutputHigh(P1_1);
250 // else
251 // /* Debug LED1 */
252 // XMC_GPIO_SetOutputLow(P1_1);
253 
254 
255  // Calculate fan speed, adjusted with the PWM duty
256  fan_pwm_duty = T_SLOPE_PWM * (Temp_fan-T_MIN_PWM);//T_SLOPE_PWM * (T_MAX_PWM-Temp[3]);
257  if (fan_pwm_duty < 0)//160)
258  fan_pwm_duty = 0;//160;
259  else if (fan_pwm_duty > fan_pwm.config_ptr->period_value)
260  fan_pwm_duty = fan_pwm.config_ptr->period_value;
261 
262  // Modify fan PWM duty cycle
263 // fan_duty_set(1200);
265 
266  // Reset checking time (updated in time_counter)
267  time_fan_100ms++;
268 
269  // Clears counter value
270  fan_speed_count.ccu4_handle->slice_ptr->TCCLR = CCU4_CC4_TCCLR_TCC_Msk;
271  }
272 }
273 
274 /*---------------------------------------------------------------------------*/
280 //#ifndef DOXYGEN_SKIP
281 //__attribute__((section(".ram_code")))
282 //#endif
283 //__STATIC_INLINE
285 {
286 
287  // Check if fan is rotating every 100ms
288  if (!time_IMON_us)
289  {
290 
291  // Calculate value to be fed in the DAC
292  IMON_DAC_value = ((LLC.qIout*18832) >> 13) - 3483;
293  if (IMON_DAC_value < 0) IMON_DAC_value = 0;
294 
295 // // Calculate value to be fed in the DAC DEBUGGING
296 // IMON_DAC_value += 1000;
297 // if (IMON_DAC_value < 0) IMON_DAC_value = 0;
298 // else if (IMON_DAC_value > 4100) IMON_DAC_value = 0;
299 
300  // Update DAC value
301  DAC_SingleValue_SetValue_u16(&DAC_imon,IMON_DAC_value);
302 
303  // Reset checking time (updated in time_counter, 100ms scale)
304  time_IMON_us = 3;
305  }
306 }