Timer percent complete Calculate percent complete and mov to D0010
#1
Posted 15 April 2012  06:11 AM
I have my program almost done thanks to peeps here all i need to do now is figure out how to Calculate percent complete and mov to D0010?
Set value for the timer is in D0001 and Timer value is T0000
I made a function block ST but have no idea how to hook up the timer to execute it and the output result moved to D0010 I have attached a sceen shot of the function so far.
Thanks in advance
I have VB.net, C#, Perl and PHP experience so if you need any help with thoselet me know!
#2
Posted 15 April 2012  08:37 AM
screaminlean, on 15 April 2012  06:11 AM, said:
I have my program almost done thanks to peeps here all i need to do now is figure out how to Calculate percent complete and mov to D0010?
Set value for the timer is in D0001 and Timer value is T0000
I made a function block ST but have no idea how to hook up the timer to execute it and the output result moved to D0010 I have attached a sceen shot of the function so far.
Thanks in advance
Ok I tried to use
TIM 0000 N01_psv AND P_0_1s /B(434) T0 N01_psv D10
so every 0.1 seconds that the timer is active the calculation is done and pushed to D0010 but this will not be any good as a timer counts down! anyone done this before?
This post has been edited by screaminlean: 15 April 2012  10:39 AM
I have VB.net, C#, Perl and PHP experience so if you need any help with thoselet me know!
#3
Posted 15 April 2012  10:49 AM
X = TimeDone
Y = % Complete
so
X = Timer Set Value (SV) Minus Timer Current Value (T0)
Y = X Divided by Timer Set Value(SV)
But how to implement this on the ladder?
I have VB.net, C#, Perl and PHP experience so if you need any help with thoselet me know!
#4
Posted 15 April 2012  11:21 AM
screaminlean, on 15 April 2012  10:49 AM, said:
X = TimeDone
Y = % Complete
so
X = Timer Set Value (SV) Minus Timer Current Value (T0)
Y = X Divided by Timer Set Value(SV)
But how to implement this on the ladder?
Hello
If you use a timer within your ST, then you can do the maths in there too. Much easier than fannying aobut with maths in ladder imho.
TIMHX(StartCondition,MyTimer,TimerValue)
#5
Posted 15 April 2012  11:59 AM
ParaffinPower, on 15 April 2012  11:21 AM, said:
screaminlean, on 15 April 2012  10:49 AM, said:
X = TimeDone
Y = % Complete
so
X = Timer Set Value (SV) Minus Timer Current Value (T0)
Y = X Divided by Timer Set Value(SV)
But how to implement this on the ladder?
Hello
If you use a timer within your ST, then you can do the maths in there too. Much easier than fannying aobut with maths in ladder imho.
TIMHX(StartCondition,MyTimer,TimerValue)
Dont know how to use ST functions and I have 4 timers i need to do the same with see attached this is my program so far rung 06 is the first instance
Attached File(s)

