From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I promptly and reliably generate an output signal upon fulfilling 2 software conditions?

I am acquiring a signal frequency approximately 1 to 2 Hz (waveform attached).  My goal is to create an output signal when 2 conditions are satisfied:

1) analog input signal crosses zero and 2) the integral under the negative part of the waveform is larger than a certain value. 

The output signal can be analog, digital or counter pulse, but it has to happen within 10 to 30 ms upon finding a trigger threshold value.

 

So far I was just trying to generate the output signal upon finding a threshold (on a sinus waveform from the signal generator), but I was not successful doing this in a reliable and fast enough manor.   I attached the latest LabVIEW code I wrote.  My sampling frequency was 1000 samples/sec, although I played with higher and lower rates, samples per channel, counter out frequency etc.

 

I am using a NI-USB-6251 mass termination board with the SCC-2345 signal conditioner.

 

I also tried hardware triggering and it works well for the sinusoidal waveform, but for the real signal I need to continuously monitor both conditions before creating the output control.

 

I would really appreciate any input. 

Download All
0 Kudos
Message 1 of 17
(3,267 Views)

I apologize; the LabVIEW code is attached now.

Again, any aid or ideas would be greatly appreciated,

 b777

0 Kudos
Message 2 of 17
(3,259 Views)
hello,
after looking at your code first came some questions into my mind:
1. Why do you use analog read with NChan, since you only need (and specify) one channel at Create Task?
2. Your while loop has a wait timeout of 1000ms, this means, it will not respond faster than 1 second.
3. You specify to read a fixed amount of samples, which means the VI must wait for that amount of data (no problem in your application), but if more data comes in, it will remain in the DAQmx- buffer and you only can read it with the next loop. This is the reason, your VI is not fast enough to react. The solution is, to wire a -1 (default) to the amount input to read all available data.

The following is just a sketch, how I would go to solve the problem. The steps are:
1. Read in one sample to initialize the waveform- shift register with the right timestamp.
2. Read all available samples and append them to the already collected waveform.
3. Find the first trigger condition.
4. If first trigger condition is detected, remove all preceeding samples. Set Flag to start integration of remaining (and additionally incoming) data.
5. Integrate and test, if integral condition is fulfilled. If so, set flag to search for final trigger condition.
6. Find final trigger condition.




This is only a quick draft, I didn't test it and there are some things to do, like setting the initial and final condition at "integral x(t).vi".
I attach the modified VI and a picture of the modified part since I cannot save the VI in 7.1 version.
greets, Dave

Message Edited by daveTW on 07-04-2007 11:37 AM

Greets, Dave
Download All
Message 3 of 17
(3,246 Views)

Hi Dave,

 

I do not have a greatest understanding of what is going on “behind the scenes”, I mean how the data are flowing through the buffer etc.  The task I was trying to solve was much beyond my LabVIEW “expertise” that I acquired by reading through the NI website, various help manuals, examples, a little bit of NI phone support, etc.

  

Actually, this is much more than what I was hoping for… thank you so much for your very elegant and detailed solution… I appreciate it a lot…

 

I wanted to ask you a few more questions though…

1) I could not open your program since I have 7.1 version… the first read API goes immediately after the start icon and later on the program always read all available samples – is that correct?

2) Is there a need to assign any value to a wait timeout? 

3)  Would you still use the counter output (set the time to implicit, finite but 1 sample?), to generate a control output?

 

4) Can LabVIEW 7.1 and 8 both be installed at the same time?  I have a LabVIEW version that I can install, but I am a little worry about the learning curve at this moment…

 

Thanks again for all your help,

Branka

0 Kudos
Message 4 of 17
(3,222 Views)
Hi Branka,
to answer your questions:


1) I could not open your program since I have 7.1 version… the first read API goes immediately after the start icon and later on the program always read all available samples – is that correct?



Yes, you are right, right before the first read there should be the start VI. The first sample before the while loop is needed to get an applicable timestamp for the waveform, since the "append waveforms" VI keeps the timestamp of the [waveform A]- input and ignores that of [waveform B]. If you wire an empty waveform constant to the shift register, this causes trouble. The other advance is that the While loop is entered when the first samples after start come in, so it is easy to handle timeout issues.
And with every loop there are always all available samples read, this empties the buffer of your DAQ device. You have to imagine this as a ring buffer or a pipeline, if you don't take elements from the opposite side, it overflows which causes an error.


2) Is there a need to assign any value to a wait timeout?




Yes, it's my mistake, I forgot it. Since you need an answering time of 10 to 30ms, I would advise less than 10 ms timeout. And what I mean is the "wait (ms)" VI from the timing palette.


