Page 1 of 1

Timed Do Loop in VBS

Posted: Mon 10. Jul 2017, 12:05
by Frederick
Hi,

In our application (e-motor with Inverter) we have a main script with a do loop in which all the calculations, alarm handling, shutdown procedure, speed control, etc are executed. I would like that every iteration of my main loop would be timed at around 10 ms. is there a way to achieve that?
I tried with

Code: Select all

wait 10
but if I calculate the frequency of every iteration (i.e. time difference between the previous iteration and the current one) and let it print in the "Ausgabe" window I always get some iteration which are longer:
0 time_diff 35
1 time_diff 15
2 time_diff 27
3 time_diff 12
4 time_diff 11
5 time_diff 14
6 time_diff 19
7 time_diff 12
8 time_diff 15
9 time_diff 25
10 time_diff 12
11 time_diff 11
12 time_diff 30
13 time_diff 16
14 time_diff 15
15 time_diff 15
16 time_diff 13
17 time_diff 11
18 time_diff 11
19 time_diff 25
20 time_diff 11
many thanks in advance.
MfG,
Frederick

Re: Timed Do Loop in VBS

Posted: Wed 12. Jul 2017, 08:28
by PEAK-Support
If you have a main loop, the time that this loop need, could changed depnding what you do in your code.
If you alsways do the same, it should be very stable (but still change from PC to PC).
But if you use If/then, or any other programming parts that could be vary, the timing will be never exact the same.

If you need a better timing, you could:
1) build own PCAN-Ecplorer AddIns in C++/C# etc. (build own threads with timers)
2) use our free Software API, using also C/C++/C+/VB.Net, Java etc.