Math Error...I think...Help

jonfarrugia

Member
Join Date
Mar 2008
Location
London
Posts
130
I’m trying to write a program that calculates OEE. However, When I run the code I get stack errors. I’m pretty sure it’s because some calculation could be dividing by zero. How do you deal with math functions that could be dividing by zero?



I've attached the exported code
VAR
Availability: REAL; (*Total Time the Line/Cell is available to run production in minutes*)
Downtime: REAL; (*Total Time the Line/Cell is down not making parts in minutes*)
Total_Parts: DINT; (*Total parts processed. Including passed and failed parts*)
Good_Parts: DINT; (*Total parts passed*)
Ideal_Run_Rate_per_min: REAL; (*Ideal Parts per minute rate. This is an expected value i.e. 5 parts required per minute.*)

(*output values are all in percentage*)
Oee_Availability: REAL;
Oee_Performance: REAL;
Oee_Quality: REAL;
Oee_Overall: REAL;
END_VAR





Oee_Availability:=((Availability-Downtime)/Availability)*100;

Oee_Performance:=((Total_Parts/(Availability-Downtime))/Ideal_Run_Rate_per_min)*100;

IF Oee_Performance>100 THEN
Oee_Performance:=100;
END_IF

Oee_Quality:=(Good_Parts/Total_Parts)*100;

Oee_Overall:=(Oee_Availability*Oee_Performance*Oee_Quality)/10000;
 
Check the value before the divide would be one method. :confused:


OK, I tried this to prevent dividing by zero


IF (Availability-Downtime)>0 AND Availability>0 AND Ideal_Run_Rate_per_min>0 AND Total_Parts>0 THEN

Oee_Availability:=((Availability-Downtime)/Availability)*100;

Oee_Performance:=((Total_Parts/(Availability-Downtime))/Ideal_Run_Rate_per_min)*100;

IF Oee_Performance>100 THEN
Oee_Performance:=100;
END_IF

Oee_Quality:=(Good_Parts/Total_Parts)*100;

ELSE
Oee_Availability:=0;
Oee_Performance:=0;
Oee_Quality:=0;
END_IF

Oee_Overall:=(Oee_Availability*Oee_Performance*Oee_Quality)/10000;
 
There is probably math you can simplify as well...
Oee_Availability:=((Availability-Downtime)/Availability)*100;

This could be changed to:
100-(Downtime/Availabilty*100) will render the same result.

You could possibly do the others, I have to run... 🍻
 

Similar Topics

Hi I need help solving this Fault Code 20h (Math Overflow Trap S5:0). I download the code into the ML 1400 PLC. When choosing RUN it gives me a...
Replies
22
Views
17,203
I recently had a SLC 5/04 processor fault out due to a math error. The overflow trap and zero bits were both set. I was finally able to locate it...
Replies
5
Views
5,596
I have an expression in a structured text routine of a Logix controller that looks more or less like the following: ResultInteger := Integer1 *...
Replies
13
Views
383
This application has a motor with encoder feedback that drives a linear actuator that moves in/out, and is at roughly 45 degs from horiz. As the...
Replies
19
Views
1,361
Hi all. First time programming a machine of this type. A center driven unwind feeding to a center driven rewind. No dancers or load cells, just...
Replies
37
Views
4,884
Back
Top Bottom