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:
- #101=#3011
- #102=#3012
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
Where:
- 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
- M30
We only need the current hour, so only the H argument is specified. Now, modify the program’s beginning:
- O0001
- 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.16666]GOTO10
- 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.
Related Content
Troubleshooting Differences in Programming Methods, Machine Usage
Regardless of the level of consistency among machines owned by your company, you probably have experienced consistency-related issues. Here are some tips to help solve them.
Read MoreHelp Operators Understand Sizing Adjustments
Even when CNCs are equipped with automatic post-process gaging systems, there are always a few important adjustments that must be done manually. Don’t take operators understanding these adjustments for granted.
Read MoreTips for Designing CNC Programs That Help Operators
The way a G-code program is formatted directly affects the productivity of the CNC people who use them. Design CNC programs that make CNC setup people and operators’ jobs easier.
Read More4 Commonly Misapplied CNC Features
Misapplication of these important CNC features will result in wasted time, wasted or duplicated effort and/or wasted material.
Read MoreRead Next
The Future of High Feed Milling in Modern Manufacturing
Achieve higher metal removal rates and enhanced predictability with ISCAR’s advanced high-feed milling tools — optimized for today’s competitive global market.
Read MoreInside Machineosaurus: Unique Job Shop with Dinosaur-Named CNC Machines, Four-Day Workweek & High-Precision Machining
Take a tour of Machineosaurus, a Massachusetts machine shop where every CNC machine is named after a dinosaur!
Read MoreIncreasing Productivity with Digitalization and AI
Job shops are implementing automation and digitalization into workflows to eliminate set up time and increase repeatability in production.
Read More