Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Read Dig Chan-Change Detection unexpected behavior

I have an application where I need to count digital pulses, but the two counters on my PCI-6221 are already used for something else.  I thought an efficient way to do this would be to use a VI similar to the Read Dig Chan-Change Detection.vi shipping example and simply keep track of how many samples were read.  The problem I encountered was that the DAQmx Read VI only executes after a multiple of 4 changes.  
 
To see what I'm talking about, add an indicator to the loop iteration terminal in the example and toggle the Rising/Falling Edge Lines.  After 4 changes have occured, the loop will run and read the number of samples selected in the Samples Per Read control.  If the Samples Per Read is set to 1, the loop will execute 4 times each time the number of changes is a multiple of 4; if it is set to 4, the loop will execute once each time the number of changes is a multiple of 4; if it is set to 3, the loop will execute once after 4 changes, once after 8 changes, and twice after 12 changes. 
 
Is there anything I can do to find out how many changes have occurred in a multiple of 1 or 2?  I've tried using digital change detection with the Register For Events node and using digital change detection as a timing source for a timed loop, but I would end up missing counts.  (The pulses can be as short as 6ms and I'm running a lot of other stuff at the same time.)  I was hoping that by doing a continous read, I could take advantage of the buffer so I didn't miss counts.
0 Kudos
Message 1 of 6
(3,812 Views)
Hi MRSACHAU,

When configuring a digital task for change detection, the default memory transfer mode for the device is set to DMA.  As a result there is a minimum number of samples that must be obtained into the onboard memory before the data transfer takes place.  It appears that this device uses 32-bit DMA transfers (4 changes * 8 digital lines).  Using a property node you can change the memory transfer mechanism that is used.  There are two options available instead of DMA - interrupts and programmed I/O.  Use a DAQmx Channel Property Node and select the Digital Input>>General Properties>>Advanced>>Data Transfer and Memory>>Data Transfer Mechanism property.  This property node would be placed after the DAQmx Timing.vi and before the DAQmx Start Task.vi.  To set the property, right click on the node and select "Change All to Write".  Here's info on the two types of alternate transfer modes:

Interrupts:  Data transfers take place independently from the application. Using interrupts increases CPU usage because the CPU must service interrupt requests. Typically, you should use interrupts if the device is out of DMA channels.

Programmed I/O:  Data transfers take place when you call DAQmx Read.

It is your preference on which one to use.  I ran this application with both on a similar M-Series device and didn't run into any problems.

Regards,
Andrew W
National Instruments
Message 2 of 6
(3,791 Views)

So if I choose the polling mode do I still get an event immediatley when the change happens and then just read the state of the lines.

 

John

0 Kudos
Message 3 of 6
(3,466 Views)

Hello rammer,

 

Are you refering to the Packet Detection Polling mode for a Real Time target?

 

Best regards,

 

Ali M

Applications Engineer

National Instruments

0 Kudos
Message 4 of 6
(3,439 Views)

Sorry a typo.  Based on the last post I was interested in:

 

Programmed I/O:  Data transfers take place when you call DAQmx Read.

I notice that if I have the hardware option then I have to have the read in the event structure.  If the event structure queues a new state to a state machine then I sometime get a timeout on reading the digital value

0 Kudos
Message 5 of 6
(3,428 Views)

Hello rammer,

 

Several reasons could cause the DAQmx Read VI to time out, for example: sample rate, trigger configurations, external timing etc. I have attached a link explaining these reasons and plausible solutions. If you still experience issues after implementing these steps, I would recommend creating a new post in order to separate forum issues. Thanks

 

1. http://digital.ni.com/public.nsf/allkb/FEF778AD990D5BD886256DD700770103

 

 

Best Regards,

 

Ali M

Applications Engineer

National Instruments

Message Edited by Ali M on 05-03-2010 05:52 PM
0 Kudos
Message 6 of 6
(3,398 Views)