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 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...
Replies
1
Views
132
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...
Replies
10
Views
383
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...
Replies
15
Views
515
Hi I have a Melsec FX1S-20MR, which has been programmed. I would like to copy the program to a new FX1S-20MR? What are the possible ways to do...
Replies
4
Views
620
Hello parky, goghie, Brian and all of you who kindly come to help when I get stuck. I cannot look into the clock issue that parki has written for...
Replies
5
Views
858
Back
Top Bottom