Table of Contents

MP STUDIO 2 · Device Clock (RTC)

The device clock has the device put 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 device keeps time by itself when there is no clock module.

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

Turning It On

  1. Select Setting → RTC (Clock)….
  2. Turn on Use device 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 device 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 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 device 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 has stopped
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 values to set 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. Start monitoring (Ctrl+M) a device to which you downloaded the program with the device clock turned on. You can also do this during simulation.
  2. Select Run → Set Device Clock….
  3. Click Set to PC Time.

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

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

Check When Monitoring Starts

When you turn on monitoring of a real device and the device time differs from the PC by 5 seconds or more, you are asked once, with a question such as “The device clock is N behind the PC — set it to the PC time?”. Click Yes to set the clock in 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 device is confirmed to be the same as this project, and never during simulation.

When There Is No Clock Module (Internal Clock)

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

← Back to the MP STUDIO 2 User Manual