You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

Reply
 
Thread Tools Display Modes
Old September 23rd, 2023, 12:05 AM   #1
AlfredoQuintero
Lifetime Supporting Member
Japan

AlfredoQuintero is offline
 
Join Date: Feb 2015
Location: Yokohama
Posts: 1,416
Melsec real-time clock resolution

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
  Reply With Quote
Old September 23rd, 2023, 03:20 AM   #2
parky
Member
United Kingdom

parky is online now
 
parky's Avatar
 
Join Date: Oct 2004
Location: Midlands
Posts: 5,484
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.
Attached Images
File Type: png Interrupts.png (50.4 KB, 65 views)
  Reply With Quote
Old September 23rd, 2023, 04:44 AM   #3
AlfredoQuintero
Lifetime Supporting Member
Japan

AlfredoQuintero is offline
 
Join Date: Feb 2015
Location: Yokohama
Posts: 1,416
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.
  Reply With Quote
Old September 23rd, 2023, 07:38 AM   #4
parky
Member
United Kingdom

parky is online now
 
parky's Avatar
 
Join Date: Oct 2004
Location: Midlands
Posts: 5,484
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.
Attached Images
File Type: png Intterupt prog.png (45.6 KB, 4 views)
File Type: png Fixed scan.png (114.7 KB, 3 views)
  Reply With Quote
Old September 23rd, 2023, 08:11 AM   #5
parky
Member
United Kingdom

parky is online now
 
parky's Avatar
 
Join Date: Oct 2004
Location: Midlands
Posts: 5,484
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 by parky; September 23rd, 2023 at 08:16 AM.
  Reply With Quote
Old September 23rd, 2023, 09:14 AM   #6
AlfredoQuintero
Lifetime Supporting Member
Japan

AlfredoQuintero is offline
 
Join Date: Feb 2015
Location: Yokohama
Posts: 1,416
Hi Parky. This sounds too complicated. I will tell the customer that this cannot be done with Melsec.
  Reply With Quote
Old September 23rd, 2023, 09:38 AM   #7
parky
Member
United Kingdom

parky is online now
 
parky's Avatar
 
Join Date: Oct 2004
Location: Midlands
Posts: 5,484
Just to get the ms between the delay is not too complicated but having it as a timestamp i.e. HH.MM.SS.MS could be a lot more code first you need to read the clock turn it into ms then add the accumulated ones & turn it back into a time, not that difficult & it does appear that there is a way to read even ms see this manual

https://dl.mitsubishielectric.com/dl...81266engaa.pdf
  Reply With Quote
Old September 23rd, 2023, 09:57 AM   #8
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 7,296
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?
__________________
_
Brian T. Carcich
i) Take care of the bits, and the bytes will take care of themselves.
ii) There is no software problem that cannot be solved with another layer of indirection.
iii) Measurement is hard.
iv) I solemnly swear that I am up to no good
v) I probably have the highest ratio of forum posts to actual applications in the field (but no longer ∞ ).
vi) Hakuna matata.
vii) Bookkeeping.
viii) But I should be ignored.
  Reply With Quote
Old September 23rd, 2023, 10:29 AM   #9
parky
Member
United Kingdom

parky is online now
 
parky's Avatar
 
Join Date: Oct 2004
Location: Midlands
Posts: 5,484
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.
  Reply With Quote
Old September 23rd, 2023, 03:38 PM   #10
goghie
Lifetime Supporting Member
Serbia

goghie is online now
 
Join Date: Jan 2008
Location: Belgrade
Posts: 739
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.
  Reply With Quote
Old September 24th, 2023, 03:06 AM   #11
parky
Member
United Kingdom

parky is online now
 
parky's Avatar
 
Join Date: Oct 2004
Location: Midlands
Posts: 5,484
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.
  Reply With Quote
Old September 24th, 2023, 07:10 AM   #12
goghie
Lifetime Supporting Member
Serbia

goghie is online now
 
Join Date: Jan 2008
Location: Belgrade
Posts: 739
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.
  Reply With Quote
Old September 26th, 2023, 06:19 AM   #13
parky
Member
United Kingdom

parky is online now
 
parky's Avatar
 
Join Date: Oct 2004
Location: Midlands
Posts: 5,484
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
Attached Images
File Type: png Parameter.png (190.2 KB, 5 views)
File Type: png Interrupt.png (282.2 KB, 5 views)
  Reply With Quote
Old September 26th, 2023, 10:12 AM   #14
AlfredoQuintero
Lifetime Supporting Member
Japan

AlfredoQuintero is offline
 
Join Date: Feb 2015
Location: Yokohama
Posts: 1,416
parky, thanks. This is so cool. I must give this a try. I think I only can do this in the weekend.
Thanks so much.
  Reply With Quote
Old September 26th, 2023, 02:55 PM   #15
parky
Member
United Kingdom

parky is online now
 
parky's Avatar
 
Join Date: Oct 2004
Location: Midlands
Posts: 5,484
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
LD M1
INC D0
etc.
.....

IRET //Interrupt return

END
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Micrologix 1400 start real time clock crawler009 LIVE PLC Questions And Answers 12 October 23rd, 2019 12:18 AM
Real Time Clock From HMI dternosky LIVE PLC Questions And Answers 25 June 26th, 2016 03:49 AM
Real Time Clock Value on PLC matt4276 LIVE PLC Questions And Answers 5 June 15th, 2016 11:20 AM
Programming for real time clock application in S7-200. kamaljit.lote LIVE PLC Questions And Answers 0 October 21st, 2009 12:37 PM
Real Time Clock setting changes OFG LIVE PLC Questions And Answers 4 January 20th, 2006 11:01 AM


All times are GMT -4. The time now is 12:05 PM.


.