Detection of DIN leading edge on NI pci-6229

53 views
Skip to first unread message

witzel...@gmail.com

unread,
Jun 16, 2008, 5:20:40 PM6/16/08
to Comedi: Linux Control and Measurement Device Interface
Hello,

I started working on an user-space application to do some DIO on my
pci-6229. So far digitial output is working just as planned, but now
I'm worrying about the digital input. According to the manual the
board has functionality to detect a change on a digital input and to
create a trigger/interrupt based on it. Now, I'd like comedi to inform
my application when a digital input changed and to note the exact time
when that happened. Since there is no way for me to have my
application polling, I'd like to be able to have either a background
process or comedi log the exact time when the leading edge on the
digital input occured.
Can you please help me setting this up with comedi ?

Thank you very much,
Thomas

witzel...@gmail.com

unread,
Jul 2, 2008, 9:09:42 PM7/2/08
to Comedi: Linux Control and Measurement Device Interface
Since there is no reply it appears that this is not supported yet.
Where do I obtain the NI register map etc., so I could look into the
driver code and add the functionality ? The hardware supports it,
because the manual says so.

Thank you,
Thomas

Ian Abbott

unread,
Jul 3, 2008, 6:37:37 AM7/3/08
to comed...@googlegroups.com

The counter subdevices for that board's driver support comedi commands
with external trigger sources, so you should be able to measure time in
terms of the value of a free-running counter at each trigger.

--
-=( Ian Abbott @ MEV Ltd. E-mail: <abb...@mev.co.uk> )=-
-=( Tel: +44 (0)161 477 1898 FAX: +44 (0)161 718 3587 )=-

Thomas Witzel

unread,
Jul 3, 2008, 12:07:06 PM7/3/08
to comed...@googlegroups.com
Yes, but I also need to tell the user mode application and read the
DIN value. So what I really need to do is this:

- detect a change in the DIN lines
- read the DIN value from a set of DIN lines
- read the time
- inform the application about this event

So if I could setup the card to do both: change detected clocking of
CDI and reading of a timer/counter as well as signalling the user mode
application, that would be great. Is there an example for this ? Even
if I can't read the timer/counter from the NI for now, I think just
doing change detection clocked CDI and informing the app instantly
that this happened would be good enough for a start.

Thank you, Thomas

Ian Abbott

unread,
Jul 3, 2008, 1:43:55 PM7/3/08
to comed...@googlegroups.com
On 03/07/08 17:07, Thomas Witzel wrote:
> Yes, but I also need to tell the user mode application and read the
> DIN value. So what I really need to do is this:
>
> - detect a change in the DIN lines
> - read the DIN value from a set of DIN lines
> - read the time
> - inform the application about this event
>
> So if I could setup the card to do both: change detected clocking of
> CDI and reading of a timer/counter as well as signalling the user mode
> application, that would be great. Is there an example for this ? Even
> if I can't read the timer/counter from the NI for now, I think just
> doing change detection clocked CDI and informing the app instantly
> that this happened would be good enough for a start.
>
> Thank you, Thomas

The digital I/O subdevices and counter subdevices are logically distinct
within the driver and commands only support reading or writing channels
on a single subdevice. You need to read channels from two different
subdevices. Also, from what I can tell, the ni_pcimio driver does not
support commands for reading digital inputs (but the ni_pcidio driver does).

If you had a card with sufficient digital inputs to cover the digital
inputs you are interested in and some way to derive a trigger from
changes to these inputs, and you also had enough spare digital inputs to
read the output from an external, free-running counter with parallel
output, and the driver for the card supported reading all these bits
using comedi_command, then what you want to achieve would be fairly
trivial! :-) (But you would either have to use a Gray-code counter or
synchronize the trigger to occur in the middle of the counter's clock
cycle.) The need for external digital logic may put you off this
solution though!

Thomas Witzel

unread,
Jul 3, 2008, 6:31:38 PM7/3/08
to comed...@googlegroups.com
Yes, since this device has all this internally. I have the
documentation and the DDK code from NI, and as first thing I'd like to
add the din change detection as ext_trig source to comedi. Then we
have to see about the cdin, but that would not be very difficult
either.
My biggest "???" is now, how do I signal a user mode application that
an external trigger has occured ?

Thanks, Thomas

Ian Abbott

unread,
Jul 4, 2008, 5:59:55 AM7/4/08
to comed...@googlegroups.com
On 03/07/08 23:31, Thomas Witzel wrote:
> Yes, since this device has all this internally. I have the
> documentation and the DDK code from NI, and as first thing I'd like to
> add the din change detection as ext_trig source to comedi. Then we
> have to see about the cdin, but that would not be very difficult
> either.
> My biggest "???" is now, how do I signal a user mode application that
> an external trigger has occured ?

In general, it's when the device becomes readable, so the application
can use select() or poll() or just return from a blocking read().

The command has to be set up with the TRIG_WAKE_EOS flag to deliver data
at the end of each scan (and the driver would have to support that
flag), otherwise the data would just remain sat in a hardware FIFO until
a FIFO level triggered interrupt occurred.

Thomas Witzel

unread,
Jul 4, 2008, 2:11:19 PM7/4/08
to comed...@googlegroups.com
The problem is that the application is doing something else (not
sleeping), otherwise I could just poll. But I could use a separate
process that waits with poll and then signals the main application,
I'll play with that.

Thomas

Ian Abbott

unread,
Jul 4, 2008, 2:30:09 PM7/4/08
to comed...@googlegroups.com
On 04/07/08 19:11, Thomas Witzel wrote:
> The problem is that the application is doing something else (not
> sleeping), otherwise I could just poll. But I could use a separate
> process that waits with poll and then signals the main application,
> I'll play with that.

If you want a traditional Unix signal, you could set a signal handler
for SIGIO and use fcntl() on the comedi device's file descriptor to set
the O_ASYNC flag. I don't like signals much though - they can be a bit
too non-specific!

Thomas Witzel

unread,
Jul 4, 2008, 2:37:26 PM7/4/08
to comed...@googlegroups.com
Wow thanks. I'll have enough input to play with that for a couple of
days now :-)

Rosali Pyun

unread,
Jan 13, 2015, 10:39:53 AM1/13/15
to comed...@googlegroups.com, witzel...@gmail.com
Hi Thomas,

I am also trying to do same thing with PCI 6229 card as you mentioned in the first post.

"... inform my application when a digital input changed and to note the exact time 
when that happened. ...log the exact time when the leading edge on the 
digital input occured."

I want to log the exact time whenever the digital input returns falling edge.

I tried to use configuration instruction to configure a digital channel as DI Change Detection mode, but the configuration instruction returns error. 

Were you able to solve your problem?
If so, could you please help me with this?

Thanks,
Rosali
Reply all
Reply to author
Forward
0 new messages