LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Gated pulse train generation with NI E-series DAQ boards

I'm using an NI E-series DAQ board with two general purpose timer/counters.
I want to generate a pulse train consisting of a precise no. of pulses.
The code example below sends 10 pulses of a 40% duty cycle, 100 Hz. pulse
train each time the function is called. The 1st counter generates the
pulse train which is gated on for a duration determined by the 2nd counter,
which is configured as a one-shot timer. It works but requires connecting
the DAQ board's FREQ_OUT signal to the GATE of the 2nd counter to act as a
trigger for the 2nd counter, so the one-shot is triggered as soon as the
counter is armed. I have 2 questions:

1. Is there another way to trigger the 2nd counter through software only
so it starts as soon as its armed?

2. What value do you use for the ND_COUNT_1 parameter for no delay?
Here I used 2 (which is only 200 ns), but is zero a legal value?

void GatedPulseTrain(void)
{
i16 iDevice = DEVICE_N;
u32 ulGpctrNum = ND_COUNTER_0;
u32 ulGpctrOutput = ND_GPCTR0_OUTPUT;
u32 ulGpctrGateNum = ND_COUNTER_1;
u32 ulGpctrGateOutput = ND_GPCTR1_OUTPUT;
u32 ulGatePulses = 10000;
u32 ulLowCount = 600;
u32 ulHiCount = 400;

// Route 1st counter's ND_GATE to the other counter's output
GPCTR_Change_Parameter(iDevice, ulGpctrNum, ND_GATE, ND_OTHER_GPCTR_OUTPUT);
GPCTR_Change_Parameter(iDevice, ulGpctrNum, ND_GATE_POLARITY, ND_POSITIVE);

GPCTR_Change_Parameter(iDevice, ulGpctrNum, ND_SOURCE, ND_INTERNAL_100_KHZ);
GPCTR_Change_Parameter(iDevice, ulGpctrNum, ND_COUNT_1, ulLowCount);
GPCTR_Change_Parameter(iDevice, ulGpctrNum, ND_COUNT_2, ulHighCount);
// To output a counter pulse, you must call Select_Signal.
Select_Signal(iDevice, ulGpctrOutput, ulGpctrOutput, ND_LOW_TO_HIGH);

// Initialize 2nd counter for one-shot operation so it's output will gate 1st
counter
GPCTR_Control(iDevice, ulGpctrGateNum, ND_RESET);
GPCTR_Set_Application(iDevice, ulGpctrGateNum, ND_SINGLE_TRIG_PULSE_GNR); //
one-shot mode
GPCTR_Change_Parameter(iDevice, ulGpctrGateNum, ND_SOURCE,
ND_INTERNAL_100_KHZ);
GPCTR_Change_Parameter(iDevice, ulGpctrGateNum, ND_COUNT_1, 2); // min. delay
after trigger
GPCTR_Change_Parameter(iDevice, ulGpctrGateNum, ND_COUNT_2, ulGatePulses); //
pulse width

// Apply a continuous trigger source (10 MHz FREQ_OUT signal) to 2nd
counter's
// gate (ND_PFI_4) so it will begin outputting the gate pulse to the 1st
// counter's gate as soon as its armed. This requires wiring a jumper between
// the ND_PFI_4 to FREQ_OUT signals.
Select_Signal(iDevice, ND_FREQ_OUT, ND_INTERNAL_10_MHZ, 1);
GPCTR_Change_Parameter(iDevice, ulGpctrGateNum, ND_GATE, ND_PFI_4);
Select_Signal(iDevice, ulGpctrOutput, ulGpctrOutput, ND_LOW_TO_HIGH);

// Program and arm both counters at once
GPCTR_Control(iDevice, ulGpctrGateNum, ND_PROGRAM);
GPCTR_Control(iDevice, ulGpctrNum, ND_PROGRAM);
}
0 Kudos
Message 1 of 3
(3,379 Views)
There are specific sections of Developer's Exchange for Data Acquisition include MIO, DIO, and Counter/Timer sections. You will normally get a better response to a question like this by posting it in those sections.

Best Regards,

Chris Matthews
Measurement Studio Support Manager
0 Kudos
Message 2 of 3
(3,379 Views)
It looks like you posted a short version of this question at the Measurement Devices section, which is the correct place to post. I will paste what I have answered there and answer the additional question.

If you want the single pulse to start as soon as the counter is armed, then I would suggest using ND_SINGLE_PULSE_GNR instead of the triggered operation. Alternatively, if you do want to software control when that pulse is generated, wire a DIO line to be the gate and then use the DIG_Out_Line function to create the gate transition to start that single pulse.

If you use the DIO line instead of the FREQ_OUT signal, you would free up the FREQ_OUT in case you want to output a pulse train for another operation.

You can find good information about the GPCTR function
s and the Digital line functions in the NI-DAQ Help file installed with NI-DAQ (Start menu >> Programs >> National Instruments >> NI-DAQ >> NI-DAQ Help).

The ND_COUNT_1 and ND_COUNT_2 parameters have a minimum value of 2. You can also find this information in the NI-DAQ Help file. Note that if you are concerned about polarity for your output signal, you can use the Select_Signal function to change that.

There is an example for generating a single pulse that ships with NI-DAQ called STCgenerateSinglePulse that you can find in the C:\MeasurementStudio\cvi55\samples\daq\Ctr directory or the C:\Program Files\National Instruments\NI-DAQ\Examples directory, depending on what programming environment you have.

Regards,

Geneva L.
Applications Engineer
National Instruments
http://www.ni.com/ask
0 Kudos
Message 3 of 3
(3,379 Views)