Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Analog Pulse Trigger

All,

Given the code from the counter generate pulse, does anyone know how to trigger a voltage analog input collection using this pulse as the starting point?  The two hardware modules for the counter and voltage input are on the same chassis.  I want to queue the analog input and wait until the pulse is received.  Then, generate the pulse when I choose, through say a button click, which will start the voltage collection at the same time.  Needs to be through this pulse, as another device uses this pulse to start acquiring.  Currently I start both tasks back to back in the code as such:

DAQmxErrChk(DAQmxStartTask(taskHandle2));
DAQmxErrChk(DAQmxStartTask(taskHandle1));

were task2 is my pulse and task1 is my AIvoltage, but this is off by a certain number of milliseconds.

 

Any advice would be appreciated.  Thanks,

0 Kudos
Message 1 of 9
(4,656 Views)

Hi Did you check the examples that come with measurement studio or DAQmx ?

There is an example that is called Continuous Voltage Acquisition, internal clock and Analog Start

You could find does examples in the following path http://www.ni.com/example/6999/en/

Or you could modify the Acquire Voltage Samples - Internal Clock - Digital Reference Trigger or

Acquire Voltage Samples - Internal Clock - Digital Start and Reference Triggers examples

0 Kudos
Message 2 of 9
(4,611 Views)

I looked at those examples.  I set my analog in task to have a digital start trigger.  The main issue I am running into is that I either do not have the correct terminal marked or I cannot get it to fire.  I have a trigger module on the same chassis that I want to emit a single pulse through which will begin the collection.  In the NI application, I can go to my device analog input trigger menu and I can see a Dev2/PFI0 terminal, so I think that is the correct one, but I cannot get it to fire and record the signals

Mainly I am looking for a way to trigger the collection once a trigger has been set.  I usually just get a timed out error.  Here is my pseudocode:

 

 DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle1, "Dev1/ai0", "", DAQmx_Val_Cfg_Default, minVoltage, maxVoltage, DAQmx_Val_Volts, NULL));
DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandle1, "", 1000.0, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 1000.0));

DAQmxErrChk(DAQmxConfigureLogging(taskHandle1, "C:\\Data\\Example1.tdms", DAQmx_Val_Log, "Measurements", DAQmx_Val_OpenOrCreate));
DAQmxErrChk(DAQmxCfgDigEdgeStartTrig(taskHandle1, "/Dev2/PFI0", DAQmx_Val_Rising));

 

DAQmxErrChk(DAQmxCreateTask("", &taskHandle2));
DAQmxErrChk(DAQmxCreateCOPulseChanTime(taskHandle2, "Dev2/ctr0", "", DAQmx_Val_Seconds, DAQmx_Val_Low, 0, 0.50, 1.00));

 

DAQmxErrChk(DAQmxStartTask(taskHandle1));
DAQmxErrChk(DAQmxStartTask(taskHandle2));

 

0 Kudos
Message 3 of 9
(4,600 Views)

When you say that you are running into issues with either having the correct terminal marked or getting it to fire, are you having these issues with the example program or just your own program? I would make sure you're able to get the example to work (to make sure all your hardware is set up correctly) before moving on to creating your own code. What kind of hardware are you using and can you give us a bit more context on your application? 

Francine P.
Applications Engineering
National Instruments
0 Kudos
Message 4 of 9
(4,594 Views)

Sorry about that.  I should be a bit more specific.  I have an NI 9402 Trigger that I use to generate a single pulse.  This pulse is used to trigger the collection of data from another device and from a NI 9234 analog input device.  Both the trigger and the analog input device are on the same NI 9137 chassis.  

 

I can run all the example programs just fine, so I know that is not my issue.  

 

Essentially, I wanted to generate a pulse on the 9402 device, which would then trigger the 9234 device.  I was able to get this working, but not exactly how I wanted it to.  On the 9402 device, I hooked a cable up from one channel on another.  Then, I told the 9234 to wait for the input pulse from the second channel.  The pulse emits on the first channel, which then travels to the second, thus triggering the 9234.  This works fine.  Was hoping to do this all from the single channel or initialize two counter pulses at the same time, but it works.  Below is a portion of my code.  If anyone has any further suggestions on this, let me know.  Thanks

 

DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle1, "Dev1/ai0", "", DAQmx_Val_Cfg_Default, minVoltage, maxVoltage, DAQmx_Val_Volts, NULL));
DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandle1, "", 1000.0, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 1000.0));

DAQmxErrChk(DAQmxConfigureLogging(taskHandle1, "C:\\Data\\Example1.tdms", DAQmx_Val_Log, "Measurements", DAQmx_Val_OpenOrCreate));
DAQmxErrChk(DAQmxCfgDigEdgeStartTrig(taskHandle1, "/Dev2/PFI1", DAQmx_Val_Rising));

 

DAQmxErrChk(DAQmxCreateTask("", &taskHandle2));
DAQmxErrChk(DAQmxCreateCOPulseChanTime(taskHandle2, "Dev2/ctr0", "", DAQmx_Val_Seconds, DAQmx_Val_Low, 0, 0.50, 1.00));

 

DAQmxErrChk(DAQmxStartTask(taskHandle1));
DAQmxErrChk(DAQmxStartTask(taskHandle2));

 

0 Kudos
Message 5 of 9
(4,568 Views)

So right now on the 9402 you have two channels wired together. You output a pulse from one channel and then input this pulse into another channel on the 9402. When this channel receives the pulse, you use it as the trigger to start acquiring data on the 9234. Is that all correct? And you have that working but you only want to use a single 9402 channel to to trigger the acquisition for the 9234? 

 

In your code below, is Dev1 the 9234 and you will begin acquiring data on AI0 as soon as it receives the trigger? And then Dev2 is the 9402 and PFI1 is waiting for the trigger input from PFI0?

 

 

Adena L.
Technical Support Engineer
National Instruments
0 Kudos
Message 6 of 9
(4,535 Views)

That is correct.  I do have this working, but I am running into an issue with the input delay on the NI 9234.  There is about a 30ms delay from the time it takes to read the first sample to the time of the rising edge from the digital pulse.  Trying to find a work around for this.  Something along the lines of a reference trigger to start taking pre-samples before the start trigger is generated. 

0 Kudos
Message 7 of 9
(4,531 Views)

Have you taken a look at this white paper? The example code is all in LabVIEW but the names of the functions map very easily to our DAQmx API in Measurement Studio. 

 

NI-DAQmx Data Acquisition Triggering Techniques Using LabVIEW
http://www.ni.com/tutorial/4329/en/

Adena L.
Technical Support Engineer
National Instruments
0 Kudos
Message 8 of 9
(4,522 Views)

I did not find the exact solution for this problem, but my sensor is delayed by a certain number of samples (x).  I recorded x more samples that desired and subtracted off the first x samples from my total amount.  In this way, I got the full amount of samples starting very near to the starting point of my trigger.  Not a perfect fix, but close enough to what I was try to achieve.

0 Kudos
Message 9 of 9
(3,981 Views)