====== 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 ===== - Select **Setting → RTC (Clock)…**. - Turn on **Use device clock (RTC)**. - Enter a D area address in **Start address** (default ''D100''). The 16 words from the start address (''D100'' to ''D115'') are used. - Click **OK**, then download the program. After the download, the device updates the time every 0.1 seconds. {{ :en-us_products:mp_studio:rtc-settings.png?640 |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 ===== - 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. - Select **Run → Set Device Clock…**. - Click **Set to PC Time**. {{ :en-us_products:mp_studio:rtc-sync.png?540 |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. * You can set the clock only when the device clock is turned on, monitoring or simulation is running, and the program on the device 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 device is the same 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 and then turn monitoring on again. * If there is no clock module, the internal clock of the device 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 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) ===== * If the module is missing, is removed or cannot be read, the status becomes 1, and the device 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 device). ===== 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 ([[:en-us_products:mp_studio:memory_symbols#data_memory|Data Memory]]). * If the ladder writes to the read words (''D100'' to ''D107''), or receiving cells of the [[:en-us_products:mp_studio:modbus_device_table|Modbus device table]] overlap the block, a yellow 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 device clock cannot be opened in V1.1.0. ===== Related Pages ===== * [[:en-us_products:mp_studio:monitoring|Phase 7 · Monitoring and the Data Table]] * [[:en-us_products:mp_studio:memory_symbols|Phase 5 · Memory and Symbols]] * [[:en-us_products:mp_studio:menus_settings|Phase 9 · Menus and Settings]] [[:en-us_products:mp_studio|← Back to the MP STUDIO 2 User Manual]]