want to run 19 motor based on run hour and trip basis

206 Views Asked by At
FOR #index := 0 TO 9 DO
    // Increase working time count if the pump is active
    IF #PumpActiveSignal[#index] = true THEN
        IF #M_Clockbit1s = true THEN // memory clock that switches on every second
            IF #LoopOnce[#index] = false THEN // execute this on a positive edge of the memoryclockbit
                #WorkingTimes[#index]."Time" := #WorkingTimes[#index]."Time" + 1; // increase the working time
                #LoopOnce[#index] := true;
            END_IF;
        ELSE
            #LoopOnce[#index] := false;
        END_IF;
    END_IF;
END_FOR;

// move working times to list that needs to be ordered
FOR #k := 0 TO 9 DO
    #OrdenedList[#k] := #WorkingTimes[#k]."Time";
END_FOR;
// Order working times, lowest to highest
FOR #i := 0 TO 9 DO
    FOR #j := #i + 1 TO 9 DO
        IF #OrdenedList[#i] > #OrdenedList[#j] THEN
            #temp1 := #OrdenedList[#i];
            #OrdenedList[#i] := #OrdenedList[#j];
            #OrdenedList[#j] := #temp1;
        END_IF;
    END_FOR;
END_FOR;

IF #CHNGOVER = 1 THEN
    // assign priority number according to working times
    FOR #l := 0 TO 9 DO
        #WorkingTimes[#l].PriorityNo := -1;
    END_FOR;
    FOR #m := 0 TO 9 DO
        FOR #l := 0 TO 9 DO
            IF #OrdenedList[#m] = #WorkingTimes[#l]."Time" AND #WorkingTimes[#l].PriorityNo = -1 THEN
                #WorkingTimes[#l].PriorityNo := #m;
                EXIT;
            END_IF;
        END_FOR;
    END_FOR;
END_IF;

///with this logic I tried to make the logic in tia portal for a project. Following are the requirement in the logic: ** Change over based on the less running hours. ** after a time cycle of 2 hrs. there will be a change over which will make the less run hour motor to start first. ** and also i want to add the trip status in the logic , so that due to above logic trip motor should not come into running logic.

1

There are 1 best solutions below

6
Yadi On

From the attached code I cannot really understand what you're trying to do with the #WorkingTimes[#l].PriorityNo and I don't know how it's being evaluated in the rest of the logic.

But... here some general points:

  • you should use a more structured approach. I would make for example an array of structures (with members "Active", "Tripped", "WorkingTimes"...) for the pumps.
  • it's not necessary to evaluate everything every PLC cycle. This costs time! For a pump application a 1 sec. period is just fine in most of the cases.
  • In my opinion - it's better to structure the task in such a manner, that we could reuse some of the data in the future.

Here my version of your code :) :

IF #M_Clockbit1s AND NOT #M_EdgeDetect THEN // execute this on a positive edge of     the memoryclockbit
// Increase working time count if the pump is active
FOR #index := 0 TO 9 DO
    IF #Pumps[#index].Active THEN 
        #Pumps[#index].WorkingTimes +=1; // increase the working time 
    END_IF;
END_FOR;
// next - it would be good to know how many alailable pumps we have (not tripped) and write them to the start order array
//
#AvailPump := 0;
//
FOR #k := 0 TO 9 DO
IF NOT #Pumps[#k].Tripped THEN
    #PumpOrder[#AvailPump] := #k;
    #AvailPump +=1;
END_IF;
END_FOR;
// I like to have the things so. -1 means no pump available for this array element. Not used right now, but might be needed someday :)
//
IF #AvailPump < 9 THEN
FOR #m := #AvailPump + 1 TO 9 DO
    #PumpOrder[#m] := -1;
END_FOR;
END_IF;
// now we can sort our array to determine which pump has to be started next time.
//
IF #AvailPump > 0 THEN
FOR #i := 0 TO #AvailPump DO
    FOR #j := #i + 1 TO #AvailPump DO
        IF  #Pumps[#PumpOrder[#i]].WorkingTimes >  #Pumps[#PumpOrder[#j]].WorkingTimes THEN
            #temp1 := #PumpOrder[#i];
            #PumpOrder[#i] := #PumpOrder[#j];
            #PumpOrder[#j] := #temp1;
        END_IF;
    END_FOR;
END_FOR;
END_IF;
// now in PumpOrder[0] you have the pump number with the least running time, in PumpOrder[1] the pump number with the second least and so on...
//
// here the closing end_if - so we evaluate the data every second and not every cycle
END_IF;
#M_EdgeDetect := #M_Clockbit1s;