matlab_23550/Inu/param.c
2024-12-27 10:50:32 +03:00

427 lines
12 KiB
C

/**************************************************************************
Description: Ôóíêöèè äëÿ ïðè¸ìà è âûäà÷è ïàðàìåòðîâ.
Àâòîð: Óëèòîâñêèé Ä.È.
Äàòà ïîñëåäíåãî îáíîâëåíèÿ: 2021.11.08
**************************************************************************/
#include "def.h"
#include "param.h"
#pragma CODE_SECTION(input_param, "ramfuncs");
#pragma CODE_SECTION(output_param, "ramfuncs");
extern short test_param(void);
extern void process_sgm_parameters(void);
// Èçìåíÿåò çíà÷åíèå ïàðàìåòðà
void input_param(unsigned short num, unsigned short val) {
switch ( num ) {
case 180://rf.PsiZ, %*10 îò PSI_BAZ
if ( (val <= 2000) && (val != param[num]) ) {
param[num] = val;
rf.PsiZ = (float)val*0.001;//%*10 -> o.e.
eprom.writeRequestNumber += 1;
}
break;
case 200://offset.Ia1, åä. ÀÖÏ
if ( (val >= 1748) && (val <= 4096) && (val != param[num]) ) {
offset.Ia1 = param[num] = val;
eprom.writeRequestNumber += 1;
}
break;
case 201://offset.Ib1, åä. ÀÖÏ
if ( (val >= 1748) && (val <= 4096) && (val != param[num]) ) {
offset.Ib1 = param[num] = val;
eprom.writeRequestNumber += 1;
}
break;
case 202://offset.Ic1, åä. ÀÖÏ
if ( (val >= 1748) && (val <= 4096) && (val != param[num]) ) {
offset.Ic1 = param[num] = val;
eprom.writeRequestNumber += 1;
}
break;
case 203://offset.Udc1, åä. ÀÖÏ
if ( (val >= 1748) && (val <= 4096) && (val != param[num]) ) {
offset.Udc1 = param[num] = val;
eprom.writeRequestNumber += 1;
}
break;
case 206://offset.Ia2, åä. ÀÖÏ
if ( (val >= 1748) && (val <= 4096) && (val != param[num]) ) {
offset.Ia2 = param[num] = val;
eprom.writeRequestNumber += 1;
}
break;
case 207://offset.Ib2, åä. ÀÖÏ
if ( (val >= 1748) && (val <= 4096) && (val != param[num]) ) {
offset.Ib2 = param[num] = val;
eprom.writeRequestNumber += 1;
}
break;
case 208://offset.Ic2, åä. ÀÖÏ
if ( (val >= 1748) && (val <= 4096) && (val != param[num]) ) {
offset.Ic2 = param[num] = val;
eprom.writeRequestNumber += 1;
}
break;
case 209://offset.Udc2, åä. ÀÖÏ
if ( (val >= 1748) && (val <= 4096) && (val != param[num]) ) {
offset.Udc2 = param[num] = val;
eprom.writeRequestNumber += 1;
}
break;
case 210://cc.Kp, %
if ( (val <= 5000) && (val != param[num]) ) {
param[num] = val;
cc.Kp = (float)val*cc.KpOrig;
eprom.writeRequestNumber += 1;
}
break;
case 211://cc.Ki, %
if ( (val <= 5000) && (val != param[num]) ) {
param[num] = val;
cc.Ki = (float)val*cc.KiOrig;
eprom.writeRequestNumber += 1;
}
break;
case 212://cf.Kp, %
if ( (val <= 5000) && (val != param[num]) ) {
param[num] = val;
cf.Kp = (float)val*cf.KpOrig;
eprom.writeRequestNumber += 1;
}
break;
case 213://cf.Ki, %
if ( (val <= 5000) && (val != param[num]) ) {
param[num] = val;
cf.Ki = (float)val*cf.KiOrig;
eprom.writeRequestNumber += 1;
}
break;
case 214://csp.Kp, %
if ( (val <= 5000) && (val != param[num]) ) {
param[num] = val;
csp.Kp = (float)val*csp.KpOrig;
eprom.writeRequestNumber += 1;
}
break;
case 215://csp.Ki, %
if ( (val <= 5000) && (val != param[num]) ) {
param[num] = val;
csp.Ki = (float)val*csp.KiOrig;
eprom.writeRequestNumber += 1;
}
break;
case 220://protect.IacMax, % îò IAC_SENS_MAX
if ( (val <= 99) && (val != param[num]) ) {
param[num] = val;
protect.IacMax = (short)(2047.*(float)val*0.01);//% -> åä. ÀÖÏ
protect.IacMin = -protect.IacMax;
eprom.writeRequestNumber += 1;
}
break;
case 221://protect.UdcMax, % îò U_NOM
if ( (val <= 136) && (val != param[num]) ) {
param[num] = val;
protect.UdcMax = (float)val*0.01;//% -> o.e.
eprom.writeRequestNumber += 1;
}
break;
case 222://IzLim, % îò I_BAZ
if ( (val <= 200) && (val != param[num]) ) {
param[num] = val;
IzLim = (float)val*0.01;//% -> o.e.
eprom.writeRequestNumber += 1;
}
break;
case 223://cf.IdLim, % îò I_BAZ
if ( (val <= 200) && (val != param[num]) ) {
param[num] = val;
cf.IdLim = (float)val*0.01;//% -> o.e.
cf.IdLimNeg = cf.IdLim*(-0.4);
eprom.writeRequestNumber += 1;
}
break;
case 224://csp.IqLim, % îò I_BAZ
if ( (val <= 200) && (val != param[num]) ) {
param[num] = val;
csp.IqLim = (float)val*0.01;//% -> o.e.
csp.IqLimNeg = -csp.IqLim;
eprom.writeRequestNumber += 1;
}
break;
case 225://protect.UdcMin, % îò U_NOM
if ( (val <= 110) && (val != param[num]) ) {
param[num] = val;
protect.UdcMin = (float)val*0.01;//% -> o.e.
eprom.writeRequestNumber += 1;
}
break;
case 226://protect.WmMax, % îò N_NOM
if ( (val <= 200) && (val != param[num]) ) {
param[num] = val;
protect.WmMax = (float)val*0.01;//% -> o.e.
eprom.writeRequestNumber += 1;
}
break;
case 228://rf.WmNomPsi, % îò N_NOM
if ( (val <= 200) && (val != param[num]) ) {
param[num] = val;
rf.WmNomPsi = (float)val*0.01;//% -> o.e.
eprom.writeRequestNumber += 1;
}
break;
case 229://rf.YlimPsi, % îò Y_LIM
if ( (val <= 101) && (val != param[num]) ) {
param[num] = val;
rf.YlimPsi = (float)val*0.01*Y_LIM;//% -> åä. ñ÷¸ò÷èêà òàéìåðà
eprom.writeRequestNumber += 1;
}
break;
case 231://protect.TudcMin, ìñ
if ( (val >= 1) && (val <= 8500) && (val != param[num]) ) {
param[num] = val;
protect.TudcMin = (unsigned short)((float)val*0.001/TY);
eprom.writeRequestNumber += 1;
}
break;
case 233://protect.TwmMax, ìñ
if ( (val >= 1) && (val <= 8500) && (val != param[num]) ) {
param[num] = val;
protect.TwmMax = (unsigned short)((float)val*0.001/TY);
eprom.writeRequestNumber += 1;
}
break;
case 244://rs.WlimIncr, ìñ
if ( (val >= 1) && (val != param[num]) ) {
param[num] = val;
// èçì. íà 1.0 çà ñòîëüêî-òî ìñ
rs.WlimIncr = 1.0*TY*DECIM_PSI_WM_PM/((float)val*0.001);
eprom.writeRequestNumber += 1;
}
break;
case 245://csp.IlimIncr, ìñ
if ( (val >= 1) && (val != param[num]) ) {
param[num] = val;
// èçì. íà I_BAZ çà ñòîëüêî-òî ìñ
csp.IlimIncr = 1.0*TY*DECIM_PSI_WM_PM/((float)val*0.001);
eprom.writeRequestNumber += 1;
}
break;
case 248://rp.PlimIncr, ìñ
if ( (val >= 1) && (val != param[num]) ) {
param[num] = val;
// èçì. íà 1.0 çà ñòîëüêî-òî ìñ
rp.PlimIncr = 1.0*TY*DECIM_PSI_WM_PM/((float)val*0.001);
eprom.writeRequestNumber += 1;
}
break;
case 269://KmeCorr, %*100
if ( (val >= 5000) && (val <= 20000) && (val != param[num]) ) {
param[num] = val;
KmeCorr = (float)val*0.0001;//%*100 -> o.e.
eprom.writeRequestNumber += 1;
}
break;
case 285://Kudc, ìñ*10
if ( (val >= 1) && (val <= 20000) && (val != param[num]) ) {
param[num] = val;
Kudc = (TY*10000.)/(float)val;
if ( Kudc > 1.0 )
Kudc = 1.0;
eprom.writeRequestNumber += 1;
}
break;
case 286://Kwm, ìñ*10
if ( (val >= 1) && (val <= 20000) && (val != param[num]) ) {
param[num] = val;
Kwm = (TY*10000.)/(float)val;
if ( Kwm > 1.0 )
Kwm = 1.0;
eprom.writeRequestNumber += 1;
}
break;
case 288://rs.Kwmz, ìñ
if ( (val >= 1) && (val <= 20000) && (val != param[num]) ) {
param[num] = val;
rs.Kwmz = (TY*DECIM_PSI_WM_PM*1000.)/(float)val;
eprom.writeRequestNumber += 1;
}
break;
case 289://rf.Kpsiz, ìñ
if ( (val >= 1) && (val <= 20000) && (val != param[num]) ) {
param[num] = val;
rf.Kpsiz = (TY*DECIM_PSI_WM_PM*1000.)/(float)val;
eprom.writeRequestNumber += 1;
}
break;
case 290://Kme, ìñ
if ( (val >= 1) && (val <= 20000) && (val != param[num]) ) {
param[num] = val;
Kme = (TY*1000.)/(float)val;
eprom.writeRequestNumber += 1;
}
break;
case 292://rp.Kpmz, ìñ
if ( (val >= 1) && (val <= 20000) && (val != param[num]) ) {
param[num] = val;
rp.Kpmz = (TY*DECIM_PSI_WM_PM*1000.)/(float)val;
eprom.writeRequestNumber += 1;
}
break;
case 303://sgmPar.Rs, ìêÎì
if ( val != param[num] ) {
param[num] = val;
sgmPar.Rs = (float)val*1e-6;//ìêÎì -> Îì
eprom.writeRequestNumber += 1;
}
break;
case 304://sgmPar.Lls, ìêÃí*10
if ( val != param[num] ) {
param[num] = val;
sgmPar.Lls = (float)val*1e-7;//ìêÃí*10 -> Ãí
process_sgm_parameters();
eprom.writeRequestNumber += 1;
}
break;
case 305://sgmPar.Rr, ìêÎì
if ( val != param[num] ) {
param[num] = val;
sgmPar.Rr = (float)val*1e-6;//ìêÎì -> Îì
process_sgm_parameters();
eprom.writeRequestNumber += 1;
}
break;
case 306://sgmPar.Llr, ìêÃí*10
if ( val != param[num] ) {
param[num] = val;
sgmPar.Llr = (float)val*1e-7;//ìêÃí*10 -> Ãí
process_sgm_parameters();
eprom.writeRequestNumber += 1;
}
break;
case 307://sgmPar.Lm, ìêÃí
if ( val != param[num] ) {
param[num] = val;
sgmPar.Lm = (float)val*1e-6;//ìêÃí -> Ãí
process_sgm_parameters();
eprom.writeRequestNumber += 1;
}
break;
default:
if ( num < PAR_NUMBER ) {
param[num] = val;
}
break;
} //switch ( num )
} //void input_param(unsigned short num, unsigned short val)
// Âûäà¸ò çíà÷åíèå ïàðàìåòðà
unsigned short output_param(unsigned short num) {
static unsigned short output;
switch ( num ) {
case 1: //udc1, o.e. -> o.e.*CONTROLLER_GAIN
if ( state == STATE_SHUTDOWN ) {
output = (unsigned short)(emerg.udc1*CONTROLLER_GAIN);
}
else {
output = (unsigned short)(out.udc1*CONTROLLER_GAIN);
}
break;
case 2: //udc2, o.e. -> o.e.*CONTROLLER_GAIN
if ( state == STATE_SHUTDOWN ) {
output = (unsigned short)(emerg.udc2*CONTROLLER_GAIN);
}
else {
output = (unsigned short)(out.udc2*CONTROLLER_GAIN);
}
break;
case 5: //iac1, o.e. -> o.e.*CONTROLLER_GAIN
if ( state == STATE_SHUTDOWN ) {
output = (unsigned short)(emerg.iac1*CONTROLLER_GAIN);
}
else {
output = (unsigned short)(out.iac1*CONTROLLER_GAIN);
}
break;
case 6: //iac2, o.e. -> o.e.*CONTROLLER_GAIN
if ( state == STATE_SHUTDOWN ) {
output = (unsigned short)(emerg.iac2*CONTROLLER_GAIN);
}
else {
output = (unsigned short)(out.iac2*CONTROLLER_GAIN);
}
break;
case 7: //me, o.e. -> (o.e. + CONTROLLER_BIAS)*CONTROLLER_GAIN
if ( state == STATE_SHUTDOWN ) {
if ( emerg.me > CONTROLLER_BIAS )
output = (unsigned short)((CONTROLLER_BIAS + CONTROLLER_BIAS)*CONTROLLER_GAIN);
else if ( emerg.me > -CONTROLLER_BIAS )
output = (unsigned short)((emerg.me + CONTROLLER_BIAS)*CONTROLLER_GAIN);
else
output = 0;
}
else {
if ( out.me > CONTROLLER_BIAS )
output = (unsigned short)((CONTROLLER_BIAS + CONTROLLER_BIAS)*CONTROLLER_GAIN);
else if ( out.me > -CONTROLLER_BIAS )
output = (unsigned short)((out.me + CONTROLLER_BIAS)*CONTROLLER_GAIN);
else
output = 0;
}
break;
case 8: //nm, o.e. -> (o.e. + CONTROLLER_BIAS)*CONTROLLER_GAIN
if ( state == STATE_SHUTDOWN ) {
if ( emerg.wm > CONTROLLER_BIAS )
output = (unsigned short)((CONTROLLER_BIAS + CONTROLLER_BIAS)*CONTROLLER_GAIN);
else if ( emerg.wm > -CONTROLLER_BIAS )
output = (unsigned short)((emerg.wm + CONTROLLER_BIAS)*CONTROLLER_GAIN);
else
output = 0;
}
else {
if ( out.wm > CONTROLLER_BIAS )
output = (unsigned short)((CONTROLLER_BIAS + CONTROLLER_BIAS)*CONTROLLER_GAIN);
else if ( out.wm > -CONTROLLER_BIAS )
output = (unsigned short)((out.wm + CONTROLLER_BIAS)*CONTROLLER_GAIN);
else
output = 0;
}
break;
case 9: //pm, o.e. -> (o.e. + CONTROLLER_BIAS)*CONTROLLER_GAIN
if ( state == STATE_SHUTDOWN ) {
if ( emerg.pm > CONTROLLER_BIAS )
output = (unsigned short)((CONTROLLER_BIAS + CONTROLLER_BIAS)*CONTROLLER_GAIN);
else if ( emerg.pm > -CONTROLLER_BIAS )
output = (unsigned short)((emerg.pm + CONTROLLER_BIAS)*CONTROLLER_GAIN);
else
output = 0;
}
else {
if ( out.pm > CONTROLLER_BIAS )
output = (unsigned short)((CONTROLLER_BIAS + CONTROLLER_BIAS)*CONTROLLER_GAIN);
else if ( out.pm > -CONTROLLER_BIAS )
output = (unsigned short)((out.pm + CONTROLLER_BIAS)*CONTROLLER_GAIN);
else
output = 0;
}
break;
case 10: //compound
output = faultNo + (inuWork<<7);
break;
default:
output = param[num];
break;
} //switch ( num )
return output;
} //unsigned short output_param(unsigned short num)