Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Setting up the counter functions

Hello,

I am merging an already existing application that was made in Labview and converting it to a C/C++ application using the Borland libs. I am currently experiencing problems in obtaining the correct value from my hollow bore counter do determine the position of my system.

Here is some of the relevant information with regards to the system setup.

Encoder 2

NI-DAQmx Global Channel

Property Value
CI.AngEncoder.PulsesPerRev 1024
CI.AngEncoder.InitialAngle 0
CI.Encoder.ZIndexVal 0
CI.Encoder.ZIndexPhase A High B High
CI.Encoder.ZIndexEnable 1
ChanType Counter Input
CI.CustomScaleName Bottom encoder
CI.MeasType Position:Angular Encoder
CI.AngEncoder.Units From Custom Scale
PhysicalChanName Dev4/ctr0
CI.Encoder.DecodingType X4

Bottom encoder

NI-DAQmx Scale

Property Value
Lin.Slope 0.045454545454499999
Lin.YIntercept 0
PreScaledUnits Degrees
ScaledUnits Degrees
ScaleType Linear

NI PCI-6221 (37-pin): "Dev4"
Property Value
ProductType PCI-6221 (37-pin)
DevSerialNum 0x12225AD
ProductNum 0x71BC
BusType PCI
PCI.BusNum 0x1
PCI.DevNum 0x2
Property Value
Name CB-37FH/Dev4/0


I have access to the labview code if there is relevant information in there to be obtain. Else my trial has been with the following two functions:
DAQmxCreateCIAngEncoderChan
DAQmxReadCounterScalarU32

I am not only off with regards to the scale of the information but if I move my position from a point zero to say +25deg and then -25deg and back to 0deg, I obtain values that are off with regards to the Count obtained from DAQmxReadCounterScalarU32. Is my approach the correct one or am I off with the use of these two functions.

Any help would be of great value.
0 Kudos
Message 1 of 6
(2,197 Views)

Hi JFKAGroup,

I see that you have a couple of options for getting LabVIEW code to work in C:

1.       If it’s heavily based off of an example program that we ship with the driver, start with that and just build on it. You can find examples here in the “Counter » Measure Position” location.

2.       You could build a dll out of the VI and call it from C.

Hopefully that’ll be a good place to start. Post back with further questions.

Mark E.
Precision DC Product Support Engineer
National Instruments

Digital Multimeters (DMMs) and LCR Meters
Programmable Power Supplies and Source Measure Units
0 Kudos
Message 2 of 6
(2,184 Views)
Hello Mark,

I reworked my application using the following functions:

DAQmxCreateTask
DAQmxCreateCIAngEncoderChan
DAQmxCfgSampClkTiming
and then
DAQmxReadCounterF64

But now I get this error message:

Source terminal to be routed could not be found on the device.

Make sure the terminal name is valid for the specified device. Refer to Measurement & Automation Explorer for valid terminal names.
Property: DAQmx_SampClk_Src
Property: DAQmx_SampClk_ActiveEdge
Source Device: Dev4
Source Terminal: Dev4/PFI0

Task Name: MyManualEncoder

Status Code: -89120

If I use the MAX I am able to test the predefined task I am able to get the correct values when rotating, so I know the Dev4/PFI0 clock source is correct but shows up as an error when I use the above functions:

MyAngularPositionTask

NI-DAQmx Task

Property Value
Channels MyAngularPositionTask/AngularPosition
SampQuant.SampMode Continuous Samples
SampClk.ActiveEdge Rising
SampQuant.SampPerChan 100
SampClk.Rate 1000
SampTimingType Sample Clock
SampClk.Src PFI0
Channel Property Value
AngularPosition

CI.AngEncoder.PulsesPerRev 24

CI.AngEncoder.InitialAngle 0

CI.Encoder.ZIndexVal 0

CI.Encoder.ZIndexPhase A High B High

CI.Encoder.ZIndexEnable 0

ChanType Counter Input

CI.MeasType Position:Angular Encoder

CI.AngEncoder.Units Degrees

PhysicalChanName Dev4/ctr0

CI.Encoder.DecodingType X4






Message Edited by JFKAGroup on 05-28-2008 12:09 PM
0 Kudos
Message 3 of 6
(2,180 Views)

Hi JFKAGroup,

I’m not sure if you’re getting that error due to any Borland interaction or not. There are a few KBs that talk about support for Borland/Delphi. I’d recommend checking those out as you mentioned using Borland.


How Can I Use The NI-DAQmx ANSI C Function Library With Borland C and Delphi?
Can I Make NI-DAQmx Calls From Borland Delphi?

Whenever an issue arises from a program, I strongly recommend you try the NI shipping examples as a starting place to eliminate any incorrect uses of functions, etc. Please navigate to the folder shown in this KB. I recommend the example in the Counter » Measure Position folder called “Angular Position-Buff Cont”.

Please post the results of running that example. Once that is working, then you can build upon it. I hope that helps!

Hopefully that’ll be a good place to start. Post back with further questions.

Mark E.
Precision DC Product Support Engineer
National Instruments

Digital Multimeters (DMMs) and LCR Meters
Programmable Power Supplies and Source Measure Units
0 Kudos
Message 4 of 6
(2,167 Views)
Ok I figured out what was wrong with my previous setup/configuration. When using the DAQmxCfgSampClkTiming function I needed to use only "PFI0" and not the full "Dev4/PFI0" to have this thing work.

But now I've come accross the following problems.
1-No matter what I seem to set the acquisition frequency this does not seem to affect the rate at which the Angles are acquired. Perhaps this is related to the next problem.

2-It seem the acquisition of the angle only occurs when I have movement on the encoder. If I do an acquisition and there is no movement I get the usual: Some or all of the samples requested have not yet been acquired.... If I go create movement I get the data. If I consider problem 1, when I do some acquisition with the DAQmxReadCounterF64 and I calculate the time it would take to sample N data at a rate of M, the function returns much more quickly than it should with the correct amount of samples.

My application requires I determine the rotation speed in function of the time, and from what I've seen so far I cannot consider that the data is acquired at fixed time intervals which is the case with analog data acquisition (this works just great so far).

To get around problems 1 and 2 I figured I would initiate the encoder task with DAQmxCreateTask,DAQmxCreateCIAngEncoderChan and DAQmxCfgSampClkTiming to do very small acquisitions (2samples) and regularly call DAQmxStartTask, DAQmxReadCounterF64 and DAQmxStopTask but I get the side affect that the position is constantly being resetted to zero with each acquisition which makes this approach impossible for my application.

I've worked with Analog Inputs/Outputs Digital Inputs/Outputs and all of these work fine; I am just having trouble with the Encoder Functions.

Thanks
0 Kudos
Message 5 of 6
(2,158 Views)

Hi JFKAGroup,

It sounds like you might be using the encoder signal itself as the sample clock, rather than an external signal. For buffered acquisitions, an external sample clock is required. The acquisition frequency you may be setting could be just for buffer allocation purposes. Try using an external clock.

I’d really like for you to get more help, but baseline results are needed to know how to approach the situation. Please run the attached code and inform the community of the results.

Hopefully that’ll be a good place to start. Post back with further questions.

Mark E.
Precision DC Product Support Engineer
National Instruments

Digital Multimeters (DMMs) and LCR Meters
Programmable Power Supplies and Source Measure Units
0 Kudos
Message 6 of 6
(2,133 Views)