Siemens S7/TIA v18: Function to Calculate 80% reached...

Mas01

Member
Join Date
Oct 2020
Location
Leicester, England
Posts
1,109
Can someone help me with this?

I'm no good at SCL - virtually everything I've done so far has been ladder logic.

The return value from the function should be TRUE when RowCounter is 80% of MaxNoOfRows.

It compiles, but the output only goes TRUE when RowCounter matches MaxNoOfRows.

Thanks in advance.

80_Percent_Reached.png
 
Last edited:
Because the numerator and denominator are INTs, the ratio (#RowCounter/#MaxNoOfRows) will be 0 until #RowCounter equals #MaxNoOfRows.


try this instead as the only line in the FC:



Code:
#"80_Percent_Reached" := (100*#RowCounter) > (80*#MaxNoOfRows);


It's not perfect as there may be roundoff errors, but come back if that is an issue.
 
Should be:
IF RowCounter / (MaxNoOfRows / 100) > 80 THEN
80_Percent_Reached := True;
ENDIF
 
Last edited:
OP says the output is true if rowcount is 80% of maxrows, so this needs an equality test. Do you want (equals), (greater than) or (greater than or equals) ? :)
 
If you want to know if it is 80% or greater then you need to use >= otherwise when it reaches 80% it will not turn on until it is above, the amount of percent above will depend on the Max rows.
 
Pretty sure the good doctor has the right of it (as usual). Division of an Int by an Int results in an Int -- only the integer portion of #RowCounter/#MaxNoOfRows is kept, effectively truncating it at the decimal point.

His suggestion of doing the multiplication first should work assuming significant precision is not required. Alternately you need to use real(s) instead.
 
Last edited:
Not sure but I imagine that Mas is going to leave a message on the screen when it rises to 80% or more to warn the operator the log is getting full so the simple change in the if statement is all that is needed.
 
If you're not fluent with SCL (Albeit this request is very simple). You could do it in ladder with the CAL function and a comparator >=
 
If you're not fluent with SCL (Albeit this request is very simple). You could do it in ladder with the CAL function and a comparator >=

Ah, I realise now that when I created the FC block, I should've chosen 'LAD' instead of 'SCL' which was the default selection. Cheers for this info.
 
Not sure but I imagine that Mas is going to leave a message on the screen when it rises to 80% or more to warn the operator the log is getting full so the simple change in the if statement is all that is needed.

Yes, exactly this.
The value 80% is sort of arbitrary and yes, the Boolean return from the FC is to display a warning message.

I'm home now, but I'll be sure to try one of the above suggestions tomorrow, cheers everyone.
 
Convert the integers to reals for the comparison as we don't know the number of rows involved. Multiplying integers by 100 also has it's drawbacks.
 
That ST I showed is certainly the way to go as it is only an approximation it is close enough, as an added precaution you could have another bit using the same calulation or just do the one calc & store it into a tag then just fo another comparison & show message file is 100% full or what ever,
Another way instead of a message just display the % of the file, Not sure about the HMI but many value displays can change colour depending on value so for example if the value was 0-70% make it green, if it was 71-80% change it to Amber, 81-100% change it to Red.

percent.png
 
Thanks for all the help (yet again).

For the moment, I've implemented @drbitboy's one-liner (works fine), with @parky's colour-coding suggestion firmly in the back pocket, in case the user wants that functionality.
 

Similar Topics

Context: PLC= S7-1212C, HMI=KTP1200 Basic. Hi again, When the "REPORT" button is pressed (on a different screen), it takes the operator to the...
Replies
7
Views
666
Context: PLC= S7-1212C, HMI=KTP1200 Basic. Hi, The operator has reported that, from time-to-time, when he presses the "Generate Report" button...
Replies
5
Views
465
General Question: The PLC and HMI that I've been working on (a laser measurement system) is soon to be transported to the site where it will be...
Replies
2
Views
701
Hi, I'm not sure how to do this... Basically, I want to restrict the user input values for this tag to be in the range 20.001 to 25.0. I...
Replies
17
Views
1,634
Hi, Am I being daft (again)? I want to increment a tag (Integer) by 1 each time a button on the HMI is pressed. Before the button press, the...
Replies
22
Views
2,362
Back
Top Bottom