##What is Control Fault Handler?

A fault condition can stop a PLC. If the PLC is controlling a dangerous process this could lead to significant damage to personnel and equipment. There are two types of faults that occur; terminal (major) and warnings (minor). A minor fault will normally set an error bit, but not stop the PLC. A major failure will normally stop the PLC, but an interrupt can be used to run a program that can reset the fault bit in memory and continue operation (or shut down safely).

The PLC can be set up to run a program when a fault occurs, such as a divide by zero. These routines are program files under ’Control Fault Handler’. These routines will be called when a fault occurs. Values are set in status memory to indicate the source of the faults.

##Fault handler program example:

In the example shown above, there will be two programs main program and recovery program. The default program ’MainProgram’ will generate a fault, and the interrupt program called ’Recover’ will detect the fault and fix it.

When A is true a compute function will interpret the expression, using indirect addressing. If B becomes true then the value in n[0] will become negative. If A becomes true after this then the expression will become n[10] +10. The negative value for the address will cause a fault, and program file ’Recover’ will be run.

In the fault program, the fault values are read with a GSV function and the fault code is checked. In this case the error will result in a status error. When this is the case the n[0] is set back to zero, and the fault code in fault_data[2] is cleared. This value is then written back to the status memory using an SSV function. If the fault was not cleared the PLC would enter a fault state and stop (the fault light on the front of the PLC will turn on).

Thus the Fault handler program works as interrupt function. When there is a fault occurs the program jumps to the fault handler program and return back to main program after correcting the error in the program.