Author Topic: Sync Time between PLC and HMI  (Read 16622 times)

rjd1234

  • Newbie
  • Posts: 6
    • View Profile
Sync Time between PLC and HMI
« on: October 02, 2015, 11:25:02 AM »
I'm using a mT6070iE and FX1616 for my process.  I'm using the HMI to log a lot of data as required for government compliance.  

I know how to set the time for the HMI and PLC individually, but I would like them to sync.

Does anyone know of a way to sync the times between both?  Maybe there is a way for the HMI to read the time from the PLC or something?

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:Sync Time between PLC and HMI
« Reply #1 on: October 02, 2015, 02:43:06 PM »
Yes.  

The approach that I would take is to copy the HMI time to the PLC.  

If you are using the TRI_FX or the Modbus drivers for the HMI you can write an HMI macro that copies the HMI time to the PLC TIME[] registers.  The HMI registers are in a block from LW-9010 to LW9049.

It is possible to have the HMI macro run on a schedule. I'd update once a day and after 2:00 AM so that you pickup daylight/standard time changes if this is important for your application.
 
I would suggest that your HMI macro, read all of the HMI time registers as a complete set in a loop until you get 2 sequential reads with the same values. It is possible that if you are reading the time registers near a big transition such as 1:59:59 --> 2:00:00 it is possible to "read" the time as 1:59:00 and the next time your read it you will see the correct time as 2:00:00.  

The same problem can occur with the PLC.  I suggest that when your write to the PLC TIME[] registers that you read them back to verify that the time registers got set to the correct value.

I would, also, suggest that you set up the HMI to sync it's real time clock to a network time server. This is an option on the HMI.

Best regards,

Gary D*ickinson

« Last Edit: October 02, 2015, 02:44:15 PM by garysdickinson »

rjd1234

  • Newbie
  • Posts: 6
    • View Profile
Re:Sync Time between PLC and HMI
« Reply #2 on: October 02, 2015, 03:01:43 PM »
Gary, Thanks for the response.  Those are good suggestions.  

I wish I could have the HMI reference a network, but the equipment is off the grid, on a remote island.  We actually power everything using a generator.

I like the idea of copying the HMI time to the PLC.  I'm wondering if I might write the time on the PLC using a 1st scan custom function.  What do you think?  The only issue then would be how to reference the HMI time registers from the PLC.

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:Sync Time between PLC and HMI
« Reply #3 on: October 02, 2015, 03:43:13 PM »
You can SYNC The HMI from the PLC but you will find that this approach is more difficult.

The 2 approaches that come to mind:
  • Set a RELAY in the PLC to indicate that you want the HMI to set its clock to match the PLC.  On the HMI side you need to have a MACRO that executes periodically and checks for this RELAY to be set.  The MACRO reads the PLC TIME[] registers and then updates the HMI registers. This macro clears the RELAY to indicate that the HMI has been updated.  This approach avoids the issue of the HMI taking longer to start up and eliminates the need for the PLC to be able to change stuff in the HMI.  
  • Set up the HMI"s MODBUS TCP/IP server and have the PLC change the  HMI time registers using Modbus TCP/IP.  This is assuming that the PLC and HMI are networked together.  In most cases the PLC is slave to the HMI, but to allow the PLC to change things in the HMI requires that the PLC act as a master device.  To do this you will need a 2nd path between the the devices.  I think that this is making things way too complicated.
You will probably have problems with syncing the clocks on the first scan of the PLC.  If the HMI and PLC are powered from the same source, the HMI will take longer to get running then the PLC.  You may have to give the HMI some extra time before it is up and running.

The issue with the clocks in the HMI and PLC is that the clocks will drift apart.  How many seconds/minutes difference between the HMI and PLC clocks is OK for your application? You may need to sync the clocks more often often depending upon how they drift.  You may want to figure out which clock is more accurate over time and temperature and this may determine which clock to use as a reference.

If you need really accurate time and time and do not have access to the net, you might consider using a GPS module as a time reference.

My FX1616 test board drifts less than one second per day! It is running under very ideal conditions.  Stable power and temperature. I left it running for several months testing code to sync it to NIST time servers and it only had to re-sync once every few days.

Gary D*ickinson


« Last Edit: October 02, 2015, 04:46:25 PM by garysdickinson »