L10_PLC1.cxp (3.22K)
Number of downloads: 145
This post has been edited by screaminlean: 15 April 2012  12:03 PM
I have VB.net, C#, Perl and PHP experience so if you need any help with thoselet me know!
#6
Posted 15 April 2012  02:28 PM
Quote
LD P_On
OUT TR0
AND 23.00
TIMX(550) 0000 D0
FLT(452) D0 D10
// Convert to Float
(410) D0 T0 D12
// Subtract
FLT(452) D12 D12
// Convert result to Float
LD TR0
/F(457) D12 D10 D20
// Divide by Preset
*F(456) D20 +100.0 D20
// Multiply by 100 to get value as %
#7
Posted 16 April 2012  05:40 PM
lostcontrol, on 15 April 2012  02:28 PM, said:
Quote
LD P_On
OUT TR0
AND 23.00
TIMX(550) 0000 D0
FLT(452) D0 D10
// Convert to Float
(410) D0 T0 D12
// Subtract
FLT(452) D12 D12
// Convert result to Float
LD TR0
/F(457) D12 D10 D20
// Divide by Preset
*F(456) D20 +100.0 D20
// Multiply by 100 to get value as %
Thanks alot thats great!!
I have VB.net, C#, Perl and PHP experience so if you need any help with thoselet me know!
#8
Posted 02 November 2012  11:29 AM
screaminlean, on 16 April 2012  05:40 PM, said:
lostcontrol, on 15 April 2012  02:28 PM, said:
Quote
LD P_On
OUT TR0
AND 23.00
TIMX(550) 0000 D0
FLT(452) D0 D10
// Convert to Float
(410) D0 T0 D12
// Subtract
FLT(452) D12 D12
// Convert result to Float
LD TR0
/F(457) D12 D10 D20
// Divide by Preset
*F(456) D20 +100.0 D20
// Multiply by 100 to get value as %
Thanks alot thats great!!
After bieng able to sign in to the site i Can post again!
I still cant get this to work right? I have NQ5 with bar graph set to UINT and my timers are TIMHX(551) CP1E so cant use function blocks or ST.
any easier ways?
Regards
I have VB.net, C#, Perl and PHP experience so if you need any help with thoselet me know!
#9
Posted 02 November 2012  01:40 PM
LD P_On
OUT TR0
AND 23.00
TIMHX(551) 000 D0
FLT(452) D0 D10
// Convert to Float
(410) D0 T0 D12
// Subtract
FLT(452) D12 D12
// Convert result to Float
LD TR0
/F(457) D12 D10 D20
// Divide by Preset
*F(456) D20 +100.0 D20
// Multiply by 100 to get value as %
I am guessing that your HMI is not set to read D20 properly. You need to make sure that you set your graph to read D20 as a REAL or FLOATING POINT number. Make sure to monitor it in CXProgrammer as a REAL number also.
In the three different cases shown the percent done value (Real number in D20 is correct).
1st case: (D0 (setpoint)  T0 (current value)) / D0 (setpoint) > (2000  1854) /2000 = 7.3 (%) which is stored in D20.
2nd Case: (2000  1042) / 2000 = 47.9 %
3rd Case: (2000  353) / 2000 = 82.35 %
It works, you must have a number format issue somewhere in your HMI or in your ladder. If you are doing a MOV instruction after the math, make sure to do a MOVL as a REAL number is a double word (meaning that it is contained in D20 and D21 in this example).
Charlotte, NC
#10
Posted 02 November 2012  02:21 PM
Michael Walsh, on 02 November 2012  01:40 PM, said:
Hi I got the same result now in the plc thanks, I have only 4 options for the number format in the NQ5 HMI
 Unsigned Int
 Signed Int
 BCD
 Hex
And current seeting in the HMI is Unsigned, can i get a conversion from REAL to Unsigned? Multiply it by 10 using *F(456) Floating point multiply?
Regards
Pete
This post has been edited by screaminlean: 02 November 2012  02:25 PM
I have VB.net, C#, Perl and PHP experience so if you need any help with thoselet me know!
#11
Posted 02 November 2012  03:04 PM
LD P_On
OUT TR0
AND 23.00
TIMHX(551) 000 D0
FLT(452) D0 D10
// Convert to Float
(410) D0 T0 D12
// Subtract
FLT(452) D12 D12
// Convert result to Float
LD TR0
/F(457) D12 D10 D20
// Divide by Preset
*F(456) D20 +100.0 D20
// Multiply by 100 to get value as %
FIX(450) D20 D25
If you want integer values that represent tenths of a percent (so that 25.2% is 252), then use this:
LD P_On
OUT TR0
AND 23.00
TIMHX(551) 000 D0
FLT(452) D0 D10
// Convert to Float
(410) D0 T0 D12
// Subtract
FLT(452) D12 D12
// Convert result to Float
LD TR0
/F(457) D12 D10 D20
// Divide by Preset
*F(456) D20 +1000.0 D20
// Multiply by 1000 to get value as tenths of a %
FIX(450) D20 D25
Then display D25 on your screen as an Unsigned Integer format. Of course if you use the tenths of a percent example (2nd set of code), you will need to scale the display by 10 to get the decimal in the proper place.
Charlotte, NC
#12
Posted 03 November 2012  03:52 AM
I have VB.net, C#, Perl and PHP experience so if you need any help with thoselet me know!