Hello everyone,
I need little help with timers in Step 7.
I want to measure running time of one pump station, when pump is working timer measure, then pump stops, after that pump continue working and timer continue measuring time.
Can someone give me some suggestion how to do that ?
Best regards,
Goran
[?]: How measure time when pump is working?
-
- Posts: 32
- Joined: Fri Oct 03, 2008 2:17 am
- Location: America
Re: [?]: How measure time when pump is working?
To measure the operating time of the pump, you can use one of the following code snippet:
1) To use this logic you have to activate Cycle Mark option in HWConfig ( cpu properties cycle / cycle
mark) and select a byte for this (in this example we use MB0)
Note that if the cycle mark is not enabled, after you enable it you must compile the HW config and
download the new configuration to plc.
with this logic the variable MD20 will have the time in seconds since the pump is running .
To reset the count you have to put the bit Reset_Time_Counter in "1"
2) Another way to do the time count is using #OB1_PREV_CYCLE (Cycle time of previous OB1 scan in milliseconds)
in "OB1" you have to write:
in this case the variable MD20 contains the time in milliseconds since the pump is running.
Again, to reset the count you have to put the bit Reste_Time_Counter in "1"
This last method is more accurate and you dont need to modify the HW config if the cycle mark is not enabled.
i hope this can be useful for you
best regards
1) To use this logic you have to activate Cycle Mark option in HWConfig ( cpu properties cycle / cycle
mark) and select a byte for this (in this example we use MB0)
Note that if the cycle mark is not enabled, after you enable it you must compile the HW config and
download the new configuration to plc.
Code: Select all
U M0.5 // cpu clock 1seg (defined in HW config with MB0)
FP M10.5 // support for pulse
= M1.5 // pulse cpu clock 1seg
// time count
U Pump_ON
U M1.5
SPBN J001
L MD20
+ 1
T MD20 // time pump ON
J001: NOP 0
// reset time
U Reset_Time_Counter
SPBN J002
L 0
T MD20
J002: NOP 0
To reset the count you have to put the bit Reset_Time_Counter in "1"
2) Another way to do the time count is using #OB1_PREV_CYCLE (Cycle time of previous OB1 scan in milliseconds)
in "OB1" you have to write:
Code: Select all
U Pump_ON
SPBN J001
L MD20
L #OB1_PREV_CYCLE
+D
T MD20 // time pump ON in mili seconds
J001: NOP 0
// reset time
U Reset_Time_Counter
SPBN J002
L 0
T MD20
J002: NOP 0
Again, to reset the count you have to put the bit Reste_Time_Counter in "1"
This last method is more accurate and you dont need to modify the HW config if the cycle mark is not enabled.
i hope this can be useful for you
best regards
-
- Posts: 2
- Joined: Fri Jun 11, 2010 7:20 pm
Re: [?]: How measure time when pump is working?
Hello,
please visit this:
http://support.automation.siemens.com/W ... earch.aspx
there is an example
BR, ha
please visit this:
http://support.automation.siemens.com/W ... earch.aspx
there is an example
BR, ha
-
- Posts: 66
- Joined: Tue May 12, 2009 9:50 am
Re: [?]: How measure time when pump is working?
But do you need that accuracy?Guille wrote: This last method is more accurate and you dont need to modify the HW config if the cycle mark is not enabled.
A double unsigned integer, counts up to 2^32 -1 = 4294967296 -1 = 4294967295
In (1) that's 4294967295 seconds = 136 years.
In (2) that's 4294967295 milliseconds = 49 days.
You win more accuracy, but you don't have duration.
The only thing you must truly consider is if you can modify HWConfig to enable memory clock, but then again it is relatively easy and _SAFE_ to do in a running project, and it only requires a byte.
Usually I'm choosing (1), but depends on your project.
-
- Posts: 1
- Joined: Thu Jan 17, 2013 3:12 pm
Re: [?]: How measure time when pump is working?
put in cyclic interrupt, if 0,1-1s accuracy is enough
-
- Posts: 32
- Joined: Fri Oct 03, 2008 2:17 am
- Location: America
Re: [?]: How measure time when pump is working?
Of course in this application probably that accuracy is not necesary, I only put the code as an example of the way you can measure time using a counter and a time base.But do you need that accuracy?
If you need more than 49 days you can use a byte and accumulate the days in that case you wil have 255*49 days of resolution. There are a lot of ways to do this.
I use the second aproachto measure time and calculate statistiscs of diferent events and i need the accuracy, so you can use the code for another application too. If you can't or don't want to modify de HW config this is one way to measure time. Certanly there are other ways to do this, for instance using a flip-flop to generate a time base by software and use this base to measure, etc.
-
- Posts: 86
- Joined: Mon Feb 25, 2008 8:40 am
- Location: Europe
Re: [?]: How measure time when pump is working?
Sorry if this is off topic but it is great to see code samples.
Thanks and want to see more projects here with code even trivial ones.
It is hard to find samples for many projects using Siemens PLC's.
Thanks again.
Regards.
Thanks and want to see more projects here with code even trivial ones.
It is hard to find samples for many projects using Siemens PLC's.
Thanks again.
Regards.
-
- Posts: 66
- Joined: Tue May 12, 2009 9:50 am
Re: [?]: How measure time when pump is working?
Ya, I was replying to the OP to consider one or the other solution depending on what he needs.Guille wrote:Of course in this application probably that accuracy is not necesary, I only put the code as an example of the way you can measure time using a counter and a time base.But do you need that accuracy?
If you need more than 49 days you can use a byte and accumulate the days in that case you wil have 255*49 days of resolution. There are a lot of ways to do this.
I use the second aproachto measure time and calculate statistiscs of diferent events and i need the accuracy, so you can use the code for another application too. If you can't or don't want to modify de HW config this is one way to measure time. Certanly there are other ways to do this, for instance using a flip-flop to generate a time base by software and use this base to measure, etc.
Huge respect for actual code samples!
-
- Posts: 1
- Joined: Sat May 11, 2013 8:52 am
Re: [?]: How measure time when pump is working?
i have simple ladder program according your req..
i just create pulse 1 sec use timer on delay on network 1.
and create 1 pump interlock network 2.
if pump interlock have a on condition, pulse 1 second will be tirigger, n give one scan add integer for M200, in the case M200 is memory for second data..
if M200 have a or grater than 59, the compare will give a one trigger for one scan to minute data, and the last network will be reset data second.
i just create pulse 1 sec use timer on delay on network 1.
and create 1 pump interlock network 2.
if pump interlock have a on condition, pulse 1 second will be tirigger, n give one scan add integer for M200, in the case M200 is memory for second data..
if M200 have a or grater than 59, the compare will give a one trigger for one scan to minute data, and the last network will be reset data second.