Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

trigger ai reading ctr0 ctr1

I have an E series board.

Problem description:

I want to set a pulse on ctr0 this pulse triggers a puls on ctr1 with a specified delay, and puls on ctr1 triggers reading of ai channel.

I wil implement this with DAQmx in Ansi C, but I have resource problems on the board.

Is there a solution to perform an ai measurement with a specific delay after pulse on ctr0.
0 Kudos
Message 1 of 3
(3,695 Views)
This is the nidaq code I have this must be converted to NIDAQmx is this possible

// reset counter1
GPCTR_Control(iDevice, ND_COUNTER_1, ND_RESET);

// use counter 1 as puls generator to trigger counter 0
GPCTR_Set_Application(iDevice, ND_COUNTER_1, ND_SINGLE_PULSE_GNR);

// write delay counter1, note this delay is not used.
GPCTR_Change_Parameter(iDevice, ND_COUNTER_1, ND_COUNT_1,ulLOWcount);

// write pulse length counter1
GPCTR_Change_Parameter(iDevice, ND_COUNTER_1, ND_COUNT_2,ulHIGHcount);

// set gpctr0 as output channel of pulse of counter1
// To output a counter pulse, you must call Select_Signal.
Select_Signal(iDevice, ND_GPCTR0_OUTPUT, ND_GPCTR0_OUTPUT, ND_LOW_TO_HIGH);

// reset counter2
GPCTR_Control(iDevice, ND_COUNTER_0, ND_RESET);

// use counter as triggered puls generator1
GPCTR_Set_Application(iDevice, ND_COUNTER_0,ND_SINGLE_TRIG_PULSE_GNR);

// set channel other counter output to be used as trigger
GPCTR_Change_Parameter(iDevice, ND_COUNTER_0, ND_GATE,ND_OTHER_GPCTR_OUTPUT);

// write delay after external trigger
GPCTR_Change_Parameter(iDevice, ND_COUNTER_0, ND_COUNT_1,ulLOWcount2);

// write pulse length
GPCTR_Change_Parameter(iDevice, ND_COUNTER_0, ND_COUNT_2,ulHIGHcount2);

// set gpctr1 as output channel of pulse of counter2
// To output a counter pulse, you must call Select_Signal.
Select_Signal(iDevice, ND_GPCTR1_OUTPUT, ND_GPCTR1_OUTPUT, ND_LOW_TO_HIGH);

// arm counter2 (delay counter)
GPCTR_Control(iDevice, ND_COUNTER_0, ND_PROGRAM);

// program ADC to wait for trigger
iStatus = DAQ_Config(iDevice,1,0);

//Configure DAQ to look for Start Trigger from GPCTR1 Ouput routed via PFI_0 //ND_GPCTR1_OUTPUT
iStatus = Select_Signal(iDevice,ND_IN_START_TRIGGER,ND_GPCTR0_OUTPUT, ND_LOW_TO_HIGH); // changed output to gate

iStatus = DAQ_Start(iDevice,iChan,iGain,piBuffer,ulCount,ND_INTERNAL_1_MHZ,2);

// arm counter 1 (puls generator)
iStatus = GPCTR_Control(iDevice, ND_COUNTER_1, ND_PROGRAM);

while ((iDAQstopped != 1) && (iStatus == 0)) {
iStatus = DAQ_Check(iDevice, &iDAQstopped, &ulRetrieved);
}

iStatus = DAQ_VScale(iDevice, 1, iGain, dGainAdjust, dOffset,ulCount, piBuffer, pdVoltBuffer);

// CLEANUP - Don't check for errors on purpose.
iStatus = DAQ_Clear(iDevice);
iStatus = GPCTR_Control(iDevice, ND_COUNTER_1, ND_RESET);
iStatus = GPCTR_Control(iDevice, ND_COUNTER_0, ND_RESET);
0 Kudos
Message 2 of 3
(3,690 Views)
You can find a example that does single pulse generation with the DAQ driver. by default it installs in:
C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Counter\Generate Pulse\Dig Pulse. You can add a trigger function to trigger the counter.

For more information on migration see:
http://zone.ni.com/devzone/conceptd.nsf/webmain/82A34EA5258568D386256DE10058912A

This is mainly LabVIEW focused but the DAQmx function calls in LabVIEW are equal to the ANCI C.

Met vriendelijke groet / Kind regards,

Karsten
Applications Engineer
National Instruments
0 Kudos
Message 3 of 3
(3,669 Views)