Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Counter and Voltage measurements

I am trying to demonstrate / develop a capability that requires simultaneous measurement of linear position and 3 voltages using a USB NI 6215 data acquisition device. I have a quadrature encoder installed for the position measurement. I am using Visual Basic 6 to demonstate the value of these measurements. I would like to make the function calls to use the counters in the 6215 to read a quadrature encoder. However, my attempts to set the X1 mode in the call to "DAQmxCreateCILinEncoderChan" have not been successful. I tried searching the NI application database and could not find any specific information. Is it possible now? I know that it was possible 15 years ago, but I'm not sure the capability has been enabled in the latest Windows device driver.

 

Ideally, I would like to read an encoder position together with a set of 3 voltage measurements. I have a task defined to read sets of 3 voltages at 1000Hz. Can a position read be added to this task or do I need to define a separate task. If a separate task is required, how are the two tasks synchronized so that I get a position reading for each set of 3 voltage readings?

 

I need to do this in Visual Basic 6. I've written a fair amount of code for this custom application and I cannot justify rewriting into another language in order to do what should be simple and straightforward.

 

Thanks, dgon.

 

0 Kudos
Message 1 of 10
(3,755 Views)

Hi dgon,

 

Because the function calls for NI-DAQmx in C and VB6 are essentially the same, you can refer to the NI-DAQmx C Reference Help (found under Start » All Programs » National Instruments » NI-DAQ). According to this help, you should be able to set the Decoder Type to X1 by passing the value DAQmx_val_X1 as the decodingType argument. If you have already done this, could you tell us more about the error message you are getting?

 

As for your second question, if you want to correlate your voltage input data with you encoder measurement, you will need to synchronize 2 tasks (AI task and Counter task) by sharing a common Start Trigger and a common sample clock. To find more information on how to synchronize multiple tasks on your M-series, you can refer to the following DevZone articles below:

 

Synchronizing USB Data Acquisition - From One Device to Multiple Systems

M Series Synchronization with LabVIEW and NI-DAQmx

 

To summarize, you will need to implement the following in your code:

1. Configure the AI task

2. Configure the Counter task with the ai/SampleClock as the sample clock source and ai/StartTrigger as your Arm Start Trigger source (this is not the same as a Start Trigger).

3. Start the Counter task before the AI task.

4. Start the AI task.

 

Because the DAQmx code is very similar between C and VB6, I also recommend you take a look at some of our DAQmx C shipping examples on synchronization in C:\Documents and Settings\All Users\Documents\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Synchronization\Multi-Function\ContAI-Read Dig Chan. Note that this particular example does not share a sample clock, however, the idea is there and should be a good place to start.

 

I hope this helps.

S_Hong
National Instruments
Applications Engineer
0 Kudos
Message 2 of 10
(3,742 Views)

I thought that I reply'd to this yesterday, but I'm not sure it was posted so I'm responding again.

Getting the USB-6215 to read position from the encoder is my 1st priority, after that's working I'll work on the simultaneous reading of voltage and position.

 

I modified an example program that NI provided, a counter example and changed the function call for the encoder function. I've pasted in the appropriate code snippet below.

When I make a call to the function " DAQmxCreateCILinEncoderChan ",

I get an error message: "Error: -200077 Measurements: Requested value is not supported value for this property".

This doesn't tell me which value nor which property it is talking about.

 

Before running this I verified that the counter is working and that I can configure the counter as a simple count-up counter. Also that it can count pulses from the quadrature encoder that I'm using, just not in quadrature mode. As you know, that is a different function call.

 

'**********************************************************************

    ' Create the DAQmx task.
    response = DAQmxCreateTask("", taskHandle)
    DAQmxErrChk response
    taskIsRunning = True
'*********************
        in_per_pulse = 1
        enc_start_pos = 0#
'        X1_mode = 10090
        decode_mode = DAQmx_Val_EncoderType2_X1
'        Inch_mode = 10379
        output_mode = DAQmx_Val_LengthUnits3_Inches
'        output_mode = DAQmx_Val_LengthUnits3_Ticks
       
'*********************
    ' Add a counter input channel to the task.
'    response = DAQmxCreateCICountEdgesChan(taskHandle, physicalChannelTextBox.Text, "", _
    edge, initialCountTextBox.Text, countDirection)
'    DAQmxErrChk response

'THE FOLLOWING LINE GENERATES THE ERROR

   response = DAQmxCreateCILinEncoderChan(taskHandle, "Dev2/ctr0", "", _ 

                    decode_mode, False, 0#, _
                    0, output_mode, in_per_pulse, enc_start_pos, "")
    DAQmxErrChk response

' **********************
 

0 Kudos
Message 3 of 10
(3,723 Views)

Hi dgon,

 

