Melsec real-time clock resolution

The program below will measure date and time difference between moment when bMsgSent is ON and bMsgRecieved is ON, and additionally add ms info in wmS_elapsed register:

SET(bMsgSent,bMsgMeasurement);
RST(bMsgRecieved,bMsgMeasurement);
PLS( bMsgMeasurement , bMsgMeasurement_PLS );



DATERD( bMsgMeasurement_PLS , wDateStart );
DATERD( bMsgMeasurement_PLF, wDateStop );

MOVP( bMsgRecieved , w1ms_cnt , wmS_elapsed);
RST(RCPU.stSM.b1sClock AND bMsgMeasurement, w1ms_cnt);


OUTH( (bMsgMeasurement AND NOT T1) , T1 , K1 );
INCP(T1, w1ms_cnt);


PLF( bMsgMeasurement , bMsgMeasurement_PLF );
IF bMsgMeasurement_PLF THEN

wDateDiff[0]:=wDateStop[0]-wDateStart[0];
wDateDiff[1]:=wDateStop[1]-wDateStart[1];
wDateDiff[2]:=wDateStop[2]-wDateStart[2];
wDateDiff[3]:=wDateStop[3]-wDateStart[3];
wDateDiff[4]:=wDateStop[4]-wDateStart[4];
wDateDiff[5]:=ABS(wDateStop[5]-wDateStart[5]);
wDateDiff[6]:=wDateStop[6]-wDateStart[6];
END_IF;

It needs a little of brush up, and it is not bad idea to put it in Fixed Scan with 0.5ms interval.
 
Alfredo needs to read ms the DATERD only reads down to seconds, you need to use the SP_DATERD to read the extended time including ms, however, depending on the processor & firmware version only High spec ones can use the SP_DATERD, My processor is an old Q06H so does not support the SP function.
Also a word of caution, try to make the code within the interrupt as small as possible due to the interrupt itteration if the code takes longer than the interrupt time.
Here is a screenshot of a trial where the interrupt ws set at 0.5ms, the PLC scan time is 6.4, the count in the interrupt is 12 or 13 so dividing it by 2 gives 6ms it is +-0.5ms, no point in using decimal places as they cannot be added to the time.

point 5 ms.jpg
 

Similar Topics

Hi! I'm currently working on connecting between vision sensor and PLC and I'm interested in one setting in IV navigator, it's connection over...
Replies
0
Views
56
Could anyone point me in the right direction for what software would be used to open up a PLC Program from a Mitsubishi MELSEC AnS processor...
Replies
10
Views
301
Hi, Does anyone here have experience logging a MELSEC Q03UDECPU with ibaPDA? I have followed this manual: ibaPDA-Interface-MELSEC-Xplorer , but...
Replies
2
Views
135
Hello all, I am trying to communicate with our test bench PLC which is a Q04UDEHCPU via the network. Ideally I would be able to do this in...
Replies
3
Views
330
Trying to buy the PLC cable that connects to the 30 pin male data port with software so I can download the program from the PLC to a computer.
Replies
5
Views
440
Back
Top Bottom