Posted 2 Nov 2020 Hello. I'm using CX-Programer and CJ2M CPU. Is it possible to get current time in ms like in arduinos millis()? Thanks. BR. Share this post Link to post Share on other sites
Posted 2 Nov 2020 (edited) Arduinos use a custom scripting type language based on C. PLCs are much simpler and are continuous scanning programs. Can you explain what you wish to accomplish? I ask because there are various methods to return time. 1) Open the instruction help section and look for "Clock Instructions". This is Calendar Time, Date. I believe the resolution is Seconds. No milliseconds that I'm aware of. 2) "Timer and Counter" instructions. These instructions will set a bit after an elapsed time. Resolutions vary. I believe down to 0.1ms in the CJ2 series. 3) There are also special bits that will pulse continuously with a 50% duty cycle. Try inserting a New Contact then type P_ then click the drop down box. For example, P_0_01s is the bit for a 0.01 second clock bit. There are several. EDIT: BTW... Since PLCs are continuous scanning programs, output reaction will only be as accurate as the PLC Scan Time. This varies depending upon the size of the program and the complexity of the instructions used. That being said, you can achieve faster reaction times with a High Speed module and Interrupt instructions. Edited 2 Nov 2020 by IO_Rack Share this post Link to post Share on other sites
Posted 2 Nov 2020 (edited) Hello. I'm trying to develop Tau filter wich uses time calculations like this: TimeNew := GetTime() // system time in miliseconds ExpTime := TimeNew - TimeOld TimeOld := TimeNew I guess I colud use CycleTime, but the resoult for CycleTime is not constant... Edited 2 Nov 2020 by AndrejP Share this post Link to post Share on other sites
Posted 2 Nov 2020 w473_cj2_cpu_units_software_users_manual_en.pdf Section "10-2-3 Monitoring the Cycle Time" of the above manual will show you the maximum, current scan time in 0.1 ms, current scan time in 0.01 ms. These settings are in the "Auxiliary Area Flags and Words" area. Regards, Garry Share this post Link to post Share on other sites
Posted 3 Nov 2020 Thanks for replay. But I don't want to mess with Cycle Time. The question is: Can I get current time/date (UDINT) in miliseconds? (Similar as arduino millis())? Thanks. BR. Share this post Link to post Share on other sites
Posted 4 Nov 2020 On 11/2/2020 at 9:34 AM, AndrejP said: Hello. I'm trying to develop Tau filter wich uses time calculations like this: TimeNew := GetTime() // system time in miliseconds ExpTime := TimeNew - TimeOld TimeOld := TimeNew I guess I colud use CycleTime, but the resoult for CycleTime is not constant... Running that code every scan will not be constant either. It will = cycle time. I don't have another suggestion for you though. Share this post Link to post Share on other sites
Posted 5 Nov 2020 The code that you show will return the Elapsed Time every time it is executed. What is the process or event you are measuring? The PLC can do this but it's not the exact same method. Share this post Link to post Share on other sites