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);
}