Jiial Posted May 2, 2022 Report Posted May 2, 2022 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? Quote
IO_Rack Posted May 2, 2022 Report Posted May 2, 2022 Apparently that's not possible. Maybe someone else knows of another method. Quote
photovoltaic Posted May 2, 2022 Report Posted May 2, 2022 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. Quote
BE Posted May 3, 2022 Report Posted May 3, 2022 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. Quote
Jiial Posted May 3, 2022 Author Report Posted May 3, 2022 (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 May 3, 2022 by Jiial Typing errors Quote
IO_Rack Posted May 3, 2022 Report Posted May 3, 2022 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. Quote
Jiial Posted May 4, 2022 Author Report Posted May 4, 2022 So it's the execution time that I need. Is there any way to get that? Quote
icanet Posted May 5, 2022 Report Posted May 5, 2022 (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 May 6, 2022 by icanet Correction of CODE, now the DeltaSysTimeCycle is correct 2 Quote
Jiial Posted May 10, 2022 Author Report Posted May 10, 2022 Hello icanet, thank you very much for your effort, I'll try that. Jiial 1 Quote
photovoltaic Posted May 10, 2022 Report Posted May 10, 2022 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: Quote
b.k.n. Posted May 25, 2022 Report Posted May 25, 2022 What about the GetMyTaskStatus instruction be helpful for what you are trying to do? See the snip 1 Quote
photovoltaic Posted May 25, 2022 Report Posted May 25, 2022 2 hours ago, b.k.n. said: What about the GetMyTaskStatus instruction be helpful for what you are trying to do? See the snip I believe you're correct 1 Quote
Recommended Posts
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.