SYSMAC counter daily reset

Got a completely new to me NJ101-9000 and it runs with SYSMAC I've never worked before. I need to reset a production counter every day at a given time. I read several threads on DT and DAT format and didn't get a lot of understanding. Also, at first, I didn't want just to compare curr_time (there is a system var) with the reset_time and wanted to extract HH from the data. Then, compare it with, say "23" hours. But got completely lost and can't figure out the structure of such variables.
So as another option I thought I'd just count minutes or hours, compare to 1440 or 24 and then reset at the end of the day (23:59). But then I also don't want to run the cycle every often and a pulse timer, likely, will be needed.
Can you share a better and easier way to implement this in SYSMAC?
 
Many yearssince used sysmac but what I have done in many other systems is use the system clock like HH/MM/SS
Then just do a oneshot of = HH 23 AND mm =59 AND ss = 59 PULSE My_Bit (oneshot to reset counters)
 
Many yearssince used sysmac but what I have done in many other systems is use the system clock like HH/MM/SS
Then just do a oneshot of = HH 23 AND mm =59 AND ss = 59 PULSE My_Bit (oneshot to reset counters)
There is a system variable _Curr_time but DT format in SYSMAC doesn't have children like Curr_Time.HH it's a kind of string. So there is no simple way to extract the HH or MM part other than truncate. At least to my understanding.
 
Had a quick look at this but it's in thai I think but seems to show conversion into uint
 
I would trigger a one-shot when the day changes e.g. in pseudocode:
Code:
if (value of saved_date) is not equal to (value of current_date) then
  [reset counter]
end_if

[copy value of current_date to saved_date]
that way, if midnight occurs while the PLC is powered off or otherwise not in RUN mode (and the clock was running), then the logic will reset the daily counter.

The current_date and saved_date in that logic could be as simple as an integer with the value that is the day of month, or it could be a compound structure with integer values for year, month, and day of month so it would also trigger if the PLC is powered off from e.g. one January 1st until another January 1st.

How to get current_date from whatever internal clock is in SYSMAC is another topic, but if it can be converted to seconds since some "zero" epoch, then dividing those seconds by 86400 (= 60s/min * 60min/h * 24h/d i.e. seconds per day) in integer arithmetic will yield the number of midnights crossed since that epoch.

How to deal with PLC internal clock drift is another topic.
 
Had a quick look at this but it's in thai I think but seems to show conversion into uint
Thank you, this video helped a lot. Thanks to Google and its auto-translation, I was able to come up with this code as attached. Worked great. Instead of the HOLD timer (just to hold the check until the reset minute will pass), a flag for "seconds" can be implemented. So in short, DtToDateStruct works like charm and allows to manipulate with its children.

But I'd still want to learn how to use Trunc and work with strings. As well as math conversions. At least to check what way works the best.

p.s. Couldn't find a simple way to increment/"++" instruction. As any TRUE/FALSE switch in simulation increases the standard "+" and the quantity by random hundreds.
 

Attachments

  • Untitled.png
    Untitled.png
    197.1 KB · Views: 9
An add instructionj will do by adding a value every scan Mitsubishi has most functions as two different types i.e. ADD & ADDP , the latter does it on a oneshot (rising edge only) As I said years since I did Omron but perhaps they also have instructions that are rising edge only you must remember the program is scanned probably every 20 ms so by adding 1 to a tag it will increase by 1 every scan until the enable bit goes false that is why many plc's have pulse instructions but not sure about Omron, however, there is an RTRIG function that when enabled only comes on for one scan so you can do this
LD My_Bit RTRIG Temp_Bit
then use the temp bit to add the value
1737609952673.png
 
An add instructionj will do by adding a value every scan Mitsubishi has most functions as two different types i.e. ADD & ADDP , the latter does it on a oneshot (rising edge only) As I said years since I did Omron but perhaps they also have instructions that are rising edge only you must remember the program is scanned probably every 20 ms so by adding 1 to a tag it will increase by 1 every scan until the enable bit goes false that is why many plc's have pulse instructions but not sure about Omron, however, there is an RTRIG function that when enabled only comes on for one scan so you can do this
LD My_Bit RTRIG Temp_Bit
then use the temp bit to add the value
Thank you for the idea. Yes, the R_TRIG instruction worked:
1737636963969.png
 
Or just generate your own one-shot (pulse) logic:
It looks like there is a glitch in the software. When you move the instruction to an existing rung with the same instruction ("=") - it first drops the connection. But re-adding or double-clicking the output solves the problem. I tried this yesterday, but for some reason, it didn't work for me. Now I tried after I saw your message, clicked a few times and it worked. Thank you, really appreciate the simplicity!
p.s. The variables aren't set correctly, it was just a test.

1737637731964.png
 
Attached is the final version of the daily reset counter that can be set a given time of the day (HH:MM but you're welcome to add secs if needed). Just wanted to post here for the records, hope it helps for anyone looking for SYSMAC Studio specifically:
1737638532803.png

Thanks @drbitboy @Sparky_Joe for your inputs!
 

Similar Topics

Hi all, anyone in the uk have a lot of experience with sysmac link, having issues at the moment which has caused the whole site to be down since...
0
Replies
19
Views
For my graduation internship, I am working on rewriting a transport system control. This system consists of three different machines. The number...
4
Replies
665
Views
My company has a library that we use for Sysmac Studio but we don't have a documented process on how to add function blocks to this library. The...
0
Replies
361
Views
Hello plc enthusiast. Just wanted to ask how to step by step add PF 525 to sysmac studio? just needed it to control the VFD via ethernet. Thanks.
0
Replies
488
Views
I´m trying to backup an NX, but when I see the backup all my IOLink devices are gone, what am I doing wrong?
0
Replies
566
Views
Top