02-28-2013 10:29 AM
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.
03-05-2013 04:00 AM
Hi,
maybe this can help:
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
03-05-2013 10:00 AM
03-08-2013 07:25 AM
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