Counter set-up

229 views
Skip to first unread message

mathmanx

unread,
Nov 18, 2010, 10:42:31 AM11/18/10
to Comedi: Linux Control and Measurement Device Interface
Hi all!
I'm new to Comedi (~2weeks), and have been very impressed by how
active this group is.

I need some advice on setting up a counter on an NI-6229 board. The
big picture is that I want to run an analog capture. I'm going to be
generating some software events that I want to correlate with the
analog capture as accurately as possible. To do this, I am planning
on running a counter with the analog input clock as the source. I've
succeeded in setting up the analog capture, both via demo's and
software. However, I have been unable to get the DAQ to configure the
counter in a meaningful way. Following is the sequence of demo
commands that I am using to initialize, run, and test the counter:

$ ./choose_clock -s 12 -c 0 -f /dev/comedi0_subd12 0
Selecting master clock 0 for channel 0 on subdevice.
Clock period unspecified.
$ ./gpct_simple_counting -s 12 -c 0 -f /dev/comedi0_subd12
Initiating simple event counting on subdevice 12.
$ ./inp -s 12 -c 0 -f /dev/comedi0_subd12
4294967295


I've tried running this sequence with varying clock frequencies, using
sub-devices 11,12, and 13, and referencing comedi0 and the
comedi0_subd(11,12,13), and clock sources of 0,1,2 - as listed in the
"enum ni_gpct_clock_source_bits" from Comedi.h. Do you have any
advice on what configuration steps I am doing incorrectly, or if I am
misunderstanding anything?

Thank you in advance,
Mike

maustin

unread,
Nov 22, 2010, 8:52:29 AM11/22/10
to comed...@googlegroups.com
Hello,

I apologize for resending this message, but I have still been
unable to get the counters on the 6229 to count the analog sample clock
ticks. Please provide any advice you may have.

Thank you!
Mike

Alessandro Toso

unread,
Nov 22, 2010, 9:05:58 AM11/22/10
to comed...@googlegroups.com
Hello Mike,

I believe that there is something wrong with this board.... I played a little bit in the past few months with the counters to read a quadrature encoder but I didn't manage to get a decent reading nor I had the time to debug the problem.

Best regards,
Alessandro



--
You received this message because you are subscribed to the Google Groups "Comedi: Linux Control and Measurement Device Interface" group.
To post to this group, send email to comed...@googlegroups.com.
To unsubscribe from this group, send email to comedi_list...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/comedi_list?hl=en.


Alessandro Toso

unread,
Mar 3, 2011, 5:49:28 AM3/3/11
to comed...@googlegroups.com
Dear all,

after a few tries with NI software under windows, I found out that connecting the quadrature encoder to PFI 8 and 9, although is supposed to work, in reality it doesn't; I don't know if my board is faulty or something else is going on but for some reason that I cannot understand, if I connect it to PFI 3 and 11 I can read the angle.... Then when I got back to linux and comedi I was also able to read the encoder (I took part of the code from the scicos encoder block and merged into my C code).

Best regards,
Alessandro

Guillaume Millet

unread,
Apr 6, 2011, 8:47:58 PM4/6/11
to Comedi: Linux Control and Measurement Device Interface
Hello,
On 68-pin NI M-series cards, for reading a quadrature encoder, A, B,
and Z inputs are on PFI 8, 10, and 9, respectively, for counter 0; and
PFI 3, 11, and 4 for counter 1 (http://digital.ni.com/manuals.nsf/
websearch/2025C99AB0614F9E8625748000577B9A, p. 136).
Best,
Guillaume

On Mar 3, 6:49 am, Alessandro Toso <alessandro.t...@gmail.com> wrote:
> Dear all,
>
> after a few tries with NI software under windows, I found out that
> connecting the quadrature encoder to PFI 8 and 9, although is supposed to
> work, in reality it doesn't; I don't know if my board is faulty or something
> else is going on but for some reason that I cannot understand, if I connect
> it to PFI 3 and 11 I can read the angle.... Then when I got back to linux
> and comedi I was also able to read the encoder (I took part of the code from
> the scicos encoder block and merged into my C code).
>
> Best regards,
> Alessandro
>
> On Mon, Nov 22, 2010 at 3:05 PM, Alessandro Toso
> <alessandro.t...@gmail.com>wrote:
>
> > Hello Mike,
>
> > I believe that there is something wrong with this board.... I played a
> > little bit in the past few months with the counters to read a quadrature
> > encoder but I didn't manage to get a decent reading nor I had the time to
> > debug the problem.
>
> > Best regards,
> > Alessandro
>

