08-19-2020 05:47 AM
Hello everyone,
I still have a lot of questions, since I'm fairly new to LabView.
So my main goal is to generate a pulse, once a certain level from an analog input is reached. Yes I was able to accomplish that.
I'm doing that with a NI PCIe-6353 with a BNC-2120.
In general I'll list my main steps:
1. Acquiring data through analog inputs ai0-ai2
2. Saving that data into a txt file
3. While the program is saving that data, it's checking the Y value of the ai0 input.
4. If that value goes below a specified value, it is supposed to start a pulse
5. Which I am generating through an analog output ao0, and a pulse pattern generator.
The read, write and compare with the if-structure functions are all inside a while loop. As well as the saving.
So far I am able to control the pulse pattern, like width, amplitude and such.
But my pulse is not starting or stopping with the if-structure. It's running continuously, if that value is reached. Even if I try to put a stop-function into the false-case.
My only problem so far is to start and stop the generated pulses.
In the image shown there is the data I want to capture, the blue graph, and the pulse I want to generate, which I'm capturing in the third graph right now to control what it is doing. So let's say my value reaches the horizontal red line at 1.75, which now is my If-value and is returned true. I would love for the pulse to be where the vertical red line is. And that at every time, the Y value reaches 1.75.
But I can't stop the pulse generation nor align the pulses where I would like them to have.
Any help would be much appreciated, because I wasn't able to find anything so far.
And if I have to rewrite my program, so be it, but please someone help?
Best regards
A desperate researcher
Solved! Go to Solution.
08-19-2020 06:06 AM - edited 08-19-2020 06:08 AM
Hi Phim,
first you should cleanup the VI:
Then several suggestions:
08-19-2020 07:12 AM
Hi GerdW,
First off: Thank you very much!
To your suggestions:
1. That is not what I had in mind no. I would want to read the changing Y-value, so the Y-value at that exact ms. But how can I only read that value? And how can I compare that value to the minimum then? Change the minimum manually?
2. I also tried to stop it, which didn't help to be honest. But that might also be because of point 3. How do I set the value back to 0, once it is not lower than my specified value? Or should I use the stop function, like you proposed?
3. I usually read with 500 S/s and 500 samples. The VI doesn't save those values (500/500), but I always change them beforehand. Now if I change the values to 1000S/s and 100, the program crashes and states: "The application is not able to keep up with the hardware acquisition." What would be the optimal way to read the samples? I have to read the samples in a 100ms frame, as shown in the image above. That data later on will be used to measure changes in samples when that pulse is applied.
4. Did that now.
I also cleaned the VI. But I kept the three boxes for Analog Inputs.
Again, thank you for your quick reply! Very much appreciated!
Best regards Phim
08-19-2020 08:35 AM
Hi Phim,
@PhimVe wrote:
1. That is not what I had in mind no. I would want to read the changing Y-value, so the Y-value at that exact ms. But how can I only read that value? And how can I compare that value to the minimum then? Change the minimum manually?
2. I also tried to stop it, which didn't help to be honest. But that might also be because of point 3. How do I set the value back to 0, once it is not lower than my specified value? Or should I use the stop function, like you proposed?
3. I usually read with 500 S/s and 500 samples. The VI doesn't save those values (500/500), but I always change them beforehand. Now if I change the values to 1000S/s and 100, the program crashes and states: "The application is not able to keep up with the hardware acquisition." What would be the optimal way to read the samples? I have to read the samples in a 100ms frame, as shown in the image above. That data later on will be used to measure changes in samples when that pulse is applied.
I also cleaned the VI. But I kept the three boxes for Analog Inputs.
1. You need to handle all samples, not just one of 100 or 500: use GetWfmComponents to read all samples…
2. Create the pulse signal inside the loop. Now you can decide upon the amplitude dynamically…
3. To save values permanently you need to set them as default value. You can do so either in the Edit menu or by right-clicking the control. Btw. the VI doesn't crash, it just gives an error because it run too slow.
You only need CreateVirtualChannel once as you can define more than one channel with the DAQmxChannel control!
It's nice you also cleaned up the VI, but please always attach the latest version when you change things…
08-20-2020 03:50 AM
Again thank you!
1. Thanks, yes that seems to work.
2. But I won't be able to do that in 100ms hold time. I'm not able to press 0 and -1 that fast. Or did I just not understand you correctly? Right now I build in the stop function into the false case of the if structure. That should work?
3. Thank you! I set some of them as default. Is there any way to increase the rate or speed of the program? Because even @500Hz and 50 samples I get the error. And it seems it's important for the pulse generation that the program runs at a higher rate.
Now I only have one of those CreateVirtualChannel
And sorry that I forgot to do that! Now with the VI.
08-20-2020 06:10 AM
Hi GerdW,
So I looked into my data during a measurement and e.g. if my minimum is around 1.65V the pulse never appears below 1.8V... Most of the time the generated pulse is somewhere around 1.8 or 2V. Could it be, that the delay of the generated pulse is too big? If so, is there a way to increase the speed of the program?
Best regards
Phim
08-20-2020 06:34 AM - edited 08-20-2020 06:34 AM
Hi Phim,
@PhimVe wrote:
2. But I won't be able to do that in 100ms hold time. I'm not able to press 0 and -1 that fast. Or did I just not understand you correctly? Right now I build in the stop function into the false case of the if structure. That should work?
Based on the comparison your VI can decide on the amplitude automatically, no need to press any button this fast…
@PhimVe wrote:
3. Thank you! I set some of them as default. Is there any way to increase the rate or speed of the program? Because even @500Hz and 50 samples I get the error. And it seems it's important for the pulse generation that the program runs at a higher rate.
First test would be without the FileSave operation as (most often) this is the slowest part in a program like yours.
Does your VI also give this error when the loop only contains the DAQmx functions?
On your comparison: Now you compare the whole waveform for your limit, but you still only use the very first sample because of this IndexArray function!
When you want to check the whole waveform then you need to evaluate all samples! Ever heard of AND-Array or OR-Array operations?
08-20-2020 07:14 AM
Hi GerdW,
As you proposed I deleted the FileSave operation. Unfortunately I still get the same error.
I changed the array to an And-Array operation. But since the graph moves to fast and I have no data to compare it, I'm not entirely sure, if the pulse is correct.
And thank you for being so patient with me...
Best regards
08-21-2020 07:35 AM
So I figured out something myself. One issue of course was the data acquisition as a txt file. That slowed down the program quite a bit. I wrote a program just to read channels, which is running just fine @100kHz and 10k samples without the txt. If I save the data into tdms, I also have no problem acquiring that much data. (See Read channels.vi)
So I deleted the save into txt function in the other program again, and the biggest issue seems to be the If-case structure and pulse generation!
I rewired the program so that now I only get an indicator showing if the comparison is doing what I would like to do and that the pulse is continuously generated.
So if I set the samples per channel and pulse sampling rate above 10, the program crashes. But at least the indicator for my comparison works correctly... So thank you for your help in that case GerdW!
Now I have two further questions:
1. Is there any other way to generate a pulse through analog outputs and control amplitude and frequency and width and such? Or through labview itself? I tried to find solutions which would work, but none of them worked for me.
2. Is there a way to make the if-case faster? Or compare the results faster? I read about the trigger function, but I wasn't able to wire it correctly and make it work in my VI... or should my comparison be fast enough but it's mostly the pulse generation?
If anyone would be so kind as to help me, that would be really much appreciated!
Best regards
Phim
08-21-2020 07:51 AM
Also, I fixed and cleaned the read channels VI a bit. To keep it simple for now.
Otherwise this one works. My biggest issues are still stated above.
Thanks for anyone helping me!