[?]: How measure time when pump is working?

SIMATIC S7-200/300/400, Step7, PCS7, CFC, SFC, PDM, PLCSIM,
SCL, Graph, SPS-VISU S5/S7, IBHsoftec, LOGO ...
Post Reply
gogycro
Posts: 22
Joined: Sat Nov 19, 2011 3:25 pm

[?]: How measure time when pump is working?

Post by gogycro » Sun Feb 24, 2013 8:08 pm

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

Guille
Posts: 32
Joined: Fri Oct 03, 2008 2:17 am
Location: America

Re: [?]: How measure time when pump is working?

Post by Guille » Tue Feb 26, 2013 7:36 am

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.

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
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:

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
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

pravda_ha
Posts: 2
Joined: Fri Jun 11, 2010 7:20 pm

Re: [?]: How measure time when pump is working?

Post by pravda_ha » Tue Feb 26, 2013 12:04 pm

Hello,
please visit this:
http://support.automation.siemens.com/W ... earch.aspx

there is an example

BR, ha

sanruku
Posts: 66
Joined: Tue May 12, 2009 9:50 am

Re: [?]: How measure time when pump is working?

Post by sanruku » Tue Feb 26, 2013 12:37 pm

Guille wrote: This last method is more accurate and you dont need to modify the HW config if the cycle mark is not enabled.
But do you need that accuracy?
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.

asesuas
Posts: 1
Joined: Thu Jan 17, 2013 3:12 pm

Re: [?]: How measure time when pump is working?

Post by asesuas » Tue Feb 26, 2013 11:26 pm

put in cyclic interrupt, if 0,1-1s accuracy is enough

Guille
Posts: 32
Joined: Fri Oct 03, 2008 2:17 am
Location: America

Re: [?]: How measure time when pump is working?

Post by Guille » Wed Feb 27, 2013 6:16 pm

But do you need that accuracy?
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.
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.

h4rdw4re
Posts: 85
Joined: Mon Feb 25, 2008 8:40 am
Location: Europe

Re: [?]: How measure time when pump is working?

Post by h4rdw4re » Thu Feb 28, 2013 7:17 pm

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.

sanruku
Posts: 66
Joined: Tue May 12, 2009 9:50 am

Re: [?]: How measure time when pump is working?

Post by sanruku » Mon Mar 04, 2013 2:41 pm

Guille wrote:
But do you need that accuracy?
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.
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.
Ya, I was replying to the OP to consider one or the other solution depending on what he needs.
Huge respect for actual code samples!
(tyou) (gpost)

spinBath
Posts: 1
Joined: Sat May 11, 2013 8:52 am

Re: [?]: How measure time when pump is working?

Post by spinBath » Sat May 11, 2013 9:25 am

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. (close)

Image

Post Reply