jordi_...@encopim.com

unread,
Apr 6, 2011, 8:49:16 PM4/6/11
to comed...@googlegroups.com
Out of the office until April 19th.


Alessandro Toso

unread,
Apr 7, 2011, 4:42:41 AM4/7/11
to comed...@googlegroups.com
Dear Guillaume,

indeed I forgot to mention that. Maybe then counter 0 on my board does not work properly....
Best regards,
Alessandro

On Thu, Apr 7, 2011 at 2:49 AM, <jordi_...@encopim.com> wrote:
Out of the office until April 19th.


--

Guillaume Millet

unread,
Apr 7, 2011, 6:40:18 PM4/7/11
to Comedi: Linux Control and Measurement Device Interface
Hi Alessandro,
I understood you made a mistake by connecting the encoder to PFI 8 and
9 instead of 8 and 10 (PFI 9 is for Z (optional), not for B).
Best regards,
Guillaume

jordi_...@encopim.com

unread,
Apr 7, 2011, 6:41:28 PM4/7/11
to comed...@googlegroups.com

Guillaume Millet

unread,
Apr 7, 2011, 6:23:58 PM4/7/11
to comed...@googlegroups.com
Hi Alessandro,
I understood you did a mistake by connecting the encoder to PFI 8 and 9
instead of 8 and 10 (PFI 9 is for Z (optional), not for B).
Best regards,
Guillaume

Guillaume Millet

unread,
Apr 6, 2011, 8:06:52 PM4/6/11
to comed...@googlegroups.com
Hello,
On a PCI 6221, for reading a quadrature encoder, A, B, and Z inputs are on PFI 8, 10, and 9, respectively, for counter 0; and PFI 3, 11, and 4 for counter 1.
Best,
Guillaume
PS: I sent this message on the 3/3/2011 but it seems that it got lost...

Finn

unread,
Nov 28, 2011, 9:58:03 AM11/28/11
to comed...@googlegroups.com
Did anybody mange to get it to work? I have tried several hours with a PCIe-6259 but I did not mange to get the counter to work... on windows it works without problems? How do I select PFI8? Is ./choose_clock -s 11 -c 8 0 right therefore?

Finn Hoffmann

unread,
Dec 1, 2011, 10:09:06 AM12/1/11
to comed...@googlegroups.com
Hello,

after looking a bit deeper into it I found out that
$ ./choose_clock -s11 -c1 0
Selecting master clock 0 for channel 1 on subdevice.
Clock period unspecified.
is calling comedi_set_clock_source which can be found here:
http://comedi.org/git?p=comedi/comedilib.git;a=blob;f=lib/insn_config_wrappers.c;h=3fc8f56d510ed37ebb4376b5b85f651b9bea54fd;hb=HEAD#l160
The thing which makes me wonder is that this function is not using the
channel information at all.
The readme says that the command line argument specifies the source ...
but how? Do I have to select 8 because my signal line is connected to
PFI8 or do I have to select 0 because it is Pin A of the Counter or
anything else?
If I initialize the counter and read the value I always get 4294967295.
If I disable gate in the pct_simple_counting code the counter starts
counting something. I do not know what exactly, but it seems like a timer:
$ ./gpct_simple_counting -s 11
Initiating simple event counting on subdevice 11.
$ ./inp -s 11
44776835
$ ./inp -s 11
54539366
Any Ideas how I can make the counter count edges on the input line?

Do I possibly have to use NI_GPCT_SOURCE_PIN_CLOCK_SRC_BITS(unsigned n)
or NI_GPCT_ANALOG_TRIGGER_OUT_CLOCK_SRC_BITS from here:
http://comedi.org/git?p=comedi/comedilib.git;a=blob;f=include/comedi.h;h=ca9a43c447b906bbf72904dfcdbbf40400c0ba7c;hb=HEAD#l588

Thanks in advance

Finn

> --
> You received this message because you are subscribed to the Google
> Groups "Comedi: Linux Control and Measurement Device Interface" group.

> To view this discussion on the web visit
> https://groups.google.com/d/msg/comedi_list/-/z4nMzr0PiGsJ.

Ian Abbott

