Forum

Parts per minute go...
 
Notifications
Clear all

[Solved] Parts per minute goes to a huge number at power-up, divide by zero on an S7-1500

9 Posts
4 Users
0 Reactions
45 Views
(@bram99)
Trusted Member
Joined: 1 year ago
Posts: 33
Topic starter   [#224]

Bench rig at school, S7-1500 with PLCSIM, and I'm putting a little production screen together for the assessment. Parts per minute is a counter value divided by an elapsed time, and for the first few seconds after a warm restart the elapsed value is still 0 and the faceplate shows ### instead of a number.

Sorry if this is basic. I tried setting elapsed to 1 in OB100 so it can't be zero, and that hides it, but then the whole first minute reads wrong and it felt like I was cheating rather than fixing.

What does the DIV actually do when the divisor is 0? Does the 1500 go to STOP over it, or does it carry on with something it invented?


Advertisement

   
Quote
(@priya87)
Trusted Member
Joined: 1 year ago
Posts: 45
 

It won't stop on you. If I remember right the integer DIV sets ENO false and doesn't write OUT at all, so you keep whatever was in there before, which is usually zero and looks harmless until it isn't.

On a Logix the same rung gives you infinity and a minor fault bit that nobody ever looks at. Which data types are your two tags?


Advertisement

   
ReplyQuote
(@bram99)
Trusted Member
Joined: 1 year ago
Posts: 33
Topic starter  

Counter is a DInt, elapsed is a Real because it comes out of a CONV on a cyclic interrupt. So the DIV is Real by Real, I think, the block picked Real on its own when I dropped the tags in, which I wasn't expecting, maybe that's just what it does.

The faceplate is a Comfort panel, 3 decimal places, and ### is what it does when the value won't fit the field.



   
ReplyQuote
 kaim
(@kaim)
Active Member
Joined: 2 years ago
Posts: 17
 

Real by Real changes the answer. That's not a division error any more, that's IEEE 754, and 5.0 divided by 0.0 is positive infinity, a legal Real value. So OUT gets written, the panel gets handed infinity, and it gives you ### because no field is wide enough.

Same on a CODESYS target, same on a Logix. The controller isn't confused and nothing is broken, the maths is doing exactly what the standard says. Where it bites you is later, when infinity goes into an average or a totaliser and poisons that too.



   
ReplyQuote
(@rsdave)
Trusted Member
Joined: 2 years ago
Posts: 65
 

Guard the divisor, not the output. One compare in front of it, elapsed greater than zero, and only then do the divide. Everything else is a plaster over the top.

Init-to-1 is the classic wrong fix and you already spotted why. You'd be lying about the time base for a whole minute to avoid three seconds of nothing.



   
ReplyQuote
(@bram99)
Trusted Member
Joined: 1 year ago
Posts: 33
Topic starter  

Put the compare in and the ### is gone.

Bit odd now though. For the first few seconds the rate shows 0.0, which reads as if the line is stopped rather than as if we don't know yet. Is 0 the right thing to show, or should it be showing nothing?



   
ReplyQuote
(@rsdave)
Trusted Member
Joined: 2 years ago
Posts: 65
 

Zero is a measurement and you haven't got one, so don't print one. Hold the last good rate in its own tag and write that when the divisor is no good. At power-up there is no last good rate either, so seed a validity bit false in OB100 and have the faceplate show dashes while it's false.

Same trick works on a Logix with a first scan bit. It's the difference between a screen that's honest and a screen that's wrong for three seconds every morning.



   
ReplyQuote
(@bram99)
Trusted Member
Joined: 1 year ago
Posts: 33
Topic starter  

Working now. The cause was nothing to do with the controller, it was a Real divide by 0.0 handing the panel positive infinity, which is a real value so the DIV was happy and the field wasn't wide enough to print it.

Fix was a compare on elapsed ahead of the divide, a Rate_Valid bool cleared in OB100, and the faceplate showing dashes while that bool is false and the held value once it's true. Three seconds of dashes and then a number.

Still not sure what my teacher will say about infinity being a legal number, I got that backwards in my notes. Thanks priya87, kaim and rsdave.



   
ReplyQuote
(@priya87)
Trusted Member
Joined: 1 year ago
Posts: 45
 

Everyone gets that one backwards once.



   
ReplyQuote
Share: