LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

data acquisition from analog start trigger to analog stop trigger

Hi,

I'm trying to start and to stop a data aquisition by using an analog input trigger. I'm using NI-USB-6251. At input channel ai0 is a sin-signal connected. At input channel apfi0 is an analog trigger signal connected. I can start the trigger signal by pushing a button on my frequency generator. Here's a part of my code:

 

Hi,

ich versuche eine Messung mit einem analogen Eingangssignal zu starten und zu beenden. Ich benutze die Messkarte NI-USB-6251. An Eingang ai0 ist ein Sinus-Signal angeschlossen. An Eingang apfi0 ist der Triggereingang angeschlossen. Das Triggersignal löse ich immer per Tastendruck auf dem Funktionsgenerator aus. Hier ist ein Teil des Quellcodes:

 

TaskHandle		taskHandle			= 0;
int32				read;
float64			*data;
float64			sampleRate 		= 1000; //Samples per Channel per Second
uInt64			sampsPerChan		= 4000; //Samples per Channel to read
int				sumOfChan		= 1;

double			triggerLevel	        = 2.0;
double			min				= -0.2;
double			max				= 0.2;
double			timeOutReadAnalog	= 10.0;





void calculate()
{
		DAQmxCreateTask("", &taskHandle);
		
		DAQmxCreateAIVoltageChan(taskHandle, "/dev1/ai0", "", DAQmx_Val_Cfg_Default, min, max, DAQmx_Val_Volts, NULL);
		
DAQmxCfgSampClkTiming(taskHandle, "", sampleRate, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, sampsPerChan);
DAQmxCfgAnlgEdgeStartTrig (taskHandle, "/dev1/apfi0", DAQmx_Val_RisingSlope, triggerLevel);
DAQmxCfgAnlgEdgeRefTrig (taskHandle, "/dev1/apfi0", DAQmx_Val_RisingSlope, triggerLevel, 3000);
DAQmxStartTask(taskHandle); if( (data=malloc(sampsPerChan*sumOfChan*sizeof(float64)))==NULL ) { MessagePopup("Error","Not enough memory"); }
//set start and stop trigger //set breakpoint here
DAQmxReadAnalogF64 (taskHandle, -1, timeOutReadAnalog, DAQmx_Val_GroupByChannel, data, (sampsPerChan * sumOfChan), &read, NULL); }

 

I've choosen the sample rate (1000/s) and the samples per channel (4000), that the aquisition needs 4 seconds to be complete. I can start the aquisition by Start-Trigger, but I think I have a problem with the function DAQmxCfgAnlgEdgeRefTrig. Actually the array will always be filled with 4000 values. I thought I can start the aquisition by triggering once and e.g. after two seconds triggering again for stopping aquisition with result of 2000 values in the array. I hope you can help me with this problem.

 

Ich habe die Sample Rate (1000/s) und die Samples pro Kanal (4000) so gewählt, dass die Aufzeichnung 4 Sekunden dauert. Ich schaffe es auch die Aufzeichnung über den Trigger zu starten, jedoch funktioniert das Stoppen mit der Funktion DAQmxCfgAnlgEdgeRefTrig nicht. Aktuell ist es so, dass das Array immer mit 4000 Werten gefüllt wird.

Ich hatte mir erhofft, dass ich durch einmalige Triggerung die Messung starten kann und beispielsweise nach zwei Sekunden erneut triggere und die Messung damit stoppe und dann nur 2000 Werte eingelesen habe.

Ich hoffe, ihr könnt mir dabei helfen.

 

 

0 Kudos
Message 1 of 4
(3,249 Views)

Hi,

 

maybe this can help:

NI-DAQmx: Simultaneous AI/AO with External Digital Trigger in CVI

http://zone.ni.com/devzone/cda/epd/p/id/881

 

I know this is a digital trigger, but this is an example in cvi. Perhaps this can help you.

 

Regards,

Philipp

0 Kudos
Message 2 of 4
(3,218 Views)
Hi, thank you for the post! I've read this thread previous, but it doesn't solve my problem. On the one hand the program is working with continuously data aquisition and overwriting the first data in buffer. On the other hand the example program does not run stable on my system, sometimes I'm getting runtime errors, so I've given up to convert the given code to analog trigger. Regards, Martin
0 Kudos
Message 3 of 4
(3,211 Views)

Hi Martin,

 

I looked over your code and noticed that you called the function without checking the returnvalue.

 

Try to change the line to the following:

 

First: define a new int32 value and call it for example: errorcode

Second: The function returns a status code, wich if it fails, includes an error code so save this code in the new generated value

 

errorcode = DAQmxCfgAnlgEdgeRefTrig (taskHandle, "/dev1/apfi0", DAQmx_Val_RisingSlope, triggerLevel, 3000);

 

and try to run the programm and read out this value.
If you got this value, please post it here and I will try to help you if I can.

 

Regards

Philipp

0 Kudos
Message 4 of 4
(3,192 Views)