A1 A2 B1 B2 C1 C2 C3这几个函数大致的用法是什么意思?谢谢
//=================================================================================
// STATE-MACHINE SEQUENCING AND SYNCRONIZATION
//=================================================================================
// STATE-MACHINE SEQUENCING AND SYNCRONIZATION
//=================================================================================
//——————————— FRAMEWORK ————————————-
void A0(void)
{
// loop rate synchronizer for A-tasks
if(CpuTimer0Regs.TCR.bit.TIF == 1)
{
CpuTimer0Regs.TCR.bit.TIF = 1; // clear flag
void A0(void)
{
// loop rate synchronizer for A-tasks
if(CpuTimer0Regs.TCR.bit.TIF == 1)
{
CpuTimer0Regs.TCR.bit.TIF = 1; // clear flag
//———————————————————–
(*A_Task_Ptr)(); // jump to an A Task (A1,A2,A3,…)
//———————————————————–
SerialCommsTimer++;
(*A_Task_Ptr)(); // jump to an A Task (A1,A2,A3,…)
//———————————————————–
SerialCommsTimer++;
VTimer0[0]++; // virtual timer 0, instance 0 (spare)
}
}
Alpha_State_Ptr = &B0; // Comment out to allow only A tasks
}
}
void B0(void)
{
// loop rate synchronizer for B-tasks
if(CpuTimer1Regs.TCR.bit.TIF == 1)
{
CpuTimer1Regs.TCR.bit.TIF = 1; // clear flag
{
// loop rate synchronizer for B-tasks
if(CpuTimer1Regs.TCR.bit.TIF == 1)
{
CpuTimer1Regs.TCR.bit.TIF = 1; // clear flag
//———————————————————–
(*B_Task_Ptr)(); // jump to a B Task (B1,B2,B3,…)
//———————————————————–
VTimer1[0]++; // virtual timer 1, instance 0 (spare)
}
(*B_Task_Ptr)(); // jump to a B Task (B1,B2,B3,…)
//———————————————————–
VTimer1[0]++; // virtual timer 1, instance 0 (spare)
}
Alpha_State_Ptr = &C0; // Allow C state tasks
}
}
void C0(void)
{
// loop rate synchronizer for C-tasks
if(CpuTimer2Regs.TCR.bit.TIF == 1)
{
CpuTimer2Regs.TCR.bit.TIF = 1; // clear flag
{
// loop rate synchronizer for C-tasks
if(CpuTimer2Regs.TCR.bit.TIF == 1)
{
CpuTimer2Regs.TCR.bit.TIF = 1; // clear flag
//———————————————————–
(*C_Task_Ptr)(); // jump to a C Task (C1,C2,C3,…)
//———————————————————–
VTimer2[0]++; //virtual timer 2, instance 0 (spare)
}
(*C_Task_Ptr)(); // jump to a C Task (C1,C2,C3,…)
//———————————————————–
VTimer2[0]++; //virtual timer 2, instance 0 (spare)
}
Alpha_State_Ptr = &A0; // Back to State A0
}
}
//=================================================================================
// A – TASKS
//=================================================================================
//——————————————————–
void A1(void)//——————————————————–
{
// Channel On/Off control
// A – TASKS
//=================================================================================
//——————————————————–
void A1(void)//——————————————————–
{
// Channel On/Off control
/* if(ChannelEnable == 1)
VrefNetBus = Vbus_set;
else
VrefNetBus = 0;*/
VrefNetBus = Vbus_set;
else
VrefNetBus = 0;*/
//OV Protection moved to 10kHz ISR
/*
if (VbusAvg > VBUS_OVP_THRSHLD)//Check for Vbus OV Condition
{
OV_flag = 1;
EALLOW;
EPwm1Regs.TZFRC.bit.OST = 1;
EPwm2Regs.TZFRC.bit.OST = 1;
EDIS;
VbusTargetSlewed = 0;
VbusTarget = 0;
Gui_Vbus_set = 0;
} */
/*
if (VbusAvg > VBUS_OVP_THRSHLD)//Check for Vbus OV Condition
{
OV_flag = 1;
EALLOW;
EPwm1Regs.TZFRC.bit.OST = 1;
EPwm2Regs.TZFRC.bit.OST = 1;
EDIS;
VbusTargetSlewed = 0;
VbusTarget = 0;
Gui_Vbus_set = 0;
} */
if (INCR_BUILD == 3)
{
Pgain_I = Gui_Pgain_I*67108.86; // Q26. Since GUI P gain (I loop) is scaled up by 1000.00, the scaling
// factor in this case is 2e26/1000 = 67108.864
Igain_I = Gui_Igain_I*67108.86; // Q26. Since GUI I gain (I loop) is scaled up by 1000.00, the scaling
// factor in this case is 2e26/1000 = 67108.864
Dgain_I = Gui_Dgain_I*67108.86; // Q26. Since GUI D gain (I loop) is scaled up by 1000.00, the scaling
// factor in this case is 2e26/1000 = 67108.864
Pgain_V = Gui_Pgain_V*6710.89; // Q26; Since GUI P gain (V loop) is scaled up by 10000.00, the scaling
// factor in this case is 2e26/10000 = 6710.8864
Igain_V = Gui_Igain_V*6710.89; // Q26.Since GUI I gain (V loop) is scaled up by 10000.00, the scaling
// factor in this case is 2e26/10000 = 6710.8864
Dgain_V = Gui_Dgain_V*6710.89; // Q26.Since GUI D gain (V loop) is scaled up by 10000.00, the scaling
// factor in this case is 2e26/10000 = 6710.8864
/*
// Current loop coefficient update
CNTL_2P2Z_CoefStruct1.b2 = Dgain_I; // B2
CNTL_2P2Z_CoefStruct1.b1 =(Igain_I-Pgain_I-Dgain_I-Dgain_I); // B1
CNTL_2P2Z_CoefStruct1.b0 =(Pgain_I + Igain_I + Dgain_I); // B0
// CNTL_2P2Z_CoefStruct1.a2 =0.0; // A2 = 0
// CNTL_2P2Z_CoefStruct1.a1 =_IQ26(1.0); // A1 = 1// CNTL_2P2Z_CoefStruct1.max =Dmax_I; //Clamp Hi// CNTL_2P2Z_CoefStruct1.min =_IQ24(0.0); //Clamp Min */
// Update Voltage loop coefficients/* CNTL_2P2Z_CoefStruct2.b2 =Dgain_V; // B2
CNTL_2P2Z_CoefStruct2.b1 =(Igain_V-Pgain_V-Dgain_V-Dgain_V); // B1
CNTL_2P2Z_CoefStruct2.b0 =(Pgain_V + Igain_V + Dgain_V); // B0
CNTL_2P2Z_CoefStruct2.a2 =0.0; // A2 = 0
CNTL_2P2Z_CoefStruct2.a1 =_IQ26(1.0); // A1 = 1 CNTL_2P2Z_CoefStruct2.max =Dmax_V; //Clamp Hi CNTL_2P2Z_CoefStruct2.min =_IQ24(0.0); //Clamp Min*/
// factor in this case is 2e26/10000 = 6710.8864
Igain_V = Gui_Igain_V*6710.89; // Q26.Since GUI I gain (V loop) is scaled up by 10000.00, the scaling
// factor in this case is 2e26/10000 = 6710.8864
Dgain_V = Gui_Dgain_V*6710.89; // Q26.Since GUI D gain (V loop) is scaled up by 10000.00, the scaling
// factor in this case is 2e26/10000 = 6710.8864
/*
// Current loop coefficient update
CNTL_2P2Z_CoefStruct1.b2 = Dgain_I; // B2
CNTL_2P2Z_CoefStruct1.b1 =(Igain_I-Pgain_I-Dgain_I-Dgain_I); // B1
CNTL_2P2Z_CoefStruct1.b0 =(Pgain_I + Igain_I + Dgain_I); // B0
// CNTL_2P2Z_CoefStruct1.a2 =0.0; // A2 = 0
// CNTL_2P2Z_CoefStruct1.a1 =_IQ26(1.0); // A1 = 1// CNTL_2P2Z_CoefStruct1.max =Dmax_I; //Clamp Hi// CNTL_2P2Z_CoefStruct1.min =_IQ24(0.0); //Clamp Min */
// Update Voltage loop coefficients/* CNTL_2P2Z_CoefStruct2.b2 =Dgain_V; // B2
CNTL_2P2Z_CoefStruct2.b1 =(Igain_V-Pgain_V-Dgain_V-Dgain_V); // B1
CNTL_2P2Z_CoefStruct2.b0 =(Pgain_V + Igain_V + Dgain_V); // B0
CNTL_2P2Z_CoefStruct2.a2 =0.0; // A2 = 0
CNTL_2P2Z_CoefStruct2.a1 =_IQ26(1.0); // A1 = 1 CNTL_2P2Z_CoefStruct2.max =Dmax_V; //Clamp Hi CNTL_2P2Z_CoefStruct2.min =_IQ24(0.0); //Clamp Min*/
//Update coefficients for current loop.
if (coeff_change == 1)
{
EPwm1Regs.ETSEL.bit.INTEN = 0; // Disable INT
{
EPwm1Regs.ETSEL.bit.INTEN = 0; // Disable INT
if (pid2p2z_Gui == 0)
{
// Current loop coefficient update
CNTL_2P2Z_CoefStruct1.b2 = Dgain_I; // B2
CNTL_2P2Z_CoefStruct1.b1 = (Igain_I – Pgain_I – Dgain_I – Dgain_I); // B1
CNTL_2P2Z_CoefStruct1.b0 = (Pgain_I + Igain_I + Dgain_I); // B0
CNTL_2P2Z_CoefStruct1.a2 = 0x00000000; // A2
CNTL_2P2Z_CoefStruct1.a1 = 0x04000000; // A1 Corresponds to 1 in Q26
// Coef2P2Z_1[5] = Dmax; // Clamp Hi limit (Q26)
// Coef2P2Z_1[6] = 0x00000000;
}
else
{
CNTL_2P2Z_CoefStruct1.b2 = b2_Gui*65536.0; // B2 – I5Q10 scaled to I5Q26
CNTL_2P2Z_CoefStruct1.b1 = b1_Gui*65536.0; // B1
CNTL_2P2Z_CoefStruct1.b0 = b0_Gui*65536.0; // B0
CNTL_2P2Z_CoefStruct1.a2 = a2_Gui*65536.0; // A2
CNTL_2P2Z_CoefStruct1.a1 = a1_Gui*65536.0; // A1 // Coef2P2Z_1[5] = Dmax; // Clamp Hi limit (Q26)
// Coef2P2Z_1[6] = 0x00000000; }
{
// Current loop coefficient update
CNTL_2P2Z_CoefStruct1.b2 = Dgain_I; // B2
CNTL_2P2Z_CoefStruct1.b1 = (Igain_I – Pgain_I – Dgain_I – Dgain_I); // B1
CNTL_2P2Z_CoefStruct1.b0 = (Pgain_I + Igain_I + Dgain_I); // B0
CNTL_2P2Z_CoefStruct1.a2 = 0x00000000; // A2
CNTL_2P2Z_CoefStruct1.a1 = 0x04000000; // A1 Corresponds to 1 in Q26
// Coef2P2Z_1[5] = Dmax; // Clamp Hi limit (Q26)
// Coef2P2Z_1[6] = 0x00000000;
}
else
{
CNTL_2P2Z_CoefStruct1.b2 = b2_Gui*65536.0; // B2 – I5Q10 scaled to I5Q26
CNTL_2P2Z_CoefStruct1.b1 = b1_Gui*65536.0; // B1
CNTL_2P2Z_CoefStruct1.b0 = b0_Gui*65536.0; // B0
CNTL_2P2Z_CoefStruct1.a2 = a2_Gui*65536.0; // A2
CNTL_2P2Z_CoefStruct1.a1 = a1_Gui*65536.0; // A1 // Coef2P2Z_1[5] = Dmax; // Clamp Hi limit (Q26)
// Coef2P2Z_1[6] = 0x00000000; }
EPwm1Regs.ETSEL.bit.INTEN = 1; // Enable INT
coeff_change = 0;
disable_auto_cloop_coeff_change = 1;
//Disable auto adjustment of Cloop coeff when the user uses //the GUI to change the Cloop coeff
}
// Update Voltage loop coefficients
if (vloop_coeff_change == 1)
{
EPwm1Regs.ETSEL.bit.INTEN = 0; // Disable INT
disable_auto_cloop_coeff_change = 1;
//Disable auto adjustment of Cloop coeff when the user uses //the GUI to change the Cloop coeff
}
// Update Voltage loop coefficients
if (vloop_coeff_change == 1)
{
EPwm1Regs.ETSEL.bit.INTEN = 0; // Disable INT
CNTL_2P2Z_CoefStruct2.b2 = Dgain_V; // B2
CNTL_2P2Z_CoefStruct2.b1 = (Igain_V-Pgain_V-Dgain_V-Dgain_V); // B1
CNTL_2P2Z_CoefStruct2.b0 = (Pgain_V + Igain_V + Dgain_V); // B0
CNTL_2P2Z_CoefStruct2.a2 = 0x00000000; // A2 = 0
CNTL_2P2Z_CoefStruct2.a1 = 0x04000000;//_IQ26(1.0); // A1 = 1 //CNTL_2P2Z_CoefStruct2.max =Dmax_V; //Clamp Hi //CNTL_2P2Z_CoefStruct2.min =_IQ24(0.0); //Clamp Min
EPwm1Regs.ETSEL.bit.INTEN = 1; // Enable INT
CNTL_2P2Z_CoefStruct2.b1 = (Igain_V-Pgain_V-Dgain_V-Dgain_V); // B1
CNTL_2P2Z_CoefStruct2.b0 = (Pgain_V + Igain_V + Dgain_V); // B0
CNTL_2P2Z_CoefStruct2.a2 = 0x00000000; // A2 = 0
CNTL_2P2Z_CoefStruct2.a1 = 0x04000000;//_IQ26(1.0); // A1 = 1 //CNTL_2P2Z_CoefStruct2.max =Dmax_V; //Clamp Hi //CNTL_2P2Z_CoefStruct2.min =_IQ24(0.0); //Clamp Min
EPwm1Regs.ETSEL.bit.INTEN = 1; // Enable INT
vloop_coeff_change = 0;
}
}
}
}
//——————-
//the next time CpuTimer0 'counter' reaches Period value go to A2
A_Task_Ptr = &A2;
//——————-
}
//the next time CpuTimer0 'counter' reaches Period value go to A2
A_Task_Ptr = &A2;
//——————-
}
//—————————————————————–
void A2(void)//—————————————————————–
{ SerialHostComms(); // Uncomment for FLASH config
//——————-
//the next time CpuTimer0 'counter' reaches Period value go to A1
A_Task_Ptr = &A1;
//——————-
}
void A2(void)//—————————————————————–
{ SerialHostComms(); // Uncomment for FLASH config
//——————-
//the next time CpuTimer0 'counter' reaches Period value go to A1
A_Task_Ptr = &A1;
//——————-
}
//=================================================================================
// B – TASKS
//=================================================================================
// B – TASKS
//=================================================================================
//———————————– USER —————————————-
//—————————————-
void B1(void)
//—————————————-
{
HistPtr++;
if (HistPtr >= HistorySize)
HistPtr = 0;
void B1(void)
//—————————————-
{
HistPtr++;
if (HistPtr >= HistorySize)
HistPtr = 0;
// BoxCar Averages – Input Raw samples into BoxCar arrays
//—————————————————————-
// Hist_Ipfc[HistPtr] = IpfcR;
Hist_Vbus[HistPtr] = VbusR;
Hist_VrectAvg[HistPtr] = (int16)(VrectAvg>>12);
//VrectAvg is in Q24. So first make it Q12 and then change it to int16
Hist_VrectRMS[HistPtr] = (int16)(VrectRMS>>12);
//VrectRMS is in Q24. So first make it Q12 and then change it to int16
Hist_Freq_Vin[HistPtr] = (int16)(Freq_Vin >>12);
//Freq_Vin is in Q15.
//—————————————————————-
// Hist_Ipfc[HistPtr] = IpfcR;
Hist_Vbus[HistPtr] = VbusR;
Hist_VrectAvg[HistPtr] = (int16)(VrectAvg>>12);
//VrectAvg is in Q24. So first make it Q12 and then change it to int16
Hist_VrectRMS[HistPtr] = (int16)(VrectRMS>>12);
//VrectRMS is in Q24. So first make it Q12 and then change it to int16
Hist_Freq_Vin[HistPtr] = (int16)(Freq_Vin >>12);
//Freq_Vin is in Q15.
// Measurements
//—————————————————————-
// view following variables in Watch Window as:
// Gui_Ipfc = Q??
// Gui_Vbus = Q??
// Gui_VL_fb = Q??
// Gui_VN_fb = Q??
//—————————————————————-
// view following variables in Watch Window as:
// Gui_Ipfc = Q??
// Gui_Vbus = Q??
// Gui_VL_fb = Q??
// Gui_VN_fb = Q??
temp_Scratch=0;
for(i=0; i<HistorySize; i++)
temp_Scratch = temp_Scratch + Hist_Vbus[i]; //Q12 * 8 = Q15
Gui_Vbus = ((long)temp_Scratch*(long)K_Vbus) >> 15; //Q15*Q15 >> 15 = Q15
for(i=0; i<HistorySize; i++)
temp_Scratch = temp_Scratch + Hist_Vbus[i]; //Q12 * 8 = Q15
Gui_Vbus = ((long)temp_Scratch*(long)K_Vbus) >> 15; //Q15*Q15 >> 15 = Q15
temp_Scratch=0;
for(i=0; i<HistorySize; i++)
temp_Scratch = temp_Scratch + Hist_VrectAvg[i]; //Q12 * 8 = Q15
Gui_VrectAvg = ((long)temp_Scratch*(long)K_VrectAvg) >> 15; //Q15*Q15 >> 15 = Q15
temp_Scratch=0;
for(i=0; i<HistorySize; i++)
temp_Scratch = temp_Scratch + Hist_VrectRMS[i]; //Q12 * 8 = Q15
Gui_VrectRMS = ((long)temp_Scratch*(long)K_Vrms) >> 15; //Q15*Q15 >> 15 = Q15
for(i=0; i<HistorySize; i++)
temp_Scratch = temp_Scratch + Hist_VrectAvg[i]; //Q12 * 8 = Q15
Gui_VrectAvg = ((long)temp_Scratch*(long)K_VrectAvg) >> 15; //Q15*Q15 >> 15 = Q15
temp_Scratch=0;
for(i=0; i<HistorySize; i++)
temp_Scratch = temp_Scratch + Hist_VrectRMS[i]; //Q12 * 8 = Q15
Gui_VrectRMS = ((long)temp_Scratch*(long)K_Vrms) >> 15; //Q15*Q15 >> 15 = Q15
temp_Scratch=0;
for(i=0; i<HistorySize; i++)
temp_Scratch = temp_Scratch + Hist_Freq_Vin[i]; //Q3 * 8 = Q6
Gui_Freq_Vin = ((long)temp_Scratch); //Q6
for(i=0; i<HistorySize; i++)
temp_Scratch = temp_Scratch + Hist_Freq_Vin[i]; //Q3 * 8 = Q6
Gui_Freq_Vin = ((long)temp_Scratch); //Q6
/* temp_Scratch=0;
for(i=0; i<HistorySize; i++)
temp_Scratch = temp_Scratch + Hist_KDCM[i]; //Q12 * 8 = Q15
Gui_KDCM = ((long)temp_Scratch)>> 3; //Q15
*/
Gui_KDCM = KDCM;
for(i=0; i<HistorySize; i++)
temp_Scratch = temp_Scratch + Hist_KDCM[i]; //Q12 * 8 = Q15
Gui_KDCM = ((long)temp_Scratch)>> 3; //Q15
*/
Gui_KDCM = KDCM;
//Multiply with longs to get proper result then shift by 14 to turn it back into an int16
//Vbus_set = ((long)Gui_Vbus_set*(long)iK_Vbus_set) >> 14;
//Vbus_set = ((long)Gui_Vbus_set*(long)iK_Vbus_set)>>5;//Q15*Q14 >> 5 =>Q24
VbusTarget = ((long)Gui_Vbus_set*(long)iK_Vbus_set)>>5;//Q15*Q14 >> 5 =>Q24
//—————–
//the next time CpuTimer1 'counter' reaches Period value go to B2
B_Task_Ptr = &B2;
//—————–
}
//Vbus_set = ((long)Gui_Vbus_set*(long)iK_Vbus_set) >> 14;
//Vbus_set = ((long)Gui_Vbus_set*(long)iK_Vbus_set)>>5;//Q15*Q14 >> 5 =>Q24
VbusTarget = ((long)Gui_Vbus_set*(long)iK_Vbus_set)>>5;//Q15*Q14 >> 5 =>Q24
//—————–
//the next time CpuTimer1 'counter' reaches Period value go to B2
B_Task_Ptr = &B2;
//—————–
}
//—————————————-
void B2(void) // Blink LED on the control CArd
//—————————————-
{
if(LedBlinkCnt==0)
{
GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1; //turn on/off LD3 on the controlCARD
LedBlinkCnt=5;
}
else
LedBlinkCnt–;
//—————–
//the next time CpuTimer1 'counter' reaches Period value go to B1
B_Task_Ptr = &B1;
//—————–
}
void B2(void) // Blink LED on the control CArd
//—————————————-
{
if(LedBlinkCnt==0)
{
GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1; //turn on/off LD3 on the controlCARD
LedBlinkCnt=5;
}
else
LedBlinkCnt–;
//—————–
//the next time CpuTimer1 'counter' reaches Period value go to B1
B_Task_Ptr = &B1;
//—————–
}
//=================================================================================
// C – TASKS
//=================================================================================
// C – TASKS
//=================================================================================
//——————————— USER ——————————————
//——————————————————
void C1(void) // Update Coefficients //——————————————————
{
if ((INCR_BUILD == 1)||(INCR_BUILD == 2))
{
GpioDataRegs.GPASET.bit.GPIO12 = 1; // Set High to turn the relay ON for BUILD 1 & 2.
}
if (INCR_BUILD == 3)
{
if (VbusTargetSlewed == 0) //
{
temp_zero = 0;
// temp_handle = 0;
CNTL_2P2Z_Ref2 = &temp_zero; // Slewed Voltage Command
// start_flag = 0;
}
void C1(void) // Update Coefficients //——————————————————
{
if ((INCR_BUILD == 1)||(INCR_BUILD == 2))
{
GpioDataRegs.GPASET.bit.GPIO12 = 1; // Set High to turn the relay ON for BUILD 1 & 2.
}
if (INCR_BUILD == 3)
{
if (VbusTargetSlewed == 0) //
{
temp_zero = 0;
// temp_handle = 0;
CNTL_2P2Z_Ref2 = &temp_zero; // Slewed Voltage Command
// start_flag = 0;
}
// if (start_flag == 1 && Vbus > VBUS_MIN)//Use this to start PFC from CCS watch window using "start_flag"
if (run_flag == 0 && Vbus > VBUS_MIN)//Use this to start PFC in stand alone mode.
//Comment this line and uncomment the line above to start PFC from CCS watch window using start_flag
{
VbusTargetSlewed = Vbus+ init_boost; // Start slewing the boost command from a value slightly greater than the PFC output voltage CNTL_2P2Z_Ref2 = &VbusTargetSlewed; // Slewed Voltage Command
// start_flag = 1; // This flag makes sure above code is executed only once when..
// the VbusTarget command goes from zero to a value > 150V
if (run_flag == 0 && Vbus > VBUS_MIN)//Use this to start PFC in stand alone mode.
//Comment this line and uncomment the line above to start PFC from CCS watch window using start_flag
{
VbusTargetSlewed = Vbus+ init_boost; // Start slewing the boost command from a value slightly greater than the PFC output voltage CNTL_2P2Z_Ref2 = &VbusTargetSlewed; // Slewed Voltage Command
// start_flag = 1; // This flag makes sure above code is executed only once when..
// the VbusTarget command goes from zero to a value > 150V
//—————–
//the next time CpuTimer2 'counter' reaches Period value go to C2
C_Task_Ptr = &C2;
//—————–
}
else
{
//C_Task_Ptr = &C1;
C_Task_Ptr = &C3;
}
}
}
//—————————————-
void C2(void) //Slew Rate ("Soft Start")
//—————————————-
{
GpioDataRegs.GPASET.bit.GPIO12 = 1; // Set High to turn the relay ON
//the next time CpuTimer2 'counter' reaches Period value go to C2
C_Task_Ptr = &C2;
//—————–
}
else
{
//C_Task_Ptr = &C1;
C_Task_Ptr = &C3;
}
}
}
//—————————————-
void C2(void) //Slew Rate ("Soft Start")
//—————————————-
{
GpioDataRegs.GPASET.bit.GPIO12 = 1; // Set High to turn the relay ON
// pfcSlewRate has to be a positive value
//pfc_slew_temp = VbusTarget – VbusTargetSlewed;
pfc_slew_temp = VBUS_TARGET – VbusTargetSlewed;//VBUS_TARGET=395v
//pfc_slew_temp = VbusTarget – VbusTargetSlewed;
pfc_slew_temp = VBUS_TARGET – VbusTargetSlewed;//VBUS_TARGET=395v
if (pfc_slew_temp >= VbusSlewRate) // Positive Command. Slewed Vbus is less than VBUS_TARGET, so increase it. This is
//VbusSlewRate=25600Q24.implement soft-start for Vbus. VbusSlewRate is initialized at the begining of this file.
{
VbusTargetSlewed = VbusTargetSlewed + VbusSlewRate;
}
else
{
//Soft-start is complete. So set the flag for RUN mode and go to Task C3 for RUN time adjustment of Vbus
// if ((-1)*(pfc_slew_temp) >= VbusSlewRate) // Negative Command
// {
// VbusTargetSlewed = VbusTargetSlewed – VbusSlewRate;
VbusTargetSlewed = VBUS_TARGET;
VbusTarget = VBUS_TARGET;
Gui_Vbus_set = VBUS_RATED_VOLTS*64;//Q15, Set Gui Vbus set point to initial value VBUS_RATED_VOLTS
start_flag = 0;
run_flag = 1;
C_Task_Ptr = &C3;
// }
}
//VbusSlewRate=25600Q24.implement soft-start for Vbus. VbusSlewRate is initialized at the begining of this file.
{
VbusTargetSlewed = VbusTargetSlewed + VbusSlewRate;
}
else
{
//Soft-start is complete. So set the flag for RUN mode and go to Task C3 for RUN time adjustment of Vbus
// if ((-1)*(pfc_slew_temp) >= VbusSlewRate) // Negative Command
// {
// VbusTargetSlewed = VbusTargetSlewed – VbusSlewRate;
VbusTargetSlewed = VBUS_TARGET;
VbusTarget = VBUS_TARGET;
Gui_Vbus_set = VBUS_RATED_VOLTS*64;//Q15, Set Gui Vbus set point to initial value VBUS_RATED_VOLTS
start_flag = 0;
run_flag = 1;
C_Task_Ptr = &C3;
// }
}
//—————–
//the next time CpuTimer2 'counter' reaches Period value go to C3
C_Task_Ptr = &C1;
//—————–
}
//the next time CpuTimer2 'counter' reaches Period value go to C3
C_Task_Ptr = &C1;
//—————–
}
//—————————————–
void C3(void) ////—————————————–
{
if (run_flag == 1) //If soft-start is over and PFC running normally
{
// pfcSlewRate has to be a positive value
pfc_slew_temp = VbusTarget – VbusTargetSlewed;
void C3(void) ////—————————————–
{
if (run_flag == 1) //If soft-start is over and PFC running normally
{
// pfcSlewRate has to be a positive value
pfc_slew_temp = VbusTarget – VbusTargetSlewed;
//pfc_slew_temp = VBUS_TARGET – VbusTargetSlewed;
if (pfc_slew_temp >= VbusSlewRate) // Positive Command. Increase Vbus
{
VbusTargetSlewed = VbusTargetSlewed + VbusSlewRate;
}
else
{
if ((-1)*(pfc_slew_temp) >= VbusSlewRate) // Negative Command. Reduce Vbus
{
VbusTargetSlewed = VbusTargetSlewed – VbusSlewRate;
// VbusTargetSlewed = VBUS_TARGET;
// start_flag = 0;
}
}
}
{
VbusTargetSlewed = VbusTargetSlewed + VbusSlewRate;
}
else
{
if ((-1)*(pfc_slew_temp) >= VbusSlewRate) // Negative Command. Reduce Vbus
{
VbusTargetSlewed = VbusTargetSlewed – VbusSlewRate;
// VbusTargetSlewed = VBUS_TARGET;
// start_flag = 0;
}
}
}
//—————–
//the next time CpuTimer2 'counter' reaches Period value go to C1
C_Task_Ptr = &C1;
//—————–
//the next time CpuTimer2 'counter' reaches Period value go to C1
C_Task_Ptr = &C1;
//—————–
}