Jiial

Sysmac Studio, how to get the program cycle time

12 posts in this topic

Hello,

I am new with the Sysmac Studio, today I ran into a new problem, I need to be able to use the current program cycle time in program.

Where and how will I get it?

Share this post


Link to post
Share on other sites

Apparently that's not possible. Maybe someone else knows of another method.

MrPLC_ExecutionTime.thumb.JPG.5679f08bd7

Share this post


Link to post
Share on other sites
4 hours ago, Jiial said:

Hello,

I am new with the Sysmac Studio, today I ran into a new problem, I need to be able to use the current program cycle time in program.

Where and how will I get it?

Out of curiosity - why would you need this?

The cycle time in an NJ/NX is always the same and you specify it in the task settings.

 

Share this post


Link to post
Share on other sites

Are you looking for the execution time or the set period time? The "Set Period" time is setup in the the task settings. In the case of a program I have in front of me, it is set to 4ms (4000us), this is what photovoltaic was referring to.

The Execution Time is the time that the PLC takes to run each cycle. This is what IO_Rack was referring to I believe. This can vary between executions (in my case 1.76ms - 2.7ms).

 

If you need the cycle time, you will know what that is from your Task Settings (in my case, 4ms), so just create a variable with the same value. If you are looking for execution time, then I dunno how that can be done.

 

 

Share this post


Link to post
Share on other sites

Posted (edited)

Hello and thank you for your replies.

Like I said I am new with Sysmac, before I have been using Siemens programs and there I am using the Program Cycle Time to calculate how much a motor has turned during one program cycle. 

If I understood correctly from BE's answer, in Sysmac Studio the Execution Time corresponds to Siemens Program Cycle Time and that is what I need?

Edited by Jiial
Typing errors

Share this post


Link to post
Share on other sites

We are referring to Execution Time or PLC Scan Time. This is the time it takes the PLC to run the program one time and is very, very fast. We mis-understood you. What you want is an Accumulation Timer to measure the amount of time your motor is ON. 

Share this post


Link to post
Share on other sites

So it's the execution time that I need.

Is there any way to get that? 

Share this post


Link to post
Share on other sites

Posted (edited)

On 2/5/2022 at 11:06 AM, Jiial said:

Hello,

I am new with the Sysmac Studio, today I ran into a new problem, I need to be able to use the current program cycle time in program.

Where and how will I get it?

Hello @Jiial, I solved this using this function: 

ULINT_type:= "Get1usCnt()";

// =========================================================================================

Precautions for Correct Use

  • Free-running counters start counting as soon as the power supply is turned ON. When the count exceeds the valid range of ULINT data (18,446,744,073,709,551,615), it returns to 0 and counting continues.
  • This instruction only gets the current value of the free-running counter. It does not reset the counter to 0.
  • The start value of Out is not defined. It does not necessarily start from 0.

// =========================================================================================

If you want to obtain the Delta System Time (The previous system time of all cycle), you need to do your Function. I do this function:

// =========================================================================================

FUNCTION F_GetDeltaSystemTime_ms : LREAL // Delta time extract in 'us', but the output is in 'ms' in LREAL format. Needs an InOut non-volatile variable.
 

VAR IN_OUT

      io_lrPrevSysTime : LREAL; // Auxiliar InOut variable in miliseconds (ms), the time calc is made in microseconds (us)

      io_uliPrevSysTime : ULINT; // In microseconds (us), auxiliar InOut variable to store the previous cycle
 

END_VAR;

VAR

     t_lrActualSystemTime : LREAL;

     t_uliActualSystemTime : ULINT;

END_VAR;

VAR_CONSTANT

     c_LREAL_LONGEST : LREAL := 1.79769313486231e+308; // This Max LREAL value : 1.7976931348623158E+308 not allowed

     c_ULINT_LONGEST : ULINT := 18446744073709551615; // Max Value for an ULINT variable

END_VAR

// -----------------------------------------------------------------

t_lrActualSystemTime := ULINT_TO_LREAL(Get1usCnt()) / 1E3; // 'us' to 'ms';

IF t_lrActualSystemTime - io_lrPrevSysTime  >= 0.0 THEN
    F_GetDeltaSystemTime_ms := t_lrActualSystemTime - io_lrPrevSysTime;
    
ELSE
    F_GetDeltaSystemTime_ms := (t_lrActualSystemTime + 1.0) + (c_LREAL_LONGEST - ABS(io_lrPrevSysTime));
END_IF;

io_lrPrevSysTime := t_lrActualSystemTime;

t_uliActualSysTime_us := Get1usCnt();

IF t_uliActualSysTime_us - io_uliPrevSysTime  >= 0 THEN
    F_GetDeltaSystemTime_ms := ULINT_TO_REAL(t_uliActualSysTime_us - io_uliPrevSysTime);
ELSE
    F_GetDeltaSystemTime_ms := ULINT_TO_REAL((t_uliActualSysTime_us + 1) + (c_ULINT_LONGEST - io_uliPrevSysTime));
END_IF;

F_GetDeltaSystemTime_ms := F_GetDeltaSystemTime_ms / 1E3; // 'us' to 'ms';

io_uliPrevSysTime := t_uliActualSysTime_us;

// =========================================================================================

I hope I've helped you.

 

Edited by icanet
Correction of CODE, now the DeltaSysTimeCycle is correct
2 people like this

Share this post


Link to post
Share on other sites

Hello icanet, thank you very much for your effort, I'll try that.

Jiial

1 person likes this

Share this post


Link to post
Share on other sites

Wouldn't this code just yield the task time?

It's a snapshot of the us counter in the same place every scan. It should equal the cycle time set in the task settings. You're after this:

Capture.PNG

Share this post


Link to post
Share on other sites

What about the GetMyTaskStatus instruction be helpful for what you are trying to do? See the snip

Capture.JPG

1 person likes this

Share this post


Link to post
Share on other sites
2 hours ago, b.k.n. said:

What about the GetMyTaskStatus instruction be helpful for what you are trying to do? See the snip

Capture.JPG

I believe you're correct

Capture.PNG

1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now