Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

finite pulse train generation for .NET

i am trying to generate a finite pulse train with a pre-determined number of pulses.

Here's the sample code I am using

myTask = New Task("COtask")
mNIClockChannel = myTask.COChannels.CreatePulseChannelFrequency(mClockChannelName, _
String.Empty, COPulseFrequencyUnits.Hertz, COPulseIdleState.Low, 0.0, _
Frequency, _
0.5)
myTask.Start()

However, this generates an infinite pulse train. Does anyone know how to limit it to an exact number of pulses without using time to do it?
0 Kudos
Message 1 of 9
(4,210 Views)
Hi Anatoly2,

You can use the DAQmxCfgImplicitTiming function to specify that the pulse generation be finite. The C function call for it is below.

int32 DAQmxCfgImplicitTiming (TaskHandle taskHandle, int32 sampleMode, uInt64 sampsPerChanToAcquire);

Set the sampleMode to finite and the sampsPerChanToAcquire to however many pulses you want to output.

-Sal
Message 2 of 9
(4,200 Views)
Keep in mind however, that generating a finite pulse train of more than one pulse will use two counters on your device. Refer to the "Counter Pairs" topic in DAQmx help if you would like to know more about this.

gus....
Message 3 of 9
(4,198 Views)
thx guys, this code seems to work:

myTask = New Task(String.Empty)
mNIClockChannel = myTask.COChannels.CreatePulseChannelFrequency(mClockChannelName, _
String.Empty, COPulseFrequencyUnits.Hertz, COPulseIdleState.Low, 0.0, _
Frequency, 0.5)
myTask.Timing.ConfigureImplicit(SampleQuantityMode.FiniteSamples, HowFar)

myTask.Start()
0 Kudos
Message 4 of 9
(4,190 Views)
it appears that both timers are being used even with only one pulse train being generated with the code above. (the shutter hooked up to ctr0 started opening as I was moving the stepper motor with ctr1)

Is there a way to avoid using both timers ( I only have 2, PCI-6014) and generate a single train with a pre-determined pulse count?
0 Kudos
Message 5 of 9
(4,183 Views)
That is correct, both counters will be used when generating a finite pulse train. If you are only concerned with the pulse being generated on the output (and not the fact that the second counter is being used internally) you can tristate the output terminal for the unused counter, which will keep the single pulse from showing up on the connector. But if you need to use that second counter, you have two options:

1) If your pulse generation is slow enough, you can use either poll the output state or TC reached properties to determine when your desired pulses have been generated and then manually stop the counter. This option would be very CPU intensive and if the signals are too fast, would be prone to error.

2) You could generate the finite pulse train using one of your analog outputs, by outputting a 0-5V square wave and use this as your finite pulse train.

I hope this helps!
gus....
0 Kudos
Message 6 of 9
(4,178 Views)
[q]you can tristate the output terminal for the unused counter[/q]

Gus: could you elaborate on the meaning of the word "tristate" ? I am assuming you are referring to turning off the actual ouput to the device breakout box, if so, how would i do that in the software (MS.NET in particular)
0 Kudos
Message 7 of 9
(4,160 Views)
You are correct, I was referring to turning off the actual output to the device breakout box. You can do this in software by calling the "DAQmxTristateOutputTerm(const char outputTerminal[]);". You would want to call this on the "CtrXOut" pin where X=the counter you are not generating the output of your finite pulse train on. Let me know if you have any trouble doing this.

I hope this helps!
gus....
0 Kudos
Message 8 of 9
(4,147 Views)
Gus:

I have tried to lookup the "Tristate" property info in MS.NET 7.1, and I am finding it is only present on the DIChannel and DOChannel, nothing about the COChannel, which I am trying to tristate.

I found no evidence of "DAQmxTristateOutputTerm" in my help files for .NET or C++, perhaps they changed it?
0 Kudos
Message 9 of 9
(4,143 Views)