Sign in to follow this  
Followers 0
mart

clock timer

4 posts in this topic

Hiya chaps, I'm more of a fire fighting kind of PLC user and new to the programming sideso all help is very much appreciated. I need to create a small piece of code to monitor real times, for example if a door is opened for a given time I need to log what time is was opened until is was closed. This could happen a number of times over a 12hr period and would want to log each occurance and its total time for the 12hrs. At the end of each 12hrs the counter would be reset. Can this information be stored into a data block etc ? I need to write it in Step 7 and at a bit of a loose end because of the clocks, when I put a timer in for when the door opens do I need to link it up a clock in the CPU's hardware diagnostics. I've not got a PLC set up yet as its all development but plan to use a S300 for it. If I'm completely barking up the wrong tree let me know but all help would be welcome. Cheers Mart

Share this post


Link to post
Share on other sites
There are a number of clock related system functions, SFC0 to SFC4. SFC 1 allows you to read the system clock. this allows you to read the PLC clock in date/time format, you would need to store the result in 8 bytes. Byte - Description. 0 - Year 1 - Month 2 - Day 3 - Hour 4 - Minute 5 - Second 6 - mSec (part) 7 (4 MSB) - mSec (part) 7 (4 LSB) - Day of Week (i.e. 1 = Sunday) Not sure if you would want al the date/time or just the time of day, if you need part you would need to extract it. You would then need to transfer this into a datablock, probably best to create an array and store into the next available space, this would require indirect addressing though, can't see a simple way out of that. For the total time, then I would just create a counter for total No. seconds and then reset at the end as you say. I presume that you would not be historically storing then as you want to reset every day.

Share this post


Link to post
Share on other sites
An example of saving the opening closing times using indirect addressing, I presume you can do the timer yourself. To compile FC7 you would need to have DB99 set up in symbols as "DoorTimes" clock.zip

Share this post


Link to post
Share on other sites
noticed I put a common error in the above file, where it says SLW 3, it should be SLD 3!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0