3)  Would you still use the counter output (set the time to implicit, finite but 1 sample?), to generate a control output?




If this works, why not. I don't have experience with this. Easiest way could be to write just to a digital portpin output, like shown in the example "write dig chan.vi" (search with example finder from the HELP menu). You can use the "Digital Bool 1Line 1Point"- version of "DAQmx Write".
OK, and to the last question I can say YES, on another computer I installed LV 6.1, 7.1.1, 8.0 and 8.2 and they all work. But I didn't dive into the parallel use of all the DAQ and MAX things.

Hope, this helps,
greets, Dave
Greets, Dave
Message 5 of 17
(3,205 Views)

Dave, I greatly appreciate your help.  I was immersed in another project for a while, and then unsuccessfully was trying to understand the problem I am facing when testing the program.  I read a bunch of literature, especially about buffering issues, and that only opened more questions for me.  I will try to explain the problem and, as always, any help would be greatly appreciated.

 

I am acquiring a sinusoidal waveform approximately 1V amplitude, 1Hz frequency.

The triggers and integration work fine, but instead of 1 sample going out as I specified (in the timing counter output API) many of them are generated.  That slows down acquisition and instead of 1 to 20 available samples per channel, there is 40 or so.  (I set the "wait (ms)" VI value to 5 but even if it is higher, the same thing happens). 

 

I tried changing a counter output into a digital output ("Digital Bool 1Line 1Point") as you suggested (it took me a while to figure out how to connect the digital output with the SC-2345), however, I am not generating any signal.

I then try to only generate one digital output signal with the modified "write dig chan.vi" (attached) and the signal appears on the oscilloscope - which probably means the connections are fine - but it happens in a strange manner:  the first time I run the program, the signal is generated, the second time is not.  It can only be generated again (negative output) once the input is false. Further on, if you alter the true and the false, the signal is generated, if you repeat the same input – nothing happens?????

 

I am attaching both versions of the program – with the counter pulse and digital output,

I hope you could point the solution on either of them.  From my limited perspective, it seems more logical, that the program would run faster if it only needs to write one digital output while samples are read.

 

It seems though that the output would be able to respond between 20 to 30 ms, which would be good if it does for every beat.

 

Please help.

 

Branka

0 Kudos
Message 6 of 17
(3,142 Views)
It seems the attachments did not go...
0 Kudos
Message 7 of 17
(3,141 Views)
Hi b777,

Thank you for posting on the National Instruments forums.

It is not our policy to debug customer code, but I will try and take a look and see if I can give you any suggestions.  If that is not possible, then I can at least tell you how things should behave.

I’m not sure that I understand what you are trying to accomplish.  I understand that you have two conditions that must be met before you want an output signal to be created and the output signal must be generated within 20 to 30 ms of the conditions being met.  What I don’t understand is what kind of signal you want to generate.  Do you want a rising edge or a sine or square wave at a certain frequency, or just a voltage level.  Since you say that it can be either analog, digital or counter, I’m confused.  The only things that I can think of that are similar between the three is either a square wave, a rising or falling edge or a voltage level.  If you can elaborate on this part, it will be easier to figure out the best way to get your application going.

Thank You,

Nick F.
Applications Engineer
0 Kudos
Message 8 of 17
(3,117 Views)

Nick,

 

Thank you very much for your reply. 

 

Let’s forget about the code.  What I would like to accomplish is to generate a voltage level upon finding a trigger on an analog pressure waveform signal.  Since besides finding a threshold analog trigger level I need to process some data, and then generate an output signal, I can not use the hardware triggering.

 

I was thinking that the easiest way to solve this is to send a counter output pulse upon finding a final software trigger, however despite specifying only one pulse to be generated, several of them are generated; that slows down the reading process (available samples per channel in a buffer increases), and make the timing of the generated pulse relatively random with respect to the trigger level.

 

I am following the “generate the pulse programming flowchart” to generate the output signal, and I don’t understand why instead of one many of them are generated.

 

Besides that the program works perfectly fine, so if you can help me understand how to generate one pulse upon a final trigger that’ll be all I need.

 

Thank you so much,

Branka

0 Kudos
Message 9 of 17
(3,102 Views)
Hi b777,


Try looking at Gen Dig Pulse.vi in the example finder.  You can find it in the directory under Hardware Input and Output >> DAQmx >> Generating Digital Pulses >> Gen Dig Pulse.vi.  You can run this code when need the output signal.  Hopefully this will work for you.

Thank You,

Nick F.
Applications Engineer
0 Kudos
Message 10 of 17
(3,081 Views)