-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dynamic KP control.h
122 lines (106 loc) · 2.92 KB
/
Dynamic KP control.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
void Class_InverterAlg::Alg_Int_InvCurrRmsReg(void)
{
INT16 i16_TmpRMSRef_0,i16_TmpAx_0,i16_TmpBx_0,i16_TmpCx_0,i16_TmpDx_0,i16_TmpKp_0,i16_TmpKi_0;
i16_TmpRMSRef_0 = (((INT32)objInvCtrl.m_i16_IrefRunM_0 * 2897)>>12);
if(objInverter.m_st_FlagInv.bInv != 0
&&objOutputXfer.m_st_OutputXferResult.bInvRelay == 1)
{
i16_TmpAx_0 = ((INT32)i16_TmpRMSRef_0 * 205)>>12;
i16_TmpBx_0 = 250;
i16_TmpCx_0 = MAX2(i16_TmpAx_0,i16_TmpBx_0);
if(m_i16_IrefSetMBake != objInvCtrl.m_i16_IrefSetM)
{
if(objInvCtrl.m_i16_IrefSetM < 880
&&m_i32_R_0 >= 768)
{
m_un_IntgInvIRRms_0.half.hword = 1536;
}
else if(objInvCtrl.m_i16_IrefSetM < 880
&&m_i32_R_0 >= 512)
{
m_un_IntgInvIRRms_0.half.hword = 1024;
}
else if(objInvCtrl.m_i16_IrefSetM < 880)
{
m_un_IntgInvIRRms_0.half.hword = 512;
}
else
{
m_un_IntgInvIRRms_0.dword = 0;
}
}
else
{
if((abs(m_i16_IerrInvRms_0) >= i16_TmpCx_0)
&&(m_i16_IerrInvRms_0 < 0)
&&(m_un_IntgInvIRRms_0.dword > 0)
&&(objInvCtrl.m_i16_IrefSetM > 2896))
{
m_un_IntgInvIRRms_0.dword -= 131070;
if(m_un_IntgInvIRRms_0.dword < 0)
{
m_un_IntgInvIRRms_0.dword = 0;
}
}
if((abs(m_i16_IerrInvRms_0) >= i16_TmpCx_0)
&&(m_i16_IerrInvRms_0 > 0)
&&(m_un_IntgInvIRRms_0.dword < 0)
&&(objInvCtrl.m_i16_IrefSetM > 2896))
{
m_un_IntgInvIRRms_0.dword += 16384;
if(m_un_IntgInvIRRms_0.dword > 0)
{
m_un_IntgInvIRRms_0.dword = 0;
}
}
}
if(abs(m_i16_IerrInvRms_0) >= 250
&&(objInvCtrl.m_i16_IrefSetM > 2896))
{
i16_TmpKp_0 = m_i16_KpInvCurrRmsReg_0 * 5;
}
else
{
i16_TmpKp_0 -= 5;
if(i16_TmpKp_0 <= m_i16_KpInvCurrRmsReg_0)
{
i16_TmpKp_0 = m_i16_KpInvCurrRmsReg_0;
}
}
if(objInvCtrl.m_i16_IrefSetM >= 614)
{
i16_TmpKi_0 = m_i16_KiInvCurrRmsReg_0;
}
else if(objInvCtrl.m_i16_IrefSetM >= 351)
{
i16_TmpKi_0 = m_i16_KiInvCurrRmsReg_0 + 20;
}
else
{
i16_TmpKi_0 = m_i16_KiInvCurrRmsReg_0 * 2;
}
i16_TmpDx_0 = ((INT32)i16_TmpRMSRef_0 * 1536)>>10;
if((objOutput.m_i16_TpriIoutPrms <<2) >= i16_TmpDx_0
&&objOutput.m_i16_TpriIoutPrms >= 154
&&(objOutput.m_i16_TsndIoutPrms <<2) <= i16_TmpRMSRef_0)
{
m_i16_IerrInvRms_0 = i16_TmpRMSRef_0 - (objOutput.m_i16_TpriIoutPrms<<2);
UPDNLMT16(m_i16_IerrInvRms_0,310,-310);
}
else
{
m_i16_IerrInvRms_0 = i16_TmpRMSRef_0 - (objOutput.m_i16_TsndIoutPrms<<2);
UPDNLMT16(m_i16_IerrInvRms_0,310,-310);
}
m_i16_IRmsCmp_0 = m_un_IntgInvIRRms_0.half.hword + (((INT32)m_i16_IerrInvRms_0 * i16_TmpKp_0)>>12);
UPDNLMT16(m_i16_IRmsCmp_0,4096,-4096);
m_un_IntgInvIRRms_0.dword += ((INT32)m_i16_IerrInvRms_0 * i16_TmpKi_0);
UPDNLMT32(m_un_IntgInvIRRms_0.dword,0x10000000,-0x10000000);
m_i16_IRmsCmp_0 = ((INT32)m_i16_IRmsCmp_0 * 5792)>>12;
}
else
{
m_un_IntgInvIRRms_0.dword = 0;
m_i16_IRmsCmp_0 = 0;
}
}