Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

digital output fixed width pulse NIDAQmx

Dear NI forum members,

 

I am using NIDAQmx C API to implement a behavioural driving program. I would like to monitor a digital input port for an event, and every time a trigger exist I would like to generate a discrete digital pulse of some define width (e.g. 0.1 sec). The PCIe card is named NI PCIe 6321 from the X-series. And the connector block is called NI BNC-2110. Here how far I am now:

 

/* configure read port task */
DAQmxErrChk(DAQmxCreateTask("ReadPort", &readPort));
DAQmxErrChk(DAQmxCreateDIChan(readPort, "Dev1/port0/line0:7", "", DAQmx_Val_ChanPerLine));
DAQmxErrChk(DAQmxCfgChangeDetectionTiming(readPort, "Dev1/port0/line0", "", DAQmx_Val_ContSamps, 1));
DAQmxErrChk(DAQmxRegisterSignalEvent(readPort, DAQmx_Val_ChangeDetectionEvent, 0, ChangeDetectionCallback, state));

/* configure write port task */
DAQmxErrChk(DAQmxCreateTask("WritePort", &writePort));
DAQmxErrChk(DAQmxCreateDOChan(writePort, "Dev1/port1/line0:7", "", DAQmx_Val_ChanForAllLines)); # in the Callback function write to digital line

/* change detection callback function */
int32 CVICALLBACK ChangeDetectionCallback(TaskHandle taskHandle, int32 signalID, void *callbackData)
{
    uInt8 data[8] = {0};
    int32 numRead;
    unsigned char lineBits = 0x01;
/* read port at event */ if (taskHandle) { DAQmxErrChk(DAQmxReadDigitalLines(taskHandle, 1, 10.0, DAQmx_Val_GroupByScanNumber, data, 8, &numRead, NULL, NULL)); /* if any bits changed trigger a pulse */ if (numRead) { DAQmxErrChk(DAQmxStartTask(writePort)); DAQmxErrChk(DAQmxWriteDigitalU8(writePort, 1, 1, 10.0, DAQmx_Val_GroupByChannel, &lineBits, NULL, NULL)); /* somewhere here update lineBits to ground (0) level and write after some time */ # pulse width time delay ??? also I do not want to use a delay command inside the callback function # will it keep it blocked if event arrived while it is being delayed lineBits = 0x02; DAQmxErrChk(DAQmxWriteDigitalU8(writePort, 1, 1, 10.0, DAQmx_Val_GroupByChannel, &lineBits, NULL, NULL)); DAQmxErrChk(DAQmxStopTask(writePort)); } } return 0; }

 

Any help or direction will be helpful! Thank you in advance!

 

Best,

Georgi

0 Kudos
Message 1 of 2
(4,278 Views)

Dear Georgi,

 

You should configure a retriggerable task (https://www.ni.com/en/support/documentation/supplemental/21/retriggerable-tasks-in-ni-daqmx.html)

 

With your PCIe-6321 X-Series board and it's Advanced timing and triggering with NI-STC3 timing and synchronization technology, you can do this application while using only one onboard counter.

 

Best,

 

Marc Oesterle

Applications Engineer, NI Germany

0 Kudos
Message 2 of 2
(4,221 Views)