Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Overwrite buffer without stopping task

Hello,

 

I am using a PCI-6120 to generate 2 AO signals (with Labview). Both AO are in the same single task in the Labview diagram.

My data are in a buffer containing one period of each signal. They are being regenerated permanentely, except in one condition. There is a switch on the front panel that enables the user to choose whether or not to generate one of the two signals. The other signal is still generated. Let's say signal S1 is always generated, and signal S2 depends on the switch state.

 

So basically I have the next two cases:

 

Switch is ON: 2 waveforms generated

Switch is OFF: 1 waveform is generated (the other channel is set to 0Volt)

 

For that I have a problem:

 

When the switch is set to OFF, I don't simply want to stop the generation of S2. I also want to set the value to 0Volt. So I have to change the values in the buffer. The solution I have for now is to overwrite the buffer with a new signal for S2 containing only zeros. More precisely, I overwrite the buffer with the two signals S1 and S2, except that only S2 has changed... But! To do so, I apparently need to stop the task before writting data in the buffer, and then start the task again. The problem is that by doing so, the generation of S1 is aborted when I stop the task, and starts again from the beginning when I start the task. Thus there is a part of the current period of S1 that will never be generated.

Could it be possible to modify the buffer without stopping the generation? Let's say, when sample N is being generated, I overwrite sample N-1, so that the old buffer is being generated completely before the new buffer starts to be generated.

 

In a similar way, when the switch is turned back ON, I would like S1 to be generated completely before generating S2 again. The two signals S1 and S2 have to be synchronized so I cannot just start S2 generation without knowing in which state S1 is. Moreover, I cannot just abort the generation of S1 because it is sending a command signal to a fairly sensitive device. I need the whole period of S1 (written in the buffer) to be generated before adding S2 again. I cannot just abort the generation of S1.

 

I hope I was clear enough...

 

To sum up: can I overwrite a buffer without stopping a "regenerating" task?

If yes, how?

If no, do you have any other suggestion?

 

Thanks in advance.

 

Regards.

Luc

0 Kudos
Message 1 of 6
(3,587 Views)

Up!

Does anybody have a suggestion please...?

0 Kudos
Message 2 of 6
(3,550 Views)

Hi LucG,

 

Could you send us your code, it will be easier to work on it and to give you some answers 😉

 

Thanks a lot !

 

Regards,

0 Kudos
Message 3 of 6
(3,547 Views)

Trying to write to a task which is regenerating from the buffer presents a race condition in that hardware might be reading from the same spot that you are writing to.  There isn't really any guarantee of phase continuity or that you will not get a mix of old and new samples.  I'd suggest not trying to write to the buffer as you are regenerating from it (although it should be technically possible).

 

Could you instead use a non-regenerating task instead?  That way, each sample you write is only generated once so you know exactly what will be output.  The downside is that this requires you to constantly be writing new samples to the buffer and you will need to manage the synchronization yourself in software.

 

OR... perhaps this would be easier to do with an external switch.  Have the switch connect 0V to the output when your signal is false, and connect S2 when your signal is true.  S2 would always be in phase with S1 since it is continuously running.  If you want S2 to not start until a complete period of S1 has finished (for reasons other than keeping the same phase) then this becomes a good deal trickier.

 

 

Best Regards,

John Passiak
0 Kudos
Message 4 of 6
(3,523 Views)

Hi all!

 

Thank you for your answers.

 

@ Antonin_G: My diagram is fairly big. I'll see if I can simplify it a bit before posting it.

 

@ John_P1: I cannot use a non-regenerating task (or I would prefere not to) for two reasons: firstly, I am generating data at a fairly high frequency (1Mech/s), and secondly, the computer is used for image acquisition at the same time. So if I could stay on a regenerating configuration, that would ensure that the patern is generated correctly on S1 and S2, while the computer is fully dedicated to image acquisition.

The idea of using an external switch is not that bad... I see how that deals with generating either a 0V signal, or the S2 signal. But with that switch you cannot control the fact that S2 starts being generated only at the end of a period of S1. S2 just starts when you touch the switch. Whatever the state of S1 is! Or am I missing something...?

 

 

Here is another way we could (maybe) deal with my question:

starting from a regenerating task (actually running!), is it possible to control the way the task stops so that the last sample being generated is the last sample in the buffer?

I mean, when I ask the task to stop, it shall not stop right away. It just stops when reaching the end of the buffer, without regenerating it again and again. Keep in mind that the task is already running in a regenerating mode...

 

Thanks in advance.

 

Best Regards.

Luc

0 Kudos
Message 5 of 6
(3,440 Views)

Looking here and there on the forum made me find that:

 

https://decibel.ni.com/content/docs/DOC-13072

 

I'll try it and let you know. That should do it! 😉

 

Luc

0 Kudos
Message 6 of 6
(3,435 Views)