CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Wed Nov 13, 2019 7:40 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sat Aug 17, 2019 2:20 pm 
Offline

Joined: Mon Aug 13, 2018 4:59 pm
Posts: 4
Hi all

I'm pretty new to all things Codesys.

I'm been playing with Oscat libraries and trying to learn from them.

Now I'm trying to understand what the 'debug' component of the T_PLC_MS function actually does. As I understand it, the PLC should reach an overflow condition every 49 days and the debug component is somehow meant to circumvent this. Is that right?

Could somebody please explain to me how this works. The Oscat explanation is a bit lost on me.

If somebody could help me I'd be very grateful.

Why wouldn't I just use the time() function? What is the benefit of the Oscat function??

FUNCTION T_PLC_MS : DWORD
VAR CONSTANT
debug : BOOL := 0;
N : INT := 0;
offset : DWORD := 0;
END_VAR
VAR
tx : TIME;
END_VAR

##############

tx := TIME();
T_PLC_MS := TIME_TO_DWORD(Tx);

IF debug THEN
T_PLC_MS := (SHL(T_PLC_MS,N) OR SHL(DWORD#1,N)-1) + OFFSET;
END_IF;


Top
   
PostPosted: Wed Aug 28, 2019 6:54 am 
Offline

Joined: Tue Mar 26, 2019 4:28 pm
Posts: 40
The debug section has some bit hackery tools for fast computation which make it hard to read.
Essentially N increases the speed of the clock, forcing a rollover not every 49 days, but every 49/(2^N) days. Offset also allows you to change the start value of your clock so the first rollover happens in say 1 minute instead of waiting a full 49/(2^N) days.
You would use this to test how your own code (which uses the T_PLC_MS()) functions at the rollover. For example do you have code that says:
Code:
IF input1 AND NOT AlreadySeenInput1 THEN
  StoredTime := T_PLC_MS();
  AlreadySeenInput1 := TRUE;
END_IF;
IF ( T_PLC_MS() > (StoredTime + 30000) ) THEN
  ThirtySecondsLater := TRUE;
END_IF;

If StoredTime was 10000ms less than the rollover,
(StoredTime + 30000) would then be only 20000, and ThirtySecondsLater would come on immediately.
You could test that scenario in simulation in a matter of minutes with the debug code, just don't leave it on the real machine!

Warm welcome to all things Codesys!


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 2 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited