Converting Time and Date to a More Useful Format
FANUC and FANUC-compatible CNCs have multiple ways to monitor time. They are accessed by four system variables: milliseconds clock, hours clock, current date and current time. Here’s how to format information in a helpful way.
- Milliseconds clock: (#3001). This variable always runs, can be reset using #3001=0 and will automatically reset after a few minutes (or when the power is turned off).
- Hours clock: (#3002). This variable includes the decimal portion of an hour. It always runs, can be reset using #3002=0, is retained after the power is turned off and will automatically reset after about 397 days.
- Current date: (#3011). This variable is shown in yyyymmdd format. It always runs and cannot be reset.
- Current time: (#3012). This variable is shown in hhmmss, 24-hour format. It always runs and cannot be reset.
The milliseconds clock reset interval is usually too short for any meaningful purpose. The hours clock is much better, but it does not consider “machine off” time. The date and time clocks are great, but their format is somewhat cumbersome. For example, at 3:45:10 p.m. May 3, 2019, we give these commands:
The values of common variables #101 and #102 will be:
- #101: 20190503 (date)
- #102: 154510 (time)
While this is great information, the format in its current state is not very helpful for timing purposes. They would not help much if, in a program, you need to determine the total amount of time a machine has been in use.
Our upcoming program uses date/time information to parse out the year value, determine the number of hours from the beginning of 2019 (midnight 12/31 of 2018), and the day-number of the current year (from 1 to 365 or 366 in a leap year). Here is the calling command, which could be placed in any program that requires timing an event:
- G65 P9060 D#3011 T#3012 Y102.0 H103.0 F104.0
- P9060: Program number for custom macro
- D (#7): The date value to convert
- T (#20): The time value to convert
- Y (#25): If included, the number of the variable that will contain the year value.
- H (#11): If included, the number of the variable that will contain the hour value.
- F (#9): If included, the number of the variable that will contain the day number.
If this command is given at 2:25 p.m. on February 4, 2019, the values of #102-#104 will be:
- #102: 2019.0000 (year)
- #103: 834.4146 (hours from the beginning of 2019)
- #104: 35.0000 (days into the year)
Of primary importance is the hours value. It works much like the hours clock, but it is not affected by power on/off status, it considers leap years and it never resets. If the need arises, you could easily modify the program to have it output other time-related information such as month, day or hour.
Example: Need for Warmup
You need to determine elapsed time since finishing the last cycle. If it is over a given amount (say 10-minutes), the machine has cooled and needs to run a warm-up routine. The longer the elapsed time, the longer the required warmup.
Add this command at the end of your machining program:
- G65 P9060 D#3011 T#3012 H500.0
We only need the current hour, so only the H argument is specified. Now, modify the program’s beginning:
- G65 P9060 D#3011 T#3012 H501.0
Next subtract #501 from #500. If the result is greater than 10 minutes (10/60 hours, or 0.1666) a warmup is required:
- #1=#501=#500 (elapsed time)
- IF[#1LE0.33332] THEN #2=300 (5-minutes)
- IF[[#1GT0.33332] AND [#1LE0.5]] THEN #2=600
- IF[#1GT0.5] THEN #2=900
- S2000 M03 (Start spindle to warmup the headstock)
- G04 X#2 (dwell)
- N10 (Continue)
You may be thinking this easily could have been done with the hours timer (#3002). Keep in mind that the hours timer will ignore any elapsed time that occurs in the power-off state. If this program is run at the beginning of the day/shift, it is likely that the power will have just been turned on. A very long time may have elapsed since the last cycle was run. Since we are using permanent common variables in which to store hours data, elapsed time will be retained after the power is turned off.
Parameters tell the CNC every little detail about the specific machine tool being used, and how all CNC features and functions are to be utilized.
What does "jerk" refer to, and where does it fit into machine performance?
While the mistakes listed here will not sound an alarm or cause a program to fail, they will cause confusion, wasted time and scrap parts.