Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

program in c to read quadrature encoder didn't work (NI 6220)

Solved!
Go to solution

Hello,

I have a NI-6220 and I connect quadrature encoder to it . Then I use Measurement & Automation program to read the encoder and it works well.

the problem when I use the c++ program it doesn't work and demonistrate arandom fixed value.

in attached files the code which I used .

I'm waiting for your reply.

 

Best Regards,

Alaa Mohammed Abd Elmoaty Khalifa. 

Egypt-Japan University for Science and Technology (E-JUST).
M.Sc. Graduate Student.
0 Kudos
Message 1 of 17
(8,101 Views)

Hello,

 

Have you tried using a simple example code with your card? Oftentimes errors like these can be attributed to a small error in the code. If it works with the example code, you can compare the syntax of the example to your own. I am attaching an example that should work for your system.

 

-Erik S

0 Kudos
Message 2 of 17
(8,064 Views)

Dear-Erik S,

thank you for your replay

I already used another examples and they worked well.

Also ,I tried to change every parameter in the program but it didn't work .

Can you help me and send to me another  program to read encoder or advise me to change what parameter in the program.

 

THANKs

0 Kudos
Message 3 of 17
(8,050 Views)

Are you getting any kind of error whenever it returns a fixed value? I looked through your code, and the syntax appears to be correct. An error could point us to which function call is causing the problem. I found a link to some more sample code regarding angular encoders. Here is the link:

 

http://read.pudn.com/downloads36/sourcecode/windows/console/112334/Measure%20Position/Angular%20Posi...

 

-Erik S

0 Kudos
Message 4 of 17
(8,027 Views)

Well I'm not sure how this isn't giving you a compiler error, but I'm seeing the name of the variable in your DAQmx Read call as "data1" instead of "data".

 

 

Best Regards,

John Passiak
0 Kudos
Message 5 of 17
(7,998 Views)

Hello,

thanks to all for your interest ,I found the solution to this problem.

The code needs to display data[0] not data only because data contain 1000 place for each sample.

Thank you very much.

 

 

Best Regards,

Alaa Khalifa. 

Egypt-Japan University for Science and Technology (E-JUST).
M.Sc. Graduate Student.
0 Kudos
Message 6 of 17
(7,968 Views)

Hello every one,

 

the previous program is working well , but when I make a new project or a new program with the same code it doesn't work and display an error

 

1>.\WriteDigChan.cpp(211) : error C2664: 'DAQmxReadCounterF64' : cannot convert parameter 4 from 'float64 (*)[1000]' to 'float64 []'

 

I think the problem in the properties of the new project , although I review it with the old one .

 

I'm waiting for your reply.

 

Best Regards,

Alaa Khalifa. 

Egypt-Japan University for Science and Technology (E-JUST).
M.Sc. Graduate Student
0 Kudos
Message 7 of 17
(7,922 Views)

Hi Alaa,

 

This could be a problem with attempting an implicit conversion that needs to be explicit. Here is a link to Microsoft page that explains how to resolve the error:

 

http://msdn.microsoft.com/en-us/library/s5b150wd.aspx

 

-Erik S

0 Kudos
Message 8 of 17
(7,903 Views)

Dear all,

 

Why I get this error

Error -200141 occurred at DAQ Assistant    "Data was overwritten before it could be read by the system. If Data Transfer Mechanism is Interrupts, try using DMA or USB Bulk. Otherwise, divide the input signal before taking the measurement."

 

note

I have 4 encoder with the same specifications and I make the same connections, 3 motors worked well but the fourth give this error .

0 Kudos
Message 9 of 17
(7,871 Views)

That error typically indicates that the counter buffer is overflowing. You may be able to avoid the error by decreasing your sampling rates. Check out this discussion forum that appears to cover the same issue:

 

http://forums.ni.com/t5/Multifunction-DAQ/quot-Data-was-overwritten-before-it-could-be-read-by-the-s...

 

 

-Erik S

0 Kudos
Message 10 of 17
(7,861 Views)