if(Alarm1 != 0 | Alarm2 !=0)
{
if (Alarm1 == 0x0003 & Alarm2 == 0x0000) //Loss of synchronism with the motor Alarm
{
alarmCounter = 0; //Reset Alarm counter
syncAlarmCounter_Aux ++;
if (syncAlarmCounter_Aux > 32000) //1 second
{
syncAlarmCounter_Aux = 0;
syncAlarmCounter ++;
if (syncAlarmCounter > 15) //Seconds of Time Out for loss of synchronism alarm
{
PORTCbits.RC0 = 0; //Activate Relay if loss of synchronism alarm detected while x period of time (Negative Logic)
PORTCbits.RC1 = 0;
}
}
}
else //For any other alarm activate Relay
{
alarmCounter_Aux ++;
syncAlarmCounter = 0; //Reset the loss of synchronism Alarm counter
if (alarmCounter_Aux > alarmTimeOut_Aux)
{
alarmCounter_Aux = 0;
alarmCounter ++;
if (alarmCounter > alarmTimeOut)
{
PORTCbits.RC0 = 0; //Activate Relay if alarm detected (Negative Logic)
PORTCbits.RC1 = 0;
}
}
}
if (TMR2_Counter > 1250) //20s without RS485 communication
{
PORTCbits.RC0 = 0; //Activate Relay if alarm detected (Negative Logic)
PORTCbits.RC1 = 0;
}
}
else
{
alarmCounter = 0;
syncAlarmCounter = 0; //Reset the loss of synchronism Alarm counter
if (TMR2_Counter > 1250 ) //20s without RS485 communication
{
PORTCbits.RC0 = 0; //Activate Relay if alarm detected (Negative Logic)
PORTCbits.RC1 = 0;
}
else
{
PORTCbits.RC0 = 1; //Desactivate Relay if no alarm detected
PORTCbits.RC1 = 1;
}
}