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 Mon Jan 20, 2020 9:51 pm

All times are UTC+01:00

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

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??

debug : BOOL := 0;
N : INT := 0;
offset : DWORD := 0;
tx : TIME;


tx := TIME();

IF debug THEN

PostPosted: Wed Aug 28, 2019 6:54 am 

Joined: Tue Mar 26, 2019 4:28 pm
Posts: 75
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:
IF input1 AND NOT AlreadySeenInput1 THEN
  StoredTime := T_PLC_MS();
  AlreadySeenInput1 := TRUE;
IF ( T_PLC_MS() > (StoredTime + 30000) ) THEN
  ThirtySecondsLater := TRUE;

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!

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: vitovt1877 and 6 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