01-13-2012 10:17 AM
Hello,
In my setup I use NI6602 card and the newest DAQmx driver for linux.
I would like to generate a single pulse on ctr0 using output of ctrl3 as a trigger. To do that I planned to create two tasks: main task which will generate a 1s pulse on ctrl0 and trigger task which generate 100ms trigger pulse on ctrl3. I tried following code, but it deosn't work:
#include <NIDAQmx.h>
#include <unistd.h>
int main()
{
//config of trigger task
TaskHandle triggerTask;
DAQmxCreateTask("TriggerTask",&triggerTask);
DAQmxSetReadAutoStart(triggerTask,FALSE);
DAQmxCreateCOPulseChanTicks(triggerTask, "Dev1/ctr3", "Channel_3", "80MHzTimebase", DAQmx_Val_Low, 0, 8000000, 8000000);
DAQmxCfgImplicitTiming(triggerTask,DAQmx_Val_FiniteSamps,1);
//config of main task
TaskHandle mainTask;
DAQmxCreateTask("MainTask",&mainTask);
DAQmxSetReadAutoStart(mainTask,FALSE);
DAQmxCreateCOPulseChanTicks(mainTask, "Dev1/ctr0", "Channel_0", "80MHzTimebase", DAQmx_Val_Low, 0, 2, 80000000);
DAQmxCfgImplicitTiming(mainTask, DAQmx_Val_FiniteSamps,1);
//config of trigger for main task
DAQmxSetStartTrigType(mainTask, DAQmx_Val_DigEdge);
DAQmxSetDigEdgeStartTrigSrc(mainTask, "Dev1/PFI38");
DAQmxSetDigEdgeStartTrigEdge(mainTask, DAQmx_Val_Rising);
DAQmxStartTask(mainTask);
DAQmxStartTask(triggerTask);
sleep(3);
DAQmxClearTask(mainTask);
DAQmxClearTask(triggerTask);
}
I do proper error handling, however I removed it here to make a code snippet shorter. There are no errors during program execution.
I suspect that I miss some trigger configuration on the mainTask, cause if I use only software trigger, both pulses (trigger and main) are generated correctly. I also tried with digital output as a signal for triggering, and it didn't work neither.
Thank you in advance for any hints.
Solved! Go to Solution.
01-14-2012 05:39 AM
01-14-2012 10:14 AM
what an ugly formatting...
Hello again,
I already solved my problem.
As I was suspecting I messed trigger configuration for main task. I was not checking errors in these 3 functions:
DAQmxSetStartTrigType(mainTask, DAQmx_Val_DigEdge);
DAQmxSetDigEdgeStartTrigSrc(mainTask, "Dev1/PFI38");
DAQmxSetDigEdgeStartTrigEdge(mainTask, DAQmx_Val_Rising);
When I did it, I realized that the second one, setting trigger source was giving following error:
DAQmx Error: Source terminal to be routed could not be found on the device.
Make sure the terminal name is valid for the specified device. Refer to Measurement & Automation Explorer for valid terminal names.
Property: DAQmx_DigEdge_StartTrig_Src
Property: DAQmx_DigEdge_StartTrig_Edge
Source Device: Dev1
Source Terminal: Dev1/PFI38
Task Name: MainTask
Status Code: -89120
And this error is due to wrong name, which should be "/Dev1/PFI" or "PFI" instead of "Dev1/PFI".
Silly and annoying error, however this happens for beginners.
Good luck in your projects!