Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Counter Output as Sample Clock of Digital Signals

I have a situation where I need to use a hardware counter as sample clock of digital output signals.
 
How do you specify the "Counter Internal Output" signal as a sample clock of digital output?
 
I want to do something like this:
 
  // Create counter task
  CNiDAQmxTask m_Task(_T("ATask"));
  m_Task.COChannels.CreatePulseChannelTicks(_T("Dev1/ctr0"), "", _T("20MHzTimebase"), DAQmxCOPulseIdleStateLow, 0, 10, 10);
  m_Task.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger("PFI0", DAQmxDigitalEdgeStartTriggerEdgeRising);
          
  // Create digital output task                     
  CNiDAQmxTask m_Task2(_T("ATask2"));
  m_Task2.DOChannels.CreateChannel("Dev1/port0/line0", "", DAQmxOneChannelForAllLines);
  m_Task2.Timing.ConfigureSampleClock("XXXXXX", 0, DAQmxSampleClockActiveEdgeRising, DAQmxSampleQuantityModeFiniteSamples, 400);
How do I specificy "counter 0 Internal Output signal" instead of "XXXXXX" above, i.e. the sample clock of the digital output signal. Can't find the name of the signal anywhere in the documentation and help files. I have a 6259 DAQ board. 
 
/pek
0 Kudos
Message 1 of 8
(5,330 Views)

Still no answers....

I have two weeks until a product shall be ready to use, and I need the get this problem solved.

Background:

I'm using a task with analog input channels and a task with one analog output channel. I also have a task with 32 digital lines which I need to have at a certain sample rate, different from the analog channels. Therefor I need to use a counter or an external clock as sample clock for the digital task. It's easier to solve this problem in software than hardware and for that reason I want to use a counter as sample clock.

 

1. How do I setup a counter as sample clock?

2. How do I connect the output from this counter as the sample clock for the digital task?

 

It's probably very easy to do, but I have failed. I'm using Measurement Studio and a 6259 DAQ board.

 

0 Kudos
Message 2 of 8
(5,292 Views)
pek:

I think "Ctr0Out" is the correct syntax for the string. I've used this for timing analog acquisitions before without any trouble.

-- Chris
0 Kudos
Message 3 of 8
(5,284 Views)
Hi pek-
 
You should actually use "/Dev1/Ctr0InternalOutput" to internally route the signal you're generating with the counter to the sample clock for the digital task.
 
Hopefully this helps-
Tom W
National Instruments
0 Kudos
Message 4 of 8
(5,276 Views)

Thank you for your answers, but I can't get it to work.

When I use "ai/SampleClock" as sample clock everything works correct. When I try to use a counter as sample clock the task completes imediately, before any digital signals has been sent/measured. The task even completes before I have started the trigger, which is very confusing. No error appears.

I think that something is wrong about how I setup the counter. I use the code below:

 

// Create counter task

CNiDAQmxTask m_Task(_T("ATask"));

m_Task.COChannels.CreatePulseChannelTicks(_T("Dev1/ctr0"), "", _T("20MHzTimebase"), DAQmxCOPulseIdleStateLow, 0, 100, 100);

m_Task.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger("PFI0", DAQmxDigitalEdgeStartTriggerEdgeRising);

 

// Create digital output task

// The code below works with "ai/SampleClock" as sample clock

CNiDAQmxTask m_Task3(_T("ATask3"));

m_Task3.DOChannels.CreateChannel("Dev1/port0/line0", "", DAQmxOneChannelForAllLines);

m_Task3.Timing.ConfigureSampleClock("Dev1/Ctr0InternalOutput" /*"ai/SampleClock"*/, 0, DAQmxSampleClockActiveEdgeRising, DAQmxSampleQuantityModeFiniteSamples, 400);

 

// Create samples

CNiUInt32Vector ui_data;

for(int i = 0; i < 200; i++)

  for(unsigned int j = 0; j < 2; j++)

    ui_data.Append(j);

 

// Create digital writer

CNiDAQmxDigitalSingleChannelWriter m_writer3(m_Task3.Stream);

m_writer3.WriteMultiSamplePortAsync(

true, ui_data);

 

// Wait until task completes

m_Task3.WaitUntilDone(-1);

 

 

0 Kudos
Message 5 of 8
(5,270 Views)

Hi pek-

Two things:  first, the clock source should be "/Dev1/Ctr0InternalOutput" .  Don't forget the leading slash.

Second, you are never starting the counter generation task.  You need to start the digital task, then start the counter task so that that digital task is waiting for the counter clock and THEN the counter task is waiting for the trigger.  Right now you're just starting the digital task and the counter task is never running.

You may want to check out some shipping examples that show how to perform both the counter output and digital output with "external" clock.  For .NET, these can be found in C:\Program Files\National Instruments\MeasurementStudioVS2003\DotNET\Examples\DAQmx\Counter\Generate Pulse\GenDigPulseTrainContinuous_DigStart and C:\Program Files\National Instruments\MeasurementStudioVS2003\DotNET\Examples\DAQmx\Digital\Generate Values\WriteDigChan_ExtClk\, respectively.

Hopefully this helps-

Tom W
National Instruments
0 Kudos
Message 6 of 8
(5,261 Views)
Thank you, now it's working!
 
- The leading slash in "/Dev1/Ctr0InternalOutput"
- Starting the counter task
 
When do you need to have the leading slash and when can you be without it? When specifing external signals and counters (i.e. "Dev1/ctr0") you don't need the leading slash, why?
 
Again, thank you for your help!
0 Kudos
Message 7 of 8
(5,256 Views)

Hi pek-

In general, the leading slash is only required for timing sources.  This means that "/Dev1/PFI0" and "/Dev1/Ctr0InternalOutput" are required for sample clock source and trigger source inputs.  When you are creating channels (i.e. "Dev1/ctr0") the slash is not necessary.

Hopefully this helps-

Tom W
National Instruments
0 Kudos
Message 8 of 8
(5,254 Views)