Bar Logo 3.8/7.6 kw Totem pole Demonstration Application (Part-No. (not specified))
 
Content
     
Loading...
Searching...
No Matches
main_tasks.c
1/*
2© [2024] Microchip Technology Inc. and its subsidiaries.
3
4 Subject to your compliance with these terms, you may use Microchip
5 software and any derivatives exclusively with Microchip products.
6 You are responsible for complying with 3rd party license terms
7 applicable to your use of 3rd party software (including open source
8 software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
9 NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
10 SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
11 MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
12 WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
13 INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
14 KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
15 MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
16 FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
17 TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
18 EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
19 THIS SOFTWARE.
20 */
21
22#include "mcc_generated_files/system/pins.h"
23#include "mcc_generated_files/system/interrupt.h"
24
28#include "sources/misc/MCC_add_on.h"
29
30#include "PFC_frameworkSetup.h"
32
33
38static PWR_CTRL_STATE_e Init_StateHandler(void);
39static PWR_CTRL_STATE_e WaitIfFaultActive_StateHandler(void);
40static PWR_CTRL_STATE_e StandBy_StateHandler(void);
41static PWR_CTRL_STATE_e VacOk_StateHandler(void);
42static PWR_CTRL_STATE_e VoutPreLoad_StateHandler(void);
43static PWR_CTRL_STATE_e RelayOn_StateHandler(void);
44static PWR_CTRL_STATE_e DelayAfterRelayOn_StateHandler(void);
45static PWR_CTRL_STATE_e StartControl_StateHandler(void);
46static PWR_CTRL_STATE_e SoftStart_StateHandler(void);
47static PWR_CTRL_STATE_e UpAndRunning_StateHandler(void);
48static PWR_CTRL_STATE_e VACOK_Check(void);
49
50
60#define t2sec 20000 //100us steps for 2s
61#define t1sec 10000 //100us steps for 1s
62#define t20ms 200 //100us steps for 20ms
63#define t50ms 500 //100us steps for 30ms
64#define VoutStartUpVary 150 //Startup ramp accuracy range to ramp further
65#define CurrentOffsetLowLimit 2020 //typ. ADC value is 2048
66#define CurrentOffsetHighLimit 2070 //typ. ADC value is 2048
67
68
73static uint16_t RelayTimeCounter = t2sec, RelayTimeCounterStart = t20ms;
74static uint16_t CalibrationTimeCounter = t2sec;
75
76
88void Tasks_100us(void)
89{
90 ReceiveMSIAMessage(); //<< check CAN receive
91
92 //<< send data via CAN
93 if ((SI1FIFOCSbits.SWFEN) && (SI1FIFOCSbits.SWFEMPTY))
94 {
96 }
97 //<<----------------------------------------------------------------------
98
99 switch (pwr_ctrl_state)
100 {
101 //<<--------------------------------------------------------------------
102 case PCS_INIT://#1
103 //wait for VACok and after 2sec check if calibration data are valid
104 pwr_ctrl_state = Init_StateHandler();
105
106 break;
107
108 //<<--------------------------------------------------------------------
110 //stall when current sensor calibration fails
111 Nop();
112
113 break;
114
115 //<<--------------------------------------------------------------------
116 case PCS_STANDBY://#3
117 pwr_ctrl_state = StandBy_StateHandler();
118
119 break;
120
121 //<<--------------------------------------------------------------------
122 case PCS_VACOK://#4
123 pwr_ctrl_state = VacOk_StateHandler();
124
125 break;
126
127 //<<--------------------------------------------------------------------
128 case PCS_VOUT_PRELOAD://#5
129 pwr_ctrl_state = VoutPreLoad_StateHandler();
130
131 break;
132
133 //<<--------------------------------------------------------------------
134 case PCS_RELAYON://#6
135 pwr_ctrl_state = RelayOn_StateHandler();
136
137 break;
138
139 //<<--------------------------------------------------------------------
141
142 // wait 50ms delay after switch on to enable relay bits for Phase Handler
143 pwr_ctrl_state = DelayAfterRelayOn_StateHandler();
144
145 break;
146
147 //<<--------------------------------------------------------------------
148 case PCS_START_CONTROL://#8
149 // wait 50ms delay to initialize controller and Vout softstart reference based
150 // on the actual Vout measurement
151 pwr_ctrl_state = StartControl_StateHandler();
152
153#ifndef VOLTAGE_LOOP
155#endif
156
157 break;
158
159 //<<--------------------------------------------------------------------
160 case PCS_SOFT_START://#9
161
162 pwr_ctrl_state = SoftStart_StateHandler();
163
164#ifdef VOLTAGE_LOOP
165 //ramp further if actual Vout is in a certain range
166 if ((Vout_Control.Vout.Raw > (Vout_Control.Reference.Reference_Internal - VoutStartUpVary)) &&
168#endif
169 {
171 }
172
173 break;
174
175 //<<--------------------------------------------------------------------
176 case PCS_UP_AND_RUNNING://#10
177
178 pwr_ctrl_state = UpAndRunning_StateHandler();
179
180 break;
181
182 //<<--------------------------------------------------------------------
183 case PCS_STALL_DEBUG://#11
184 //stall when VACOK is false or anything goes completely wrong
185 //for debug purposes
186 Nop();
187
188 break;
189
190 //<<--------------------------------------------------------------------
191 default:
192
193 break;
194 }
195 //<<----------------------------------------------------------------------
196
197 //fast AC loss check
198 pwr_ctrl_state = VACOK_Check();
199
200}
201
202
213static __inline__ PWR_CTRL_STATE_e Init_StateHandler(void)
214{
215 static PWR_CTRL_STATE_e returnvalue = 1;
216
217 //<<< only testing >>>
219 {
220 if ((CalibrationTimeCounter--) == 0)
221 {
222 //<<< only testing >>>
223 if ((Phase_Values_PH1.Phase_Current.Offset > CurrentOffsetLowLimit) || (Phase_Values_PH1.Phase_Current.Offset < CurrentOffsetHighLimit))
224 {
225 returnvalue = PCS_STANDBY;
226 }
227 else
228 returnvalue = PCS_WAIT_IF_FAULT_ACTIVE;
229 }
230 }
231 else
232 returnvalue = PCS_INIT;
233
234 return returnvalue;
235
236}
237
238
250static __inline__ PWR_CTRL_STATE_e WaitIfFaultActive_StateHandler(void)
251{
252 static PWR_CTRL_STATE_e returnvalue = 1;
253
254 returnvalue = pwr_ctrl_state;
255
256 return returnvalue;
257}
258
259
270static __inline__ PWR_CTRL_STATE_e StandBy_StateHandler(void)
271{
272 static PWR_CTRL_STATE_e returnvalue = 1;
273
274#ifdef AUTO_START
275 if ((Phase_Values_PH1.ACcontrol_Status_Flags_perPhase.bits.VAC_OK)) //testsetup to startPFC automatic without CAN GUI
276 {
278#else
279 if (PFC_Flags.bits.Run)
280 {
281#endif
282 PFC_Flags.bits.Run = 1;
283 PFC_Flags.bits.Fault = 0;
287 PFC_Flags.bits.Stop = 0;
289
292
293 RelayTimeCounter = t1sec;
294 returnvalue = PCS_VACOK;
295 }
296 else
297 returnvalue = PCS_STANDBY;
298
299 return returnvalue;
300}
301
302
313static __inline__ PWR_CTRL_STATE_e VacOk_StateHandler(void)
314{
315 static PWR_CTRL_STATE_e returnvalue = 1;
316
317 if ((RelayTimeCounter--) == 0)
318 {
319#ifdef VOUT_PRECHARGE_PCS_ENABLE
320 returnvalue = PCS_VOUT_PRELOAD;
321#else
322 returnvalue = PCS_RELAYON;
323#endif
324 }
325 else
326 returnvalue = PCS_VACOK;
327
328 return returnvalue;
329}
330
331
343static __inline__ PWR_CTRL_STATE_e VoutPreLoad_StateHandler(void)
344{
345 static PWR_CTRL_STATE_e returnvalue = 1;
346
347 if (!PFC_Flags.bits.Run)
348 {
350 returnvalue = PCS_STANDBY;
351 }
352 else
353 {
355 {
356 returnvalue = PCS_RELAYON;
357 }
358 else
359 returnvalue = PCS_VOUT_PRELOAD;
360 }
361
362 return returnvalue;
363}
364
365
376static __inline__ PWR_CTRL_STATE_e RelayOn_StateHandler(void)
377{
378 static PWR_CTRL_STATE_e returnvalue = 1;
379
380 RELAY_SetHigh(); //Relay ON
381 RelayTimeCounter = t20ms;
382 returnvalue = PCS_DELAY_AFTER_RELAYON;
383
384 return returnvalue;
385}
386
387
397static __inline__ PWR_CTRL_STATE_e DelayAfterRelayOn_StateHandler(void)
398{
399 static PWR_CTRL_STATE_e returnvalue = 1;
400
401 if (((RelayTimeCounter--) == 0) && (!Phase_Values_PH1.Control_Status_Flags.bits.Relay))
402 {
405 RelayTimeCounterStart = 1; //xx t50ms;
406
407 returnvalue = PCS_START_CONTROL;
408 }
409 else
410 returnvalue = PCS_DELAY_AFTER_RELAYON;
411
412 return returnvalue;
413}
414
415
429static __inline__ PWR_CTRL_STATE_e StartControl_StateHandler(void)
430{
431 static PWR_CTRL_STATE_e returnvalue = 1;
432
433 if (((RelayTimeCounterStart--) == 0) && (Phase_Values_PH1.Control_Status_Flags.bits.Relay))
434 {
440
441 SMPS_Controller2P2ZInitialize(&PHx_AVG_CM2p2z[1]); // Clear histories
442 SMPS_Controller2P2ZInitialize(&PHx_AVG_CM2p2z[2]); // Clear histories
443 SMPS_Controller2P2ZInitialize(&VMC_2p2z); // Clear histories
444
446
448
449#ifdef MODE_GRID_TIE_INVERTER
450 //<< initiate change bit to enable PWM in SoftstartAfterZC_PH1 for DC mode
453#endif
454 returnvalue = PCS_SOFT_START;
455 }
456 else
457 returnvalue = PCS_START_CONTROL;
458
459 return returnvalue;
460
461}
462
463
473static __inline__ PWR_CTRL_STATE_e SoftStart_StateHandler(void)
474{
475 static PWR_CTRL_STATE_e returnvalue = 1;
476
477 if (!PFC_Flags.bits.Run)
478 {
482 RELAY_SetLow(); //Relay OFF
483
484 returnvalue = PCS_STANDBY;
485 }
486 else
487 returnvalue = pwr_ctrl_state;
488
489 return returnvalue;
490
491}
492
493
504static __inline__ PWR_CTRL_STATE_e UpAndRunning_StateHandler(void)
505{
506 static PWR_CTRL_STATE_e returnvalue = 1;
507
508 if (!PFC_Flags.bits.Run)
509 {
513 RELAY_SetLow(); //Relay OFF
514
515 returnvalue = PCS_STANDBY;
516 }
519 {
521 returnvalue = PCS_SOFT_START;
522 }
523 else
524 returnvalue = PCS_UP_AND_RUNNING;
525
526 return returnvalue;
527}
528
529
541static __inline__ PWR_CTRL_STATE_e VACOK_Check(void)
542{
543 static PWR_CTRL_STATE_e returnvalue = 1;
544
546 {
548 {
549 RELAY_SetLow(); //Relay OFF
551 returnvalue = PCS_STALL_DEBUG;
552 PFC_Flags.bits.Run = 0;
553 PFC_Flags.bits.Stop = 1;
554 }
555 else
556 returnvalue = pwr_ctrl_state;
557 }
558 else
559 returnvalue = pwr_ctrl_state;
560
561 return returnvalue;
562}
563
564//------------------------------------------------------------------------------
565//------------------------------------------------------------------------------
566
PHASE_VALUES_t Phase_Values_PH2
PWR_CTRL_STATE_e pwr_ctrl_state
VMC_VALUES_t Vout_Control
PHASE_VALUES_t Phase_Values_PH1
PFC_FLAGS_t PFC_Flags
This is the typedef file for power controller.
PWR_CTRL_STATE_e
@ PCS_VACOK
@ PCS_STANDBY
@ PCS_RELAYON
@ PCS_SOFT_START
@ PCS_WAIT_IF_FAULT_ACTIVE
@ PCS_START_CONTROL
@ PCS_VOUT_PRELOAD
@ PCS_DELAY_AFTER_RELAYON
@ PCS_UP_AND_RUNNING
@ PCS_STALL_DEBUG
void SendMSIFIFOMessage(void)
Definition drv_msi.c:134
void ReceiveMSIAMessage(void)
Definition drv_msi.c:62
This is the driver header file for MSI.
SMPS_2P2Z_T PHx_AVG_CM2p2z[3]
SMPS_2P2Z_T VMC_2p2z
This is the driver header file for the power controller.
void Drv_PwrCtrl_TPBLPFC_Stop(void)
PWR_CTRL_STATE_e Softstart_reference(void)
This is the driver header file for the power controller misc app.
void SMPS_Controller2P2ZInitialize(SMPS_2P2Z_T *controllerData)
Allows the user to change the advanced operating parameters.
#define VOUT_REF
#define VOUT_PRECHARGE_VALUE
static void INTERRUPT_GlobalEnable(void)
Enables the global interrupt bit.
Definition interrupt.h:65
static void INTERRUPT_GlobalDisable(void)
Disables the global interrupt bit.
Definition interrupt.h:76
#define RELAY_SetLow()
Sets the RD14 GPIO Pin which has a custom name of RELAY to Low.
Definition pins.h:725
#define RELAY_SetHigh()
Sets the RD14 GPIO Pin which has a custom name of RELAY to High.
Definition pins.h:716
volatile uint16_t Filtered
volatile int16_t Offset
volatile int16_t Raw
volatile uint16_t Reference_Internal
volatile uint16_t CCM_Counter
struct CONTROL_STATUS_FLAGS_s::@24::@26 bits
volatile unsigned Reference_Changed
volatile unsigned VAC_Polarity_last
volatile unsigned VAC_Polarity_Changed
struct ACCONTROL_PHASE_STATUS_FLAGS_s::@27::@29 bits
ACCONTROL_PHASE_STATUS_FLAGS_t ACcontrol_Status_Flags_perPhase
CONTROLLER_VALUES_t Controller_Values
ANALOG_VALUES_t Phase_Current
CONTROL_STATUS_FLAGS_t Control_Status_Flags
CONTROL_REFERENCE_VALUES_t Reference
ANALOG_VALUES_t Vout
volatile unsigned OC_PH3
struct PFC_FLAGS_s::@30::@32 bits
volatile unsigned Fault
volatile unsigned OC_PH2
volatile unsigned OV_Vout
volatile unsigned Stop
volatile unsigned OC_PH1
volatile unsigned Run