Code for SoftPAC (Computer running SoftPAC and Display Runtime on the same PC)
IncrementVariable(Scan_Time_00); //Executed every scan
If (Comm_3_Timer == 0) Then
SetUpTimerTarget(1.0, Comm_3_Timer);
StartTimer(Comm_3_Timer);
Endif
If (HasUpTimerReachedTargetTime(Comm_3_Timer)) Then
Scan_Time_02 = Scan_Time_00; //Number of scans per Second
Scan_Time_01 = ((1/Scan_Time_00) * 1000); //1 second divided number of scans per second * 1000 to display mSecs
Scan_Time_00 = 0; //Reset Scans per second
Bit009 = GetIoUnitScratchPadFloatTable(PAC_A01, 10, 0, 0, Flt10); //Get scans per second and mSec calc from SNAP-PAC-R1
Comm_3_Timer = 0; //Reset Timer
Endif
Comm_3_Timer is an up timer
Scan_Time_00 - 02 is Floating Point Values
Bit009 is a 32 integer
Flt10 is a FloatTable Length 10
SNAP-PAC R1 Code
IncrementVariable(Value005);
Flt10[0] = Value005;
If (Comm_1_Timer == 0) Then
SetUpTimerTarget(1.0, Comm_1_Timer);
StartTimer(Comm_1_Timer);
Endif
Comm_1_Timer is an up timer
Flt[0] - [2] and Value005 are Floating Point
Bit009 is a 32 integer
Flt10 is a FloatTable Length 10
This is not exact because of the execution time of the actual code, but it is fairly accurate.
I’ve included a shot of my screen and the one thing I haven’t figured out is why SoftPAC executions drops off so fast when I close Google Chrome (ESPN). Then goes back up when I reopen ESPN. Any ideas?
I failed to mention… This must be put in a Chart that runs all the time on both “Controllers”.
Edit: Just for some perspective in the sorting speed on PAC Sim - even though this is 50 times faster than an R1, it is still about 3 to 4 orders of magnitude slower than running quicksort natively on a modern PC.
Hmm, very interesting. I wanted to know how fast the execution was in each. I guess it depends on exactly what it is trying to do as well. Any thoughts as to why SoftPAC slows down when I don’t have a web browser up and running (example ESPN)… or is this just a misconception of what is actually happening?
We have been doing similar tests here at Opto (cant say why, or on what hardware).
Enough to say, yes, your right, it all depends on what code you are running. If you add a few I/O units and some analog or serial modules into the mix, things change again.
For a base line, you have the right idea, do some stuff and time it. Make it the same code on both platforms and you can get a very rough approximation.
Hint, if you throw some ‘heavy’ float calculations in there, you will see (very) different again numbers.
One thing that is super super super super super critical is that your chart must must must must must must must have a delay in it. All charts, through all loops must must must must must have a delay (At least 1msec, but honestly, 10msec or so would be better). Can not stress this strongly enough.
Regarding the Windows CPU / speed . You are not seeing things. Windows is not deterministic. It is happy to let its different programs just float around the grid as the master control program (MCP) wishes… sorry, my Tron might be leaking… But seriously, we saw the exact same thing here. Depending on what programs were or were not doing, the softpac speed would go up and down, and not always in an expected or logical manor.
Best result is on a headless unit with a really minimal install.
This really shows why a PAC R or PAC S controller is the best for consistent performance. (Unless you can dedicate said headless Windows box).
The other thing that is interesting is that some hardware platforms will throttle CPU speed (clock) as they heat up.
We could plot this really clearly in PAC Display or groov trends. Again, the R and S controllers DO NOT do this.
Computer BIOS settings will also impact these sorts of speed ‘tests’. (No, I cant say more on this).
So with my browser just sitting there open (ex at ESPN.com .or basically anything that has ads on the page), the speed increases 10x (easily) So, wouldn’t it be safe to say there is some process that is running in the background while that browser is open that enhances SoftPAC? …or is it just the fact that I am actually making the CPU do more work, which makes SoftPAC run smoother? My end goal is to use SoftPAC to take away duties from the R1 so the R1 can run my process as fast and efficient as it can. The faster SoftPAC runs efficiently, the more I can make it do, but if it can’t do that at a consistent basis, I might want to rethink what I am trying to achieve.
Ben touched on it with windows speed throttling- I suspect what is happening when you have your browser open to ESPN, is that it is putting enough load on your system to bring the CPU to full speed - or even into the turbo speed if your CPU supports that.
You may want to try putting a system monitor that shows you your CPUs current clock speed and see how it is changing.
Just for kicks i tried 10msec delay on each chart. It stayed at a constant 97 scans per second with browser open or not. Then I set the delays to 0 msecs and it is off the charts fast. 9,455 scans per second. no browser open. It’s like my system ate spinach. heh.
I couldn’t leave this alone so I ran some tests myself. Ben is absolutely right about having a delay in every chart in the SoftPAC strategy. Although, if you control the rate at which you apply that 1 msec delay, you can maintain a smooth execution rate per Chart in SoftPAC. It will also automatically adjust the Execution Rate so no matter what you are doing in Windows (Web Browser, Image Program, AutoCAD), it will continue to execute at the desired rate.
Please keep in mind, I program my strategy using OptoScript as much as I possibly can. So this will not work in every case. Also, every computer is different and I have only tested this on my system. My system is as follows:
Windows 10 Pro 64bit
Intel Core i5-6260U CPU @ 1.8GHz
16.0 GB RAM
250GB SSDrive
(This is an Intel NUC build)
I’ve included a .png image of what I did. I think you’ll figure it out.