static WORD TBTudc123schwellen(int hovsense,int sovsense, BYTE b, WORD Ubatt,WORD Uabgr)
{
# define Umain usMIT_UDC2
# define LOWER(val,proz) (val - __divu(__mulu(val,proz),100))
# define HIGHER(val,proz) (val + __divu(__mulu(val,proz),100))
# define TIMER(i,ge,s) (++timer[i] ge s && (timer[i]=0,1))
static WORD __direct udc_timer[3][3];
WORD __direct * timer;
static union schw_t __direct s;
timer= udc_timer[b];
s.w=0;
/*** Auswertung der Schwellen von Udc1 ***/
if (Ubatt <= usUMIN_DC1) {
if (sovsense && TIMER(0,>=,vdtumin1) ) s.ein.u1_lt_umin=1;
if (Ubatt <= LOWER(usUMAX_DC1,vdUmax)) s.aus.u1_gt_umax=1;
}
else {
if (Ubatt > usUMAX_DC1) {
if (hovsense&&sovsense && TIMER(0,>,vdtumax)) s.ein.u1_gt_umax=1;
if (Ubatt > HIGHER(usUMIN_DC1,vdUmin1)) s.aus.u1_lt_umin=1;
}
else {
timer[0]= 0;
if (Ubatt > HIGHER(usUMIN_DC1,vdUmin1)) s.aus.u1_lt_umin=1;
if (Ubatt <= LOWER(usUMAX_DC1,vdUmax)) s.aus.u1_gt_umax=1;
}
}
if (sovsense && Ubatt <= vUwarndc1) s.ein.u1_lt_uwarn=1;
else if (Ubatt > HIGHER(vUwarndc1,vdUmin1)) s.aus.u1_lt_uwarn=1;
if (b==0) {
/*** Auswertung der Schwellen von Udc2 ***/
if ( Umain <= vUmindc2 ) {
if (sovsense && TIMER(1,>=,vdtumin2) ) s.ein.u2_lt_umin=1;
s.aus.u2_gt_umax=1;
}
else {
if ( Umain > vUmaxdc2 ) {
if (hovsense&&sovsense && TIMER(1,>,vdtumax) ) s.ein.u2_gt_umax=1;
s.aus.u2_lt_umin=1;
}
else {
timer[1]= 0;
if ( Umain > HIGHER(vUmindc2,vdUmin2) ) s.aus.u2_lt_umin=1;
if ( Umain <= LOWER(vUmaxdc2,vdUmax) ) s.aus.u2_gt_umax=1;
}
}
}
{ /*** Auswertung der Schwellen von Udc3 ***/
WORD umin3, umax3, dumin3;
if (S==0) umin3=vUmindc3 , umax3=vUmaxdc3 , dumin3=vdUmin3;
if (S==1) umin3=usUMIN_DC1, umax3=usUMAX_DC1, dumin3=vdUmin1;
if ( Uabgr <= umin3 ) {
if (sovsense && TIMER(2,>=,vdtumin1)) s.ein.u3_lt_umin=1;
if (Uabgr <= LOWER(umax3,vdUmax)) s.aus.u3_gt_umax=1;
}
else {
if ( Uabgr > umax3 ) {
if (hovsense&&sovsense && TIMER(2,>,vdtumax) ) s.ein.u3_gt_umax=1;
if (Uabgr > HIGHER(umin3,dumin3)) s.aus.u3_lt_umin=1;
}
else {
timer[2]=0;
if (Uabgr > HIGHER(umin3,dumin3)) s.aus.u3_lt_umin=1;
if (Uabgr <= LOWER(umax3,vdUmax)) s.aus.u3_gt_umax=1;
}
}
}
return s.w;
#undef Umain
#undef LOWER
#undef HIGHER
#undef TIMER
}
static void TBTschwellen_check(int hovs, int sovs)
{
# define PSS_ein DTR_WORD(8,0)=0x0190
# define PSS_aus DTR_WORD(8,0)=0x0290
# define UNV_ein DTR_WORD(9,0)=0x0001
# define UNV_aus DTR_WORD(9,0)=0x0101
# define LED_UgtUMIN pinLED6
# define LED_UgtUMAX pinLED7
static union schw_t __direct s[3], sand, sor_;
BYTE b=0;
if (BAT(2)) b|=2;
if (BAT(3)) b|=4;
s[0].w= TBTudc123schwellen(hovs,sovs, 0, usMIT_UDC1,usMIT_UDC3);
if (S==1) {
if (s[0].ein.u2_lt_umin ) pinLED6=0, UNV_aus;
if (s[0].aus.u2_lt_umin ) pinLED6=1, UNV_ein;
if (s[0].ein.u2_gt_umax ) pinLED7=1, PSS_aus, UNV_aus;
if (s[0].aus.u2_gt_umax ) pinLED7=0, PSS_ein;
if (s[0].ein.u1_lt_uwarn) Can.CDZ.K.k1=1;
if (s[0].ein.u1_gt_umax ) Err.Alarm.bit.u1_gt_umax =1;
if (s[0].aus.u1_gt_umax ) Err.Alarm.bit.u1_gt_umax =0;
if (s[0].ein.u1_lt_umin ) Err.Alarm.bit.u1_lt_umin =1;
if (s[0].aus.u1_lt_umin ) Err.Alarm.bit.u1_lt_umin =0;
if (s[0].ein.u1_lt_uwarn) Err.Alarm.bit.u1_lt_uwarn=1;
if (s[0].aus.u1_lt_uwarn) Err.Alarm.bit.u1_lt_uwarn=0;
if (s[0].ein.u2_gt_umax ) Err.Alarm.bit.u2_gt_umax =1;
if (s[0].aus.u2_gt_umax ) Err.Alarm.bit.u2_gt_umax =0;
if (s[0].ein.u2_lt_umin ) Err.Alarm.bit.u2_lt_umin =1;
if (s[0].aus.u2_lt_umin ) Err.Alarm.bit.u2_lt_umin =0;
if (s[0].ein.u3_gt_umax ) Err.Alarm.bit.u3_gt_umax =1;
if (s[0].aus.u3_gt_umax ) Err.Alarm.bit.u3_gt_umax =0;
if (s[0].ein.u3_lt_umin ) Err.Alarm.bit.u3_lt_umin =1;
if (s[0].aus.u3_lt_umin ) Err.Alarm.bit.u3_lt_umin =0;
return;
}
if (b&2) s[1].w= TBTudc123schwellen(hovs,sovs, 1, Can.BM1.u1[0],Can.BM1.u3[0]);
else s[1].bits.ein=0x00, s[1].bits.aus=0xff;
if (b&4) s[2].w= TBTudc123schwellen(hovs,sovs, 2, Can.BM1.u1[1],Can.BM1.u3[1]);
else s[2].bits.ein=0x00, s[2].bits.aus=0xff;
sand.w= s[0].w & s[1].w & s[2].w;
sor_.w= s[0].w | s[1].w | s[2].w;
if (sor_.ein.u1_lt_umin ) pinLED6=0;
if (sand.aus.u1_lt_umin ) pinLED6=1;
if (sor_.ein.u1_gt_umax ) pinLED7=1, PSS_aus;
if (sand.aus.u1_gt_umax ) pinLED7=0, PSS_ein;
if (sor_.ein.u1_lt_uwarn) Can.CDZ.K.k1=1;
if (sand.aus.u1_lt_uwarn) Can.CDZ.K.k1=0;
if (s[0].ein.u2_lt_umin ) UNV_aus;
if (s[0].aus.u2_lt_umin ) UNV_ein;
if (s[0].ein.u2_gt_umax ) UNV_aus;
if (sor_.ein.u1_gt_umax ) Err.Alarm.bit.u1_gt_umax =1;
if (sand.aus.u1_gt_umax ) Err.Alarm.bit.u1_gt_umax =0;
if (sor_.ein.u1_lt_umin ) Err.Alarm.bit.u1_lt_umin =1;
if (sand.aus.u1_lt_umin ) Err.Alarm.bit.u1_lt_umin =0;
if (sor_.ein.u1_lt_uwarn) Err.Alarm.bit.u1_lt_uwarn=1;
if (sand.aus.u1_lt_uwarn) Err.Alarm.bit.u1_lt_uwarn=0;
if (s[0].ein.u2_gt_umax ) Err.Alarm.bit.u2_gt_umax =1;
if (s[0].aus.u2_gt_umax ) Err.Alarm.bit.u2_gt_umax =0;
if (s[0].ein.u2_lt_umin ) Err.Alarm.bit.u2_lt_umin =1;
if (s[0].aus.u2_lt_umin ) Err.Alarm.bit.u2_lt_umin =0;
if (sor_.ein.u3_gt_umax ) Err.Alarm.bit.u3_gt_umax =1;
if (sand.aus.u3_gt_umax ) Err.Alarm.bit.u3_gt_umax =0;
if (sor_.ein.u3_lt_umin ) Err.Alarm.bit.u3_lt_umin =1;
if (sand.aus.u3_lt_umin ) Err.Alarm.bit.u3_lt_umin =0;
{
if (s[0].ein.u1_gt_umax ) Err.Alarm.bit.u1_gt_umax1 =1;
if (s[0].aus.u1_gt_umax ) Err.Alarm.bit.u1_gt_umax1 =0;
if (s[0].ein.u1_lt_umin ) Err.Alarm.bit.u1_lt_umin1 =1;
if (s[0].aus.u1_lt_umin ) Err.Alarm.bit.u1_lt_umin1 =0;
if (s[0].ein.u1_lt_uwarn) Err.Alarm.bit.u1_lt_uwarn1=1;
if (s[0].aus.u1_lt_uwarn) Err.Alarm.bit.u1_lt_uwarn1=0;
if (s[0].ein.u3_gt_umax ) Err.Alarm.bit.u3_gt_umax1 =1;
if (s[0].aus.u3_gt_umax ) Err.Alarm.bit.u3_gt_umax1 =0;
if (s[0].ein.u3_lt_umin ) Err.Alarm.bit.u3_lt_umin1 =1;
if (s[0].aus.u3_lt_umin ) Err.Alarm.bit.u3_lt_umin1 =0;
}
if (b&2) {
if (s[1].ein.u1_gt_umax ) Err.Alarm.bit.u1_gt_umax2 =1;
if (s[1].aus.u1_gt_umax ) Err.Alarm.bit.u1_gt_umax2 =0;
if (s[1].ein.u1_lt_umin ) Err.Alarm.bit.u1_lt_umin2 =1;
if (s[1].aus.u1_lt_umin ) Err.Alarm.bit.u1_lt_umin2 =0;
if (s[1].ein.u1_lt_uwarn) Err.Alarm.bit.u1_lt_uwarn2=1;
if (s[1].aus.u1_lt_uwarn) Err.Alarm.bit.u1_lt_uwarn2=0;
if (s[1].ein.u3_gt_umax ) Err.Alarm.bit.u3_gt_umax2 =1;
if (s[1].aus.u3_gt_umax ) Err.Alarm.bit.u3_gt_umax2 =0;
if (s[1].ein.u3_lt_umin ) Err.Alarm.bit.u3_lt_umin2 =1;
if (s[1].aus.u3_lt_umin ) Err.Alarm.bit.u3_lt_umin2 =0;
}
if (b&4) {
if (s[2].ein.u1_gt_umax ) Err.Alarm.bit.u1_gt_umax3 =1;
if (s[2].aus.u1_gt_umax ) Err.Alarm.bit.u1_gt_umax3 =0;
if (s[2].ein.u1_lt_umin ) Err.Alarm.bit.u1_lt_umin3 =1;
if (s[2].aus.u1_lt_umin ) Err.Alarm.bit.u1_lt_umin3 =0;
if (s[2].ein.u1_lt_uwarn) Err.Alarm.bit.u1_lt_uwarn3=1;
if (s[2].aus.u1_lt_uwarn) Err.Alarm.bit.u1_lt_uwarn3=0;
if (s[2].ein.u3_gt_umax ) Err.Alarm.bit.u3_gt_umax3 =1;
if (s[2].aus.u3_gt_umax ) Err.Alarm.bit.u3_gt_umax3 =0;
if (s[2].ein.u3_lt_umin ) Err.Alarm.bit.u3_lt_umin3 =1;
if (s[2].aus.u3_lt_umin ) Err.Alarm.bit.u3_lt_umin3 =0;
}
return;
#undef PSS_ein
#undef PSS_aus
#undef UNV_ein
#undef UNV_aus
#undef LED_UgtUMIN
#undef LED_UgtUMAX
} |