Melsec real-time clock resolution


Lifetime Supporting Member
Join Date
Feb 2015
Hello. This is one for the Mitsubishi experts.
I need to measure the time for a remote device's to return process data sent from the i-QR processor.
I had never tried to do this with Mitsubishi. I have found that the system devices related to the real-time clock support only resolution down to seconds. I am kind of shocked that this PLC does not provide millseconds resolution.
I wish I am wrong. Is there a way to get RTC down to millisec resolution in i-QR processor? Have been reading the manual and can't fine anything, so I need to make sure my conclusion is correct. Thanks
SM509 is 0.01 seconds or 100ms.

These are the others
SM400 Always On
SM401 Always Off
SM402 After RUN, ON for 1 scan only
SM403 After RUN, OFF for 1 scan only
SM409 0.01 second clock
SM410 0.1 second clock
SM411 0.2 second clock
SM412 1 second clock
SM413 2 second clock
SM414 2n second clock
SM415 2n millisecond clock
SM420 User timing clock No.0
SM421 User timing clock No.1
SM422 User timing clock No.2
SM423 User timing clock No.3
SM424 User timing clock No.4
SM440 On only initial I44 execution after RUN
SM441 On only initial I45 execution after RUN
There are also timed interrupts see pic.

Sparky thanks for your help, as always for Mitsubishi problems.
I am confused. SM509 is a system coil that pulses every 100 msec.
I need to get the the system time with a resolution of one msec.
I do not need to generate pulses. I need to calculate the time difference between the occurrence of two events.
I think the best solution is to use the 1ms time interrupt & increment a device for example in the 1ms time interrupt you use whatever the condition is to start the time & increment the device, when the condition is false stop incrementing & store the value, never tried it on a IQ series but did something similar on an older Q series
Create a program block in the constant scan task, set the constant program scan to 1ms.
I have just done one but in my case set a trigger bit in normal scan program then every ms the constant scan program increments a word, when the bit goes false it copies the ms count into a store & resets the count.

Intterupt prog.png Fixed scan.png
Just re-read your post 1ms is probably unatainable in reality unless you use the return information within the 1ms interrupt so if your program in normal scan is being used although the incoming response will have some kind of lag i.e. what ever you do in normal scan process until the return information is there don't know what sort of effect on the actual return time will be but assume you send a message, the return would only be processed in the processor tidying up after normal scan I would think so that may be the only delay. If you an actual time then again this would be doubtful, only the time it took to respond in ms plus any normal comms delay in processing the message.
you could probably read the RTC & store it when you trigger the request, then in the interrupt add that to the RTC timestamp somehow.
Last edited:
Would it be possible to combine fractional seconds from high speed retentive timers with whole seconds from the real-time clock? Or is that too complex?

What time resolution is desired? What is the maximum time to be measured?
The resolution required is 1ms, the extended clock data is in 0-999 ms in 1ms increments, however, the manual does state that it could be +-2ms not sure if that is when read by the functions.
Standard timer for Mitsubishi iQR is from 0 ms to 32767 ms (with 1 ms increment). There is way to use even shorter ones, but i takes little bit workaround.
Yes but even high speed timers if used in main scan will only update timer increment plus scan time so not really practical for a resolution of 1ms, even the timed interrupt can be 2ms even if set at 1ms i.e. 2 iterrations as it shows in the manual.
First solution is to use high speed timer which is from 1 us to 10000 us.
Second solution is to use fixed scan which is from 0.5 ms to 60000ms.
Attached, is a program that works, there are two programs both called in the scan program, the first is just some code where I have created a simple bit on/off every other scan (idea is to use this so it measures the scan time), just added a loop to get a reasonable scan time i.e. 5.7ms according to GXWorks2.
The other is the interrupt program, here I'm using the toggle bit from scan program to count the ms per scan.
Then when it goes false it stores the scan time or ms counts in a word & resets the count. so if you use some kind of trigger bit in your program (perhaps put it into the interrupt program i.e. true when you start a operation then false on the end this will store the number of ms of the function).
Note to set the interrupt you need to set the Interrupt program event to I31 & set the Time interrupt in PLC parameters I31 to 1ms.
If you need actual time then do a SP_DATERD function to read extended date/time values D+7 contains the ms of the extended RTC so you could read the clock, add the ms of the event & that will give you the time. I cannot use the extended read date/time as my processor is an early version i.e. a Q06H & it does not support the SP_DATERD function.
In my trial the IDE reported a scan time of 5.7ms, the interrupt counted it as 5ms but as we are only reading ms the 0.7 of the scan is not shown
I tried it at 0.5ms (the shortest allowed & gave me a real scan time of 6.2 & a count of 13 x 0.5 = 6.5ms so you could get a resolution of .5ms

Parameter.png Interrupt.png
Yes it's a little confusing at first, you need to set I31 into 1.0 ms in the PLC Parameters, in one of your main scan programs call the IE (Interrupt enable) function, then create a program block for the interrupt drop it in the scan program, go to properties & put I31 in the box, the rest is up to you what you want to do, i.e. perhaps read the extended RTC, on initial start of the request for the remote data reset the ms count, grab the RTC (Extended one with the ms data), when the remote data has been recieved, store the ms count add the ms to the the stored start time (not sure how you achieve this but there are some functions to do that but not being able to read extended RTC only standard RTC with my processor cannot try it.
Then again if you do not need actual real time just format your ms count into seconds/ms.

When compiled, it does the following:

Prog Main.
Call IE //call the interrupt enable
Do what ever your programs do
FEND / this is the end of the program scan
// start of subroutines
I31 // This is the interrupt program after the end of scan so called every 1ms

IRET //Interrupt return


Similar Topics

Hello to the Mitsubishi gurus. As always your words of wisdom are appreciated. I bought this CC-Link master in an auction site similar to to eBay...
I want to communicate my Q series PLC with Factory IO using GX works 2 software, I want to use modbus as server and the ips are as follows plc...
Hi everyone, I have a small project for an industrial site entry gate system. It's running on an old Melsec PLC, and I have a new Shihlin PLC...
Anyone have access to Melsec Medoc plus 2.31a that can either open a file (.pcd zipped in link below) and send a PDF/screenshot of the ladder, or...
Hello! First time poster and a big PLC newbie so I am looking for some backup here. I have an old Mitsubishi FX-48MR that lost its program...
Top Bottom