Machine expert basic: problem with comparison

You are addind %MW130 to %MW130 + timer timed value.
This should be only %MW130:=%Tx.V as otherwise you are adding pause timer from earlier pause also.





[Update: forget this part; I think I understand what Lare was saying now and he is right]



I am not sure I agree: doesn't Tx get reset, and Tx.V get reset to 0, when the rung feeding the timer goes false?



I am more concerned about the OR of the three edges on Rung0 (one rising/positive (--]P[--); two falling (--]N[--). I think we want an edge of the combined OR of those three bits, not the OR of the combined edges.


For example, say there is a drive fault on pump1, which changes %I0.2 from 1 to 0 and generates falling edge to set the --]N[-- True, resulting in a True on Rung0 after the OR; then there is a fault on pump2 (%I0.3), which generates another True on Rung0; then the operator hits the pause, which generates a third True on Rung0.


Although it may not matter because Tx.V will be reset to 0 after the first edge.
 
Last edited:
Sorry about the missing attachment.

I use the [%mw130 := %mw130 + %tm1.v] because it makes me able to get the total runtime within the batch. When the batch timer is done the %mw130 is set to zero. There is also a function for reset batch.

About the rising edge, and the two falling edge in rung 0, if either pause is set or a fault input. The timer is set to zero and pump1 and pump2 is stopped.

Tested it on the plc now, and its working just fine.

drbitboy: you are correct, the tmx.v is set to zero if the input on times goes false.

Timer working.JPG
 
Discovered that if i move the timer call to before the comparison it actually works.. Why is that?




The edge on Rung0 should be the falling edge whatever makes the timer run.


So when the timer is going to evaluate to False, Tx.V will be added to %MW130 on Rung0, and then Tx.V will be reset to 0 when the timer Rung executes.


But if the [<=] comparison is made before the timer Rung, then Tx.V has not yet been reset to 0, so it is added twice for that one scan into the sum (Tx.V + %MW130) that is used in the [<=] comparison.




So that is why it worked when you moved the timer before the comparison.





Also, I think I misunderstood what Lare said before: this may be what he was referring to.
 
Last edited:
Only 5 years with M221 and still learning sometimes :D đź“š
Sorry, I have Somachine installed only at work computer, but thinking that I would code (if not used counters or variables or own code functions blocks on M221)


http://www.plctalk.net/qanda/showthread.php?t=124509


Retentive timer:




pause start
-|P|--------|----| |---|timer_preset:=From HMI setpoint - %T0.V |
|
Fault |
-|P|--------|



start
-|\|--------|-----|timer_preset:=From HMI setpoint |
|
stop |
-| |--------|



------------------|%T0.P:=timer_preset |


start stop fault pause TON
-| |----|\|----|\|----|\|------|%T0|




start stop fault pause %T0.Q control
-| |----|\|----|\|----|\|------|\|-----------( )







start pause
-| |-----|N|----|-----------------|overall_paused:=overall + timer_preset|
| |
| |
| fault |
|--|N|----|

----------------------------------|overall := overall_paused + %T0.V |


stop
-| |------------------------------|overall := 0 |
|overall_paused := 0 |









p.s Overall timimg added
p.s 2. This works only for 1 pause. For working several pauses you need to save paused time so that preset time subtraction goes right also for 2,3.. pauses.
 
Last edited:
About the rising edge, and the two falling edge in rung 0, if either pause is set or a fault input. The timer is set to zero and pump1 and pump2 is stopped.

Tested it on the plc now, and its working just fine.




Does either pump fault cause the timer to stop? I think there should be a 1:1 correspondence between
  • whatever has a falling edge to execute the accumulation into %MW130 on Rung0,
  • AND
  • the logic that feeds the timer, with the possible exception of %M300.
 
Fault signal from pump1 or pump2 sets the batch in pause mode, the pause_on stops the timer.

I think I stumbeled upon some kind of bug, because if i had the timer on minutes with the ladder in the first post. On a 60 minute preset, i pressed pause when there was 8 minutes left and the comparison block set the bit and stopped.

In the program i saw it compared 60 <= 52 and set it true..
 
Only 5 years with M221 and still learning sometimes :D đź“š
Sorry, I have Somachine installed only at work computer, but thinking that I would code (if not used counters or variables or own code functions blocks on M221)


http://www.plctalk.net/qanda/showthread.php?t=124509


Retentive timer:





pause start
-|P|--------|----| |---|timer_preset:=%T0.V |
|
Fault |
-|P|--------|



start
-|\|--------|-----|timer_preset:=From HMI setpoint |
|
stop |
-| |--------|



------------------|%T0.P:=timer_preset |


start stop fault pause TON
-| |----|\|----|\|----|\|------|%T0|




start stop fault pause %T0.Q control
-| |----|\|----|\|----|\|------|\|-----------( )












Yes, this is nice and should work. It also demonstrates why a using a non-retentive timer plus additional logic is perhaps not the best way to make a retentive timer.


I think it would be cleaner to keep track of the RTC (Real-Time Clock) SECONDS value and increment a counter on a rising edge of NEQ(last_second,current_second) and the pump being on.


Another way would be to accumulate
microseconds := microseconds + (%SW30 * 1000) + %SW70
for each scan whenever the pump is on and not paused or faulted. that would have to be a 32-bit integer, and would only work up to just over half an hour (2 billion microseconds ~ 2000s).
 
^There is still litttle error also on this, would have noticed on real PLC and several pause commands.


I would do with counter or Dint-variable after all even it is possible to change non retentive timer to retentive with extra coding
 
OK, so overthinking this also like OP


additional rungs and variables are only needed if timer is non retentive

(M221 timers have selection of retentive, not sure when timers had this setting added)


But if retentive setting isn't selected then you need code on attacment1 or similar for saving timed value


if retentive setting is selected, all you need is only pause and fault added to timer input (attachment2)

ret_timer_test1.jpg ret_timer_test2.jpg
 
Last edited:

Similar Topics

Hey Programmers, Heres todays puzzle I was trying to solve... I have a Modbus TCP network with two Modicon M221 controllers live on my work bench...
Replies
0
Views
475
In the last two months I have had an issue after making some online changes between the software and an Schneider M221 PLC via ethernet network...
Replies
0
Views
1,099
Hello, I am using Machine expert - basic with an M221 PLC. I have two 16 bit modbus registers coming in and I want to convert to a 32bit real...
Replies
8
Views
3,918
I've searched and I can't find anywhere to trigger a compilation of the program without going into simulation mode and back out. Does any one...
Replies
0
Views
1,627
Hello, As part of our project, we are using an M241 controller. This controller interfaces with an industrial computer and a router via a switch...
Replies
2
Views
113
Back
Top Bottom