LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

about digital-edge triggering and buffer pointer reset

Hi all,

  I am learning how to use the digital edge to trigger the task for analog output. I copy some code from the NI example and have the code written as follow

 

  double data[102000];
  int datasize = 102000;

  // data is built here, the first 100000 elements are non-zero, the last 2000 elements are all zeros
  // my_task was setup elsewhere and bind to dev1/ao0
  DAQmxCfgSampClkTiming(my_task, NULL, 100000, DAQmx_Val_Falling, DAQmx_Val_FiniteSamps, datasize);
  DAQmxWriteAnalogF64(my_task,datasize,0,10,DAQmx_Val_GroupByChannel,data,NULL,NULL);
  DAQmxStartTask(my_task);
  Sleep(50);
  DAQmxStopTask(my_task);
  DAQmxSetWriteAttribute(my_task, DAQmx_Write_RelativeTo, DAQmx_Val_FirstSample);
  DAQmxSetWriteAttribute(my_task, DAQmx_Write_Offset, 101050);
  DAQmxCfgDigEdgeStartTrig(my_task, "Dev1/port0/line0", DAQmx_Val_Rising);
  DAQmxStartTask(my_task);
  DAQmxWaitUntilTaskDone(my_task, -1);
  DAQmxClearTask(my_task);

 My code implements something like this: first build an array of total 102000 elements. The first 100000 elements are all non-zero voltages and the last 2000 elements are all zeros. Since I set the sample rate to be 100000 per second, the first 100000 elements will last about 1 second. I start the task and wait 50ms so the some non-zero voltage will be output (I can see that from the scope). After 50ms, I stop the task. Then reset the pointer of the ouput buffer to be 101050 (so the next output sample will be zero). But instead of directly start the task to output the rest "zeros", I would like to use a digital edge to trigger the task start.

 

But I find the code doesn't work as I expect. What I observed is it output the some non-zero voltages first, after 50ms, the task stop, the scope maintains at the last output value. But after redirect the buffer pointer and start the task, it doesn't wait for my digital trigger; it instead return immediately. Would you please help to point out what's wrong with my code and how to fix it to implement my goal? Thanks

 

p.s. the trigger "Dev1/port0/line0" is set in a separate program.

0 Kudos
Message 1 of 6
(4,014 Views)

@PKIM wrote:

Hi all,

  I am learning how to use the digital edge to trigger the task for analog output. I copy some code from the NI example and have the code written as follow

 

  double data[102000];
  int datasize = 102000;

  // data is built here, the first 100000 elements are non-zero, the last 2000 elements are all zeros
  // my_task was setup elsewhere and bind to dev1/ao0
  DAQmxCfgSampClkTiming(my_task, NULL, 100000, DAQmx_Val_Falling, DAQmx_Val_FiniteSamps, datasize);
  DAQmxWriteAnalogF64(my_task,datasize,0,10,DAQmx_Val_GroupByChannel,data,NULL,NULL);
  DAQmxStartTask(my_task);
  Sleep(50);
  DAQmxStopTask(my_task);
  DAQmxSetWriteAttribute(my_task, DAQmx_Write_RelativeTo, DAQmx_Val_FirstSample);
  DAQmxSetWriteAttribute(my_task, DAQmx_Write_Offset, 101050);
  DAQmxCfgDigEdgeStartTrig(my_task, "Dev1/port0/line0", DAQmx_Val_Rising);
  DAQmxStartTask(my_task);
  DAQmxWaitUntilTaskDone(my_task, -1);
  DAQmxClearTask(my_task);

 My code implements something like this: first build an array of total 102000 elements. The first 100000 elements are all non-zero voltages and the last 2000 elements are all zeros. Since I set the sample rate to be 100000 per second, the first 100000 elements will last about 1 second. I start the task and wait 50ms so the some non-zero voltage will be output (I can see that from the scope). After 50ms, I stop the task. Then reset the pointer of the ouput buffer to be 101050 (so the next output sample will be zero). But instead of directly start the task to output the rest "zeros", I would like to use a digital edge to trigger the task start.

 

