06-08-2012 01:30 PM
I am using NI 9401 as a digital output to control a switch in a simple circuit and using NI 9205 to measure the voltage across a diode in that circuit. The control signal of the swith is a square wave. So what I need to do is to get two values of the voltage across the diode: about 10us before the falling edge of the waveform and 200us after the falling edge. Then I need to use the two voltages to do some math,say, add the two values and plot the sum vs time. I am a starter of LabView and have no idea how to do that. Can anyone help me?
Solved! Go to Solution.
06-11-2012 03:07 PM
What you will need to do is setup a reference trigger (falling edge of the waveform) and then read pre and posttrigger samples, something similar to the following figure:
Then based on the sampling rate that you use to acquire your analog signal (i.e. voltage across the diode) you can exteact the 10us sample from pretriggered samples and 200us sample from posttriggered samples
Can you provide a bit more details on your hardware setup? Are NI 9401 and NI 9205 in the same cDAQ chassis? What is the model number of your cDAQ? You can generate your trigger with your NI 9401 (e.g. on DIO0 - pin 14) and then feed this sigal into PFI0 input (pins 28 or 36 depending on your module) of your NI 9205. Once you are done with wiring up your hardware you can use the examples in the following article to setup your post/pre triggered acquisition:
However, if you are just starting with LabVIEW I recommend that you read throught the following articles:
06-11-2012 08:43 PM
Thank you so much. I build a block diagram based on your answer and it's working.
However, there are still problems...
My NI 9401 and NI 9205 are in the same cDAQ chassis cDAQ-9174. I generate my switch signal with my NI 9401 (I use pin 19, with pin 14 I cannot change the duty ratio..I use the example in the software )and then feed this sigal into (pins 0) of my NI 9205.(I fail to use the digital output as a trigger source because i cannot find PFI0 as a source in the physical channel). I guess I am using "self triggering"?
The major problem is that the loop count speed is two slow. My switching frequency is 100Hz, but the loop count frequency is like 3Hz. I wonder whether there is a way to fix that.
See the attached the vi and I'd appreciate if you could help!
06-12-2012 11:04 AM
The reason your while loop is running slow is that on every interation, it reinitializes and restarts your acquisition. That's because your while loop surrounds your main code and all the DAQ VIs in it. I would remove the while from your code and if you want to continiously see your graph update you need to change your samples from Finite to Continious in Sample Clock VI. In addition, currently you are triggering off the analog edge of your input signal. To trigger off a digital line have a look at the following example in the Example Finder:
Help >> Find Examples >> Hardware input and output >> DAQmx -> Analog Measurements -> Voltage -> Acq&Graph Voltage -Int Clk-Dig Start.vi
In this example, you will need to change your Trigger VI to "Reference Digital Edge" and specify PFI0 as the trigger source.
Finally, you will need to export the counter task from your NI 9401 module to PFI0 line on your cDAQ that will be used for triggering. I have attached a quick example on how to accomplish this. Hope this helps.
The attached Code is provided As Is. It has not been tested or validated as a product, for use in a deployed application or system, or for use in hazardous environments. You assume all risks for use of the Code and use of the Code is subject to the Sample Code License Terms which can be found at: http://ni.com/samplecodelicense
06-12-2012 12:48 PM
Thank you for your reply, I'll try the digital triggering.
And I am wondering whether I could trigger the analog edge of my input signal ( the voltage across the diode) continuously. Because there is a delay between the control signal of the switch and the voltage across the diode. So when the digital signal triggers, my analog signal might reach the edge yet. It seems that I could not use reference trigger when I change your samples from Finite to Continious in Sample Clock VI. Is there a way to do that?
If not, I'll try the digital trigger.
Thank you so much!
06-12-2012 05:37 PM
So the voltage waveform is 100Hz, but the loop count speed is like only 3Hz which is too slow. I am surprised that the computer is that slow.. After all 100Hz is not that fast.
06-12-2012 06:40 PM
You are correct. You cannot do reference trigger in Continious mode. You have to use Finite mode sampling.
Now, here is what you need to do to make your setup work. Generate a pulse train on CTR0 on 9401, then feed this output (coming off from pin 19) to the analog input Ai1 and PFI0 lines on your 9205 module. Also make sure both modules are connected to the same ground.
Refer to wiring.png for more details. Once you are done with wiring have a look at setup.png and setup your code in a similar way, chaning the device names as necessary. Run your code and you should observe results similar to mine. In this example all I am doing is generating pulses on 9401 and then acquiring this signal on Analog Input 1 of my 9205 module. However, in addition to acquiring the signal after the first falling edge the analog input sees, I also take 4 pretriggered sample that occured before the falling edge was registered. Good luck!
06-12-2012 06:48 PM
If I cannot speed up the loop acount, I am thinking that I could abtain the data first(the continuous waveform of the voltage) and then find the falling edge of this waveform and the values before or after the edge. But how can I achieve that?
06-12-2012 08:42 PM
Thank you. Yes, the setup is OK and it works. But what I want to do is to acquire that data around every falling edge. I run the whole thing in one while-loop, the loop count frequency is around 2Hz. But my signal is at least 100Hz.I have been trying to do that for a whole day but I still cannot work it out. So I am wondering whether there is a way to do that.
SO...If I cannot speed up the loop acount, I am thinking that I could abtain the data first(the continuous waveform of the voltage) and then find the falling edge of this waveform and the values around the edge. But I am not sure how to achieve that.