unread,
Dec 1, 2011, 11:46:08 AM12/1/11
to comed...@googlegroups.com
On 2011-12-01 15:09, Finn Hoffmann wrote:
> Hello,
>
> after looking a bit deeper into it I found out that
> $ ./choose_clock -s11 -c1 0
> Selecting master clock 0 for channel 1 on subdevice.
> Clock period unspecified.
> is calling comedi_set_clock_source which can be found here:
> http://comedi.org/git?p=comedi/comedilib.git;a=blob;f=lib/insn_config_wrappers.c;h=3fc8f56d510ed37ebb4376b5b85f651b9bea54fd;hb=HEAD#l160
> The thing which makes me wonder is that this function is not using the
> channel information at all.

That's a bug. Fixed it. Thanks for the report! It won't make any
difference to your problem though as the ni_tio module ignores the
channel number when configuring the clock source.

> The readme says that the command line argument specifies the source ...
> but how? Do I have to select 8 because my signal line is connected to
> PFI8 or do I have to select 0 because it is Pin A of the Counter or
> anything else?

I think you set it to 40, which is 32 + 8 or 0x20 + 8. See
NI_GPCT_PFI_CLOCK_SRC_BITS(n) in comedi.h. You can also modify the
clock source with some flag values to pre-scale the counter and/or
invert the clock signal - see enum ni_gpct_clock_source_bits in comedi.h
for the values.

> If I initialize the counter and read the value I always get 4294967295.
> If I disable gate in the pct_simple_counting code the counter starts
> counting something. I do not know what exactly, but it seems like a timer:
> $ ./gpct_simple_counting -s 11
> Initiating simple event counting on subdevice 11.
> $ ./inp -s 11
> 44776835
> $ ./inp -s 11
> 54539366
> Any Ideas how I can make the counter count edges on the input line?
>
> Do I possibly have to use NI_GPCT_SOURCE_PIN_CLOCK_SRC_BITS(unsigned n)
> or NI_GPCT_ANALOG_TRIGGER_OUT_CLOCK_SRC_BITS from here:
> http://comedi.org/git?p=comedi/comedilib.git;a=blob;f=include/comedi.h;h=ca9a43c447b906bbf72904dfcdbbf40400c0ba7c;hb=HEAD#l588

NI_GPCT_SOURCE_PIN_CLOCK_SRC_BITS(n), I think.

Since the channel is ignored, try:

./choose_clock -s 11 40

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

Finn Hoffmann

unread,
Dec 5, 2011, 8:21:13 AM12/5/11
to comed...@googlegroups.com
Am 01.12.2011 17:46, schrieb Ian Abbott:
> I think you set it to 40, which is 32 + 8 or 0x20 + 8. See
> NI_GPCT_PFI_CLOCK_SRC_BITS(n) in comedi.h. You can also modify the
> clock source with some flag values to pre-scale the counter and/or
> invert the clock signal - see enum ni_gpct_clock_source_bits in
> comedi.h for the values.
>
> NI_GPCT_SOURCE_PIN_CLOCK_SRC_BITS(n), I think.
>
> Since the channel is ignored, try:
>
> ./choose_clock -s 11 40
>
thank you, that works.

Why is there a NI_GPCT_GATE_PIN_GATE_SELECT(0)? For me it worked only
with NI_GPCT_DISABLED_GATE_SELECT | CR_EDGE in
http://comedi.org/git?p=comedi/comedilib.git;a=blob;f=demo/gpct_simple_counting.c;h=649dd52388aa06bf2d0b050e12d8ee4b1069d2d3;hb=HEAD#l42

How to select counting direction pin?
I have tried it with
comedi_set_gate_source(dev,subdev,0,0,NI_GPCT_UP_DOWN_PIN_GATE_SELECT(10)),
counter mode NI_GPCT_COUNTING_DIRECTION_HW_GATE_BITS and with
comedi_set_other_source(dev,subdev,0,NI_GPCT_SOURCE_ENCODER_B,NI_GPCT_PFI_OTHER_SELECT(10)),
counter mode NI_GPCT_COUNTING_DIRECTION_HW_UP_DOWN_BITS but without success.

Finn Hoffmann

unread,
Dec 5, 2011, 9:59:43 AM12/5/11
to comed...@googlegroups.com

Got it, the second way works. I messed up the counter mode in first place.

Reply all
Reply to author
Forward
0 new messages