PLC Clock to reset a Counter

Ones_Zeros

Member
Join Date
Feb 2014
Location
at work
Posts
367
Hello
I have a AB Compact logic 1769-L32E controller.
I'm wanting to reset a counter at the end of each month.
Since the months have different number of days in them, how would be the best way to accomplish this in the PLC using the PLC clock?


thanks,
 
I believe Rockwell has some sample code for julian date. You could then use the Day to reset the Counter for each Month.
Jan = 31
Feb = 59
Mar = 90
Apr = 120
May = 151
June =181
July = 212
Aug = 243
Sep = 273
Oct = 304
Nov = 334
Dec = 365
 
Last edited:
I agree with the others, monitor the month value. If no change, do nothing. If a change is detected perform the reset. You could also monitor the day and look for the day to be equal to "1".

Here is an example. I would use either rung 1 or rung 2, but not necessarily both. The ONS on rung 2 isn't really necessary but it isn't hurting anything. The ONS on rung 1 is necessary though.

OG

Reset on new month.JPG
 
The ONS (one shot) seems to confuse me.
Can you explain why it would be necessary on rung #1 but not rung #2?

I appreciate it, thanks for helping
 
Without a oneshot, rung #1 will continuously reset the counter throughout the entire first day of the month.

On rung #2 it is redundant because the NEQ statement will only be true for one scan each time the month changes.

The advantage of monitoring the month rather than the day is if the machine happens to be powered off the entirety of the first day, it will still reset when first entering run mode after powering on because it sees the month has changed (unless it was powered off for 12 months... but that's probably not worth worrying about).
 
If you want to reset it before midnight on the 1st of the month and are NOT in the 0:00 hour of UTC time (which everyone I know grew up called it Greenwich Mean Time) then GSV the UTC time.


Compare the UTC date (which will be tomorrow for 4 or 5 hours at least depending on time zone and DST) and if that day = 1 then just before midnight local time reset the counter.
 
The ONS (one shot) seems to confuse me.
Can you explain why it would be necessary on rung #1 but not rung #2? ...

I realize others have already answered the query, and correctly, and hopefully those answers cleared up any confusion.

But because the query was made in the first place, I wonder if the fundamental issue is that @Ones_Zeros does not fully understand the significance of the scan cycle, which is a primary aspect of a digital PLC.

Background

Programming PLCs is about time: measuring or sensing when input events occur, and choosing when to respond to those events by modifying outputs.

The scan cycle of a digital PLC is an attempt to model a continuous process (e.g. physical relays) with a discrete, i.e. non-continuous, but repeating process. That process is the PLC running the entire program one discrete scan cycle at a time, but also running successive scan cycles repeatedly and so quickly that the overall PLC process of repeating discrete scans approximates, i.e. models, a continuous process.

Given that background, let me take a stab at getting @Ones_Zeros to answer their own query by asking these questions:

1) On Rung 1, for how many scan cycles in a row will the output rung of the [EQU DateTime.Day 1] instruction be true?

1.1) I.e. just the output rung of that one [EQU] instruction, not including the [ONS] instruction?

2) On Rung 2, for how many scan cycles in a row will the output rung of the [NEQ Current_Month DateTime.Month] instruction be true?

2.1) Note that, once the [NEQ] output rung is true, that activates the input rung of the [MOV DateTime.Month Current_Month] instruction.

2.1.1) That means that Rung 2, in toto, implements a one-shot pattern (algorithm).

3) Can you implement the one-shot algorithm against a bit (boolean) tag using only XIC, XIO, and OTE instructions, i.e. with no purpose-built ONS/OSR instruction?
 
Last edited:
Hello
I was wanting to expand and ask couple more questions on what I was wanting to accomplish.

I have a total run hours from a motor that I'm currently feeding into the PLC and was needing to separate the run hours by month.

Here is what I was thinking.
1. Use the GSV instruction to get the month value
2. I currently have the "Motor_Run_Hours_Total" tag that is keeping an overall total.
3. At the start of a new month. I would need to store the previous month run hours to a tag. I thought creating (12) monthly tags to store this data.
4. Then I would need to reset the run hours total for the new month to start calculating the runs hours for the new month.

How would be the best method to accomplish this?
thanks
 
This way it will record the value as soon as the PLC sees a month change, whether that's right after midnight on the 1st, or next time the PLC is powered up, unless 12 months later. If that will ever be an issue then log and compare the month and year.


It simply:
records the run hours in an array
Zero's out the run hours
Records the month the last log was made


EDIT: And I reduced the screenshot size by 50% before attaching it!

Capture.PNG
 
This way it will record the value as soon as the PLC sees a month change, whether that's right after midnight on the 1st, or next time the PLC is powered up, unless 12 months later. If that will ever be an issue then log and compare the month and year.


It simply:
records the run hours in an array
Zero's out the run hours
Records the month the last log was made


EDIT: And I reduced the screenshot size by 50% before attaching it!

I would suggest a change of storing the data into Array[month_stored] before the MOV date.month month_stored.

The example as shown puts the stored data for the previous month in the current month's position, for example November's data in Array[12] and December's in Array[1], which seems likely to confuse someone at some point.

Note that doing it this way will require an array of size 13 since the 0 position is unused.
 
The example as shown puts the stored data for the previous month in the current month's position, for example November's data in Array[12] and December's in Array[1], which seems likely to confuse someone at some point.


I don't see that being a problem for the first few hours.


I would go back a month to save it, unless it's January then jump to 12.


When I do something like this I use the method above I posted to read UTC time and just before midnight do the logging.
 
Hello I had several questions if you don't mind

Here are my screen shots.
1. Is the "Month_Stored" tag on rung#1 a DINT , INT, or array?
2. I'm sure I did this wrong..but when the systemtime[1] which is August gets moved to the tag "Month_Stored" won't this will always be equal. This is the part that i'm confused on.
3. I'm assuming i have to create a rung like #1 for each each month that i want to store the run hour data? is this correct?

Thanks again..I appreciate the help

Run Hrs Stored.JPG

Month_Array.jpg
 
Month_Stored would be a DINT, using an INT wouldn't save memory.
The NEQ would only be true one scan every month, however if you just check the NEQ like you are you will record all months to July (Month_Array[7])
For that to work add a EQU System time[1] =8 to record the set 7th month. Otherwise SUB 1 from the month and use Month_Array[Month_Less_One] just if it is 0 then add 12 for December


EDIT: Doing your way add a EQU System_Time[1] 8 to that branch and remove the MOV 0

Then add 11 more branches - one for each month
Then add a final rung with the MOV 0 and you could move the MOV Sytem_Time[1] Month_Stored to this last branch too
 
Last edited:

Similar Topics

At the moment on my application (S7-1212C), the PLC/HMI are showing the correct time, i.e. the displayed time matches the time of the clock on the...
Replies
10
Views
880
The PLC in question is a S7-1212C. The PLC will be transportable on a wheeled trolley and used wherever it's needed in the factory. I've been...
Replies
14
Views
1,278
Hi, I'm using CX Programmer and just seeing what the best way to trigger an output from the plc clock time would be. I need this to come on at 9am...
Replies
4
Views
1,699
Hi all, I'm running into an issue with a Modicon M340 PLC Clock and daylight savings time. I found an old thread that wrote out specific code...
Replies
3
Views
1,841
I have a system installed in my company which have M340 PLC and it has a program which is used toh turn lights on and off. I am attaching program...
Replies
5
Views
3,281
Back
Top Bottom