How Can We Help?
How to set and synchronize the ACE PLC clock with the HMI using a macro
In this post, we will show you how to synchronize the HMI clock with the ACE PLC clock.
As the HMI has a saved clock, we use it to update the ACE PLC clock.
The HMI clock is in BCD format. In the ACE PLC, the clock is in DEC format.
This tutorial uses a macro to convert the HMI’s BCD (Binary-Coded Decimal) format clock into a DEC (DECimal) format clock.
With vBuilderFirst of all, the UI8 tags which will be written by the HMI must be defined in the Modbus register. For example, here we are using addresses 4×900 to 4×905. But you can use any area you want. Don’t forget to define them as ‘Writable’: ‘Y’ (See Tag list in vBuilder). You will obtain the HMI clock in your ACE PC (here, ‘sec’, ‘min”,..) |
![]() |
With HMI-Tool
The macro to convert BCD to DEC
In the Macro Editor, add a new macro and copy it.
The Script editor:
You don’t have to use all the tags, if you need, for example, only the hours and minutes.
#include "MacroInit.h"
int Convert (int input) // function to convert BCD to DEC
{
int iFirst = input &0x000F;
int iSecond = (input/16) &0x000F;
int iThird = (input/256) &0x000F;
int iFourth = (input/4096) &0x000F;
return iFirst + iSecond*10 + iThird*100 + iFourth*1000;
}
void Macro_main(IN *p)
{
MarcoInit // Main program
LocalWord[900] = Convert (BCDSec);
LocalWord[901] = Convert (BCDMin);
LocalWord[902] = Convert (BCDHou);
LocalWord[903] = Convert (BCDDay);
LocalWord[904] = Convert (BCDMon);
LocalWord[905] = Convert (BCDYea)-2000;
}
LocalWord[900] to LocalWord[905] are the HMI registers where we have placed the clock values in DEC format.
We could have used LocalWord[0] to LocalWord[5] or any other HMI register.
The macro tag list
And create the list of the tags used in the macro.
- BCDSec = LW[60000] = the seconds in HMI
- BCDMin = LW[60001] = the minutes in HMI
- etc…
Note: For all LB and LW HMI registers and to understand how the HMI register is organised, see “Useful HMI reserved and special registers”
Below the window script, the variables settings and an example of variable setting :
Compil the macro
The result must be ‘Success’
Add the macro in “Global Macro” list
Add the macro in “global Macro” list And set its frequency of execution to 1000 ms for update the clock every seconds.
From now, the HMI registers LocalWord[900] to LocalWord[905] contains clock values in decimal format (DEC)
Forward LocalWord[900] to LocalWord[905] in the ACE PLC
In HMI-Tool, on the left, “Data forward” > “Word address”, add the right word address forward for copy the LW900 to LW905 to the right network link and PLC id.
Once again, we are using the 900 registers on both sides, HMI and PLC, but you can use any area. The key is to be consistent throughout the configuration.
From now on, the ACE PLC receives the HMI clock in DECimal format in its registers.
Replace the LocalWord[900] to LocalWord[905] by your variables to write directly in the ACE PLC
In a macro, you can replace the ” LocalWord[900] = Convert (BCDSec);
” etc.. lines by ” MyPLC_Tag_Sec = Convert (BCDSec);
” where “MyPLC_Tag_Sec” is directly your PLC variable in macro’s tag list.
Project to download
You can download here the HMI and ACE project if you wish to test it.
Case where we want to switch off the HMI and keep the clock in the ACE PLC
It is necessary to set the ACE’s internal clock if the HMI clock is active
In main program If HMIsec, HMImin,… are the HMI clock in Modbus register We pass the HMI clock to the subroutine, which will update the ACE clock only if the HMI clock is active (HMIsec is changing) “Clock Read” (“Timer/Clock” in Tool Box) is a tool just for read the ACE clock |
In a subroutine (or main program) We check the the HMIsec, if it change, we update the ACE clock
|