It looks like some of the parameters you may be passing to this particular DAQmx function may not be valid. According to the DAQmx C Reference Help, DAQmx_Val_EncoderType2_X1 is not a valid option, nor is DAQmx_Val_LengthUnits3_Inches.

 

Could we try running the following function instead?

DAQmxCreateCILinEncoderChan(taskHandle,"Dev2/ctr0","",DAQmx_Val_X1,0,0.0,DAQmx_Val_AHighBHigh,DAQmx_Val_Inches,1,0.0,"")

S_Hong
National Instruments
Applications Engineer
0 Kudos
Message 4 of 10
(3,710 Views)

By the way, the DAQmxGetExtendedErrorInfo function should tell you what value and property the error is talking about.

 

Brad

---
Brad Keryan
NI R&D
0 Kudos
Message 5 of 10
(3,707 Views)

S_Hong,

 

The contact you suggested, " DAQmx_Val_X1", is not a valid constact for VB6. Yes, it is listed as the constant in the function reference documentation, but the actual constant in VB6 is the value I used. That is: "DAQmx_Val_EncoderType2_X1". I found this myself, somewhat accidentally by VIEWing the object browser in the VB6 environment. I saw this also mentioned in one of the message threads on the board when I first browsed here a few days ago. You can use the object browser to view the constants that are contained in the library .tlb file.Using the Print statement in an interactive window allows one to see the actual value associated with the constant. I used both methods to determine what parameters to give the encoder function call. None worked.

The fact that the constants referenced in the NI C language reference are not accurate leads me to suspect that there may be other inaccuracies in the documentation. For example, in the function call syntax itself?

In the example you suggested, you included a constant "DAQmx_Val_AHighBHigh" before the constant for units, "DAQmx_Val_Inches". However, the syntax does not show any such parameter. The C language reference that I have, see below, shows the parameters for ZidxPhase and next is units. There is nothing about the AHIghBHigh, what's the correct syntax and is that my problem?

 

Thanks, Dgon

 

DAQmxCreateCILinEncoderChan

int32 DAQmxCreateCILinEncoderChan (TaskHandle taskHandle, const char counter[], const char nameToAssignToChannel[], int32 decodingType, bool32 ZidxEnable, float64 ZidxVal, int32 ZidxPhase, int32 units, float64 distPerPulse, float64 initialPos, const char customScaleName[]);

 

0 Kudos
Message 6 of 10
(3,698 Views)

S_Hong,

 

Sorry, I forgot to add; That if I pass the constant that you suggested to the encoder function call, I get a Visual Basic error message,

"Value not defined". Whereas, if I pass the constant listed in the VB Object Viewer, it will compile without a Visual Basic error message, but then I get a National Instruments runtime error message.

 

dgon

 

0 Kudos
Message 7 of 10
(3,697 Views)

Brad,

 

The error handler that you mentioned would be very helpful. I've thought about modifying NI's handler because it doesn't give me enough information. Is this error handler available to Visual Basic 6? I haven't seen it. If it's in the C library, then I'd need to add extra code to enable the VB6 program to compile with the appropriate C library.

 

dgon

 

0 Kudos
Message 8 of 10
(3,696 Views)

Hi dgon,

 

It seems like you are right and that there are some differences in the values you can pass as parameters for the different DAQmx function calls. This is despite the fact that most DAQmx functions and parameters are identical to those in C. In any case, I did a bit of digging into the VB Object Browse and if you actually search Daqmx » DAQmxCreateCILinEncoderChan, you should be able to click on the DAQmxEncodeZIndexPhase1 parameter to see its members. One valid option for this parameter is DAQmx_Val_EncoderZIndexPhase1_AHighBHigh. Now although you are not using any Z index, this parameter needs a valid value. I believe if you try the following line, it should fix your problem.

 

DAQmxErrChk DAQmxCreateCILinEncoderChan(taskHandle, physicalChannelTextBox.Text, "", DAQmx_Val_EncoderType2_X1, 0, 0, DAQmx_Val_EncoderZIndexPhase1_AHighBHigh, DAQmx_Val_LengthUnits3_Inches, 1, 0, "")

 

Let us know if this is the solution to your problem.

S_Hong
National Instruments
Applications Engineer
0 Kudos
Message 9 of 10
(3,660 Views)

S_Hong,

 

Thank you for the information you provided on this problem last November. I'm sorry it's taken me so long to respond, with only a couple days notice I had a 3 week work trip to eastern Siberia followed by a mandatory 2 week vacation break around Christmas. Now, I'm just catching up with critical items at my desk and will be restarting my work with the NI card and the counter / encoder configuration. Before I left for Siberia, I was able to verify that the information you provided did allow the needed function calls to compile and run, but I was did not have time to verify that the function call was operating properly and that correct information was being returned to the program. As I said, I expect to continue work on this next week and, hopefully, can confirm a successful solution at that time.

 

Thanks again, dgon.

 

0 Kudos
Message 10 of 10
(3,531 Views)