LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Real time - Change time loop phase on the fly

Hi,

 

I have an application on a real time cRIO that uses a timed loop to time data acquisition. This timed loop uses the 1kHz absolute time clock.

 

I would like to modify, on the fly, the phase of the loop.

 

For instance, let's say my timed loop has started at 15h00m05,000s and is running every 25ms. Now, while the loop is running, I want it to be re-phased the loop and have its next iteration starting at, let's says 15h06m07,333s and then still run every 25ms.

 

How could I do that? I thought i could just use the right terminal of the timed loop and enter a new offset but apparently, offset can only be set for the first iteration!

 

Thanks in advance,

 

Regards,

 

peper2001

 

 

0 Kudos
Message 1 of 7
(3,041 Views)

Hi peper2001,

 

Re-phasing and dynamically setting the offset can be done. You have also been on the right track by looking to do it with the right data node in the timed loop. What you might have missed though, is that if you want to dynamically set the offset, you also have to set the mode in the right data node while you are at it. To set the mode, right-click the Mode input terminal of the Right Data Node and select Create»Constant or Create»Control from the shortcut menu to create an enumerated constant or control you can use to select a mode.

 

Please let me know if this solved your problem!

 

Best Regards,

Rasmus Pettersson

Application Engineer | National Instruments

 

0 Kudos
Message 2 of 7
(2,886 Views)

Hi,

 

Thanks for your answer.

 

I ended up encapsulating the timed loop in a regular while loop and, whenever I need to rephase the timed loop, I stop it and restart it with a new phase:

Labview - rephasing.png

 

If I understand you correctly what I could have done it set a new phase and, at the same time a new mode (the way the timed loop behaves when it runs late) using the right node. Here is what I tried:

 

Labview - rephasing 2.png

 

This does a good to set the new phase however, the way the loop behaves when it finishes late is also modified. Here I want the loop to discard the missed loop and keep the phase but it can't use this mode anymore:

- If I set the mode of the loop to "maintain original phase", the loop ignores the new, dynamically modified, phase and go back to the original phase (the one the loop had when it started for the first time). 

 If I set the mode of the loop to "ignore original phase", the loop uses the new phase but if it runs late the phase is modified.

 

Am I missing something?

 

Best regards,

 

peper

0 Kudos
Message 3 of 7
(2,847 Views)

Hi Peper,

 

Perhaps you could try to explain it a bit more comprehesively.

 

How is the phase modified if the loop runs late?

 

If I undestood correctly, if the loop runs late, you want to discard this period. Does this not happen? Or does the loop resume original phase if the loop runs late?

 

Best regards,

Rasmus Pettersson

Application Engineer | national Instruments

0 Kudos
Message 4 of 7
(2,816 Views)

Hi,

 

To be clear, let's call:

- the "original" phase of the timed loop: the phase the loop has the very first time it is started. It is the phase set with the outer left node of the loop.

- the "new" phase of the timed loop: the phase that is set, on the fly, after the loop started. So it is the phase set with the inner right node of the loop.

 

Whenever a new phase is set, I want to loop to stick to that new phase even if it runs late and discard the missing periods.

 

For example, let's say the original phase is 19h30m03,100s.The loop runs at 10Hz and hence the start time of each iterations are:

19h30m03,100

19h30m03,200

19h30m03,300

...

 

If for some reasons the thrid iteration runs late, the actual iterations start time will be:

19h30m03,100

19h30m03,200

19h30m03,300

19h30m03,500

...

as expected.

 

Now I want to set a new phase wich is 19h30m03,725s. I use the inner right node to set this new phase and use the mode "discard missing period, ignore original phase". The new phase is correctly set and the actual start times of the iterations are:

19h30m03,725s

19h30m03,825s

...

 

If for some reasons the iterations starting at 19h30m03,825s runs late and takes 123ms instead of 100ms, I would like my start times to be:

19h30m03,725s

19h30m03,825s

19h30m04,025s

19h30m04,125s

...

 

but my actual iteration start times are:

19h30m03,725s

19h30m03,825s

19h30m03,948s

19h30m04,048s

...

 

So i've lost my phase sync! Which is logical because I have instructed the loop to ignore the phase information when it runs late.

 

I thought that switching back the mode to "maintain original phase" with the right inner node would do the trick but Labview seems to interpret "original phase" exactly as defined at the beginning of this post i.e. as the phase the loop had the first time it started.  Hence, if a use this mode, the new phase is ignored. 

 

I hope that makes it clearer.

 

Best regards,

 

peper

 

0 Kudos
Message 5 of 7
(2,811 Views)

Hi Peper,

 

I'm sorry it took me a while to answer you back, but I wanted to make my own example program (based on your design, with a few modifications) just to be 100% sure that my information is correct. You are right! Setting the mode for "Ignore original phase" will set the loop out of sync indeed!

 

However...

 

The mode setting "Discard missed periods, maintain original phase" should have exactly the functionality you are looking for. It doesn't go back to the "original" phase, but should keep using the "new" phase instead.

 

Take a look at the this VI and the corresponding results. The VI always changes phase on the 3rd iteration of the loop. Then it runs 2 iterations with the new phase, after which a loop is missed because it runs late. From there on, it runs normally with the "new" phase. I will attach it so you can freely edit it and compare it to your own program (it should run on a cRIO target).

 

Capture3.JPG


And the results:

Capture2.JPG

 

What I suspect is happening in your VI is this:

Capture.JPG

When the button is pushed to set the "new phase" it will run the phase for one iteration, after which the buttons value returns to false. After this, the select node selects the "original" phase again for the following iterations.

 

I hope this post gives some insight!

 

Best regards,

Rasmus Pettersson

Application Engineer | National Instruments

Message 6 of 7
(2,798 Views)

 

I think the behavior of the right inner node is to take the new offset into account only if the mode is different than "no change" (as explained in the Labview help by the way).

 

My mistake was that I set the mode to "discard missed periods, ignore original phase", if I set  to "maintain original phase" it works as expected. And hence "original phase" must be interpreted as the phase of the loop the last time the mode was different than "no change".

 

In summary, this works:):Labview Rephase 3.png

 

Thanks for your help,

 

Best regards,

 

peper

 

0 Kudos
Message 7 of 7
(2,794 Views)