Jump to content

Recommended Posts

Posted

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?

Posted
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.

 

Posted

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.

 

 

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
Posted

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. 

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
  • Like 2
Posted

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

Posted
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

  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...