But I find the code doesn't work as I expect. What I observed is it output the some non-zero voltages first, after 50ms, the task stop, the scope maintains at the last output value. But after redirect the buffer pointer and start the task, it doesn't wait for my digital trigger; it instead return immediately. Would you please help to point out what's wrong with my code and how to fix it to implement my goal? Thanks

 

p.s. the trigger "Dev1/port0/line0" is set in a separate program.


I wonder if the issue is caused by my specifying an digital line "Dev1/port0/line0" as trigger source is not supported by DAQmx? It will be quite difficult for my since all ports and pins for the PCI card are placed in a sealed box and I cannot connect the digital line to PFI. Is that any other way to use a line to trigger the AO output?

0 Kudos
Message 2 of 6
(4,011 Views)

Hi PKIM,

 

Are you getting any errors?

 

What DAQ device are you running? Double check to see if that is the line your are trying to read the trigger at. Try using the PFI name for that line.

 

Regards,

Noah | Applications Engineer | National Instruments
0 Kudos
Message 3 of 6
(3,986 Views)

@Door-C wrote:

Hi PKIM,

 

Are you getting any errors?

 

What DAQ device are you running? Double check to see if that is the line your are trying to read the trigger at. Try using the PFI name for that line.

 

Regards,


Hi,

  Thanks for the reply. It doesn't show any error, it just finish the task without triggering. What confusing me is: can I use digital line (e.g. dev1/do0) instead of PFI to trigger task? I try search for all examples online but seems they all use PFI, none example is using digital line. Also, if I need to use PFI, how can I use external TTL source to trigger the task, do I need to connect the external TTL source to PFI? I am using PCI6711 but that card's port outlet are sealed in a box, I can only plug the external source to digital lines and analog channel.

0 Kudos
Message 4 of 6
(3,983 Views)

Did you use one of the prototypes to create the instance of that function? Try hitting Ctrl+P while on the line of the configure start trigger function. This should pull up a front panel and there should be a button next to the dialog box for the Trigger Source that should list the available lines for the trigger and they will be in the right format for the device.

 

How are you seeing if the box triggered or not? Are you looking at your outputted data or do you have some other set up to show the trigger was read? If it is data make sure that the array you are writing to is set correctly.

 

You can set off an analog trigger in LabVIEW and the process should be similar in CVI.

Here is a link to how to do it in LabVIEW: http://digital.ni.com/public.nsf/allkb/6F50064F936FA29186257537005B244A?OpenDocument

 

You can also set off an internal hardware trigger. There is plenty of documentation on how to do it in LabVIEW. The process should be similar in CVI.

 

Regards,

Noah | Applications Engineer | National Instruments
0 Kudos
Message 5 of 6
(3,962 Views)

@Door-C wrote:

Did you use one of the prototypes to create the instance of that function? Try hitting Ctrl+P while on the line of the configure start trigger function. This should pull up a front panel and there should be a button next to the dialog box for the Trigger Source that should list the available lines for the trigger and they will be in the right format for the device.

 

How are you seeing if the box triggered or not? Are you looking at your outputted data or do you have some other set up to show the trigger was read? If it is data make sure that the array you are writing to is set correctly.

 

You can set off an analog trigger in LabVIEW and the process should be similar in CVI.

Here is a link to how to do it in LabVIEW: http://digital.ni.com/public.nsf/allkb/6F50064F936FA29186257537005B244A?OpenDocument

 

You can also set off an internal hardware trigger. There is plenty of documentation on how to do it in LabVIEW. The process should be similar in CVI.

 

Regards,


Thanks for the hint. I didn't see that line as the option of trigger. I only see the PFI. Anyway, today I got another cheaper card installed in my computer so I can use the PFI as external trigger now 🙂

0 Kudos
Message 6 of 6
(3,957 Views)