en-us_products:mp_studio:device_clock

MP STUDIO 2 · PLC Clock (RTC)

The PLC clock has the PLC write the date and time of an external DS3231 clock module connected to it into 16 words of the D area every 0.1 seconds, so that the ladder can read them directly (V1.2.0 and later). It also provides a window for setting the clock to the PC time, and an internal clock with which the PLC keeps time by itself when there is no clock module.

The PLC has no built-in clock module, so connect a DS3231 module (I²C address 0x68) to the I²C terminals of the PLC. Check the connection pins on each product's page. The module shares its lines with other I²C devices such as a character LCD.

Turning It On

  1. Select Settings → RTC (Clock)….
  2. Turn on Use PLC clock (RTC).
  3. Enter a D area address in Start address (default D100). The 16 words from the start address (D100 to D115) are used.
  4. Click OK, then download the program. After the download, the PLC updates the time every 0.1 seconds.

Figure 1. The RTC (Clock) window

The bottom of the window shows the flash and RAM this feature uses and its processing time (about 0.4 ms every 0.1 seconds). When it is off, the compiled program does not change by a single byte. Click Add names to the symbol table to add the names RTC_YEAR … RTC_REQ to the symbol table, so that you can use names instead of addresses in the ladder (optional).

Layout of the 16 Words

Values are stored as decimal numbers. The tables below are for a start address of D100.

Address Read (written by the PLC every 0.1 s) Range
D100 Year 2000 to 2099
D101 Month 1 to 12
D102 Date 1 to 31
D103 Day of week 1 to 7 (1 = Sunday)
D104 Hour 0 to 23
D105 Minute 0 to 59
D106 Second 0 to 59
D107 Status 0 OK · 1 no module (internal clock) · 2 stopped before
Address Set (written by PC, HMI or ladder) Description
D108 to D114 Year, month, date, day of week, hour, minute and second to set The ranges are the same as for reading.
D115 Set request Write 1 to set the clock. It becomes 0 when done, or 2 if a value is invalid (the clock is unchanged).

To set the time from the ladder or an HMI, write the new time values to D108 to D114, then write 1 to D115. A status of 2 means that the clock has stopped at some point, for example because the module battery was removed, so set the time again.

Setting the Clock to the PC Time

  1. Download the program with the PLC clock turned on, then start monitoring the PLC (Ctrl+M). You can also set the clock during simulation.
  2. Select Run → Set PLC Clock….
  3. Click Set to PC time.

Figure 2. The Set PLC Clock window (shown with the virtual clock because a simulation is running)

The window shows the PC time, the PLC time and the difference between them (“In sync (±1 s)”, “PLC N behind” or “PLC N ahead”). The time is sent so that it arrives just as the next second begins, and after setting, the PLC time is read again to confirm that it was actually set.

  • You can set the clock only when the PLC clock is turned on, monitoring or simulation is running, and the program on the PLC is confirmed to be the same as this project. If these conditions are not met, the button is disabled and the reason is shown in one line.
  • Whether the program on the PLC matches this project is confirmed from the record of downloading this program to that port (COM or IP) with MP STUDIO 2 on this PC. If it cannot be confirmed, download the program and turn monitoring on again.
  • If there is no clock module, the internal clock of the PLC is set, and you are told that the time is lost when the power is turned off.
  • The S1 port does not accept value writes, so the clock cannot be set through it. Connect through the download port.

Check When Monitoring Starts

When you turn on monitoring of a real PLC and the PLC time differs from the PC by 5 seconds or more, you are asked once, with a question such as “The PLC clock is N behind the PC — set it to the PC time?” Click Yes to set the clock the same way as above. If the clock has stopped at some point (status 2), a question asking you to check the module battery is shown instead. The question is asked only when the program on the PLC is confirmed to be the same as this project, and never during simulation.

When There Is No Clock Module (Internal Clock)

  • If the module is missing, is removed or cannot be read, the status becomes 1, and the PLC counts the time by itself and keeps updating it. The scan does not stop.
  • If the power is turned on without a module, the clock counts from 2000-01-01 00:00:00. The time is lost when the power is turned off.
  • When the module is plugged back in, the clock follows the module's time. It also follows a module that lost its time because it has no battery, so set the time again.
  • The internal clock is less accurate than the module (about -2.3 seconds a day on one PLC).

Simulation

In simulation, a virtual clock runs. It starts from the PC time when the simulation starts and advances with the simulation time, so it falls behind the PC if you pause or step one scan at a time. Restarting the simulation returns it to the PC time. The status is always 0. The DS3231_RD and DS3231_WR functions in the ladder use the same virtual clock.

Things to Check

  • If the 16-word block overlaps a retentive (EEPROM) D range, the program can be neither compiled nor downloaded, because the time words change constantly and would quickly shorten the life of the EEPROM. Move the block outside the retentive range or shrink the range (Data Memory).
  • If the ladder writes to the read words (D100 to D107), or the receiving cells of the Modbus device table overlap the block, an orange warning is shown. The warning does not prevent compiling.
  • The clock module uses the SDA pin, so that pin cannot be used as a counter or encoder input.
  • A project file (.mpx) that uses the PLC clock cannot be opened in V1.1.0.
en-us_products/mp_studio/device_clock.txt · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki