LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting gray code to binary/decimal when using port0

Good day everybody,
 
I'm currently doing the final touch to a project I did for my 3-month traineechip abroad (I'm a French student engineer). I'm getting the date from a axial flux motor my supervisor wants to drive so as to reduce noise, therefore vibrations : 4 piezo sensors under the housing, another force sensor for measuring the torque, 3 PWM current converters, and a 12bit gray encoder for speed & position.
 
Everything is eventually working, after months trying to understand the DAQmx philosophy Smiley Tongue. However, I'm acquiring the position using port0, thus getting a number, which I log in a spreadsheet for a later conversion via a lookup table. It's the only way I found to log it, as I couldn't log directly the gray code (don't know how to work with that data type). This is not a real issue.
 
What's missing now, is a real time display for the speed. I previously drew a diagram that converts gray code into binary and finally decimal, but this used a express VI gathering 12 digital lines that I could isolate to do some logic. This worked pretty well, but once I include it to my master VI an error appears :
 
Error -200587 occurred at DAQmx Start Task.v
 
Possible reason(s):
Requested operation could not be performed, because the specified digital lines are either reserved or the device is not present in NI-DAQmx. It is possible that these lines are reserved by another task, the device is being used through the Traditional NI-DAQ interface, or the device is being reset.
 
If you are using these lines with another task, wait for the task to complete.  If you are using the device through the Traditional NI-DAQ interface, and you want to use it with NI-DAQmx, reset (initialize) the device using the Traditional NI-DAQ interface. If you are resetting the device, wait for the reset to finish.
 
Device:  Dev1
Task Name: _unnamedTask<0>
 
I undestand the conflict between these 2 tasks that use the same inputs. But using port0 as a task input, I can't islolate the different lines to do the logic that could convert it to binary/decimal.
 
Thanks for your help,
 
Gabriel
 
PS : I'm using a NI 6259.
0 Kudos
Message 1 of 6
(6,160 Views)

Hi,

From your statement, "I previously drew a diagram that converts gray code into binary and finally decimal, but this used a express VI gathering 12 digital lines that I could isolate to do some logic.This worked pretty well, but once I include it to my master VI an error appears". This is what i can infer.

The problem you are facing seems to be a conflict between Traditional DAQ and DAQ mx device drivers.

In your code, you must be trying to use both trad DAQ and DAQ mx functions.

so , just check your code and build it entirely in either trad DAQ or DAQ mx.

Hope this helps

Regards

Dev

 

 

Message 2 of 6
(6,159 Views)
That's what I thought. I don't know how to program with DAQmx what I did with the express VI : I created a task via "Measurement & automation explorer", and the data I get is wether waveform, wether U32... I don't know how to isolate each digital line to do some logic on it.
0 Kudos
Message 3 of 6
(6,141 Views)

Hi,

Post your code with a little pointers as to what you want to do?, where?, in the code

we should be able to suggest better.

Regards

Dev

 

 

0 Kudos
Message 4 of 6
(6,134 Views)
I apologize for the delay : I was pretty busy in this Chritmas time. Here are the VI's you requested, for which I added some comments and context help for any user in the future ; I hope it will be useful. You might notice an improvement in the use of the language within the next messages : my supervisor wil carry on this project as I am going back to France to finish my studies. In any case your help will be very valuable, for his project, in which I dealt with the data acquisition, as well as for my own training (I will keep on following this thread).
 
Thanks for you support,
 
Gabriel, French student engineer
0 Kudos
Message 5 of 6
(6,109 Views)
Hello Gabriel,

It looks like from your VI that you're most of the way there.  I'm a little confused about what 'gray code' is, but here is my understanding of what you are trying to do (correct me if I'm wrong):

In the 'Encoder' task on your block diagram, you are reading from a digital port.  Right now, you receive that number as a U32 (unsigned 32-bit integer), which is actually in 'gray code'.  You are trying to convert this gray code U32 integer into a useful decimal number that represents speed.  You have created an algorithm that does this, but you need a way to access the value of each digital line in the port from the U32 number that you are reading from the DAQmx Digital Read VI.  Does this sound right?

For some background, a port is simply a collection of eight digital lines.  A line can be either 0 (off) or 1 (on).  When you group these lines together into a string of 0s and 1s, you get a binary number, which also has a corresponding decimal representation.  That decimal representation of the status of the digital lines is reported by the DAQmx Digital Read VI as either a U8 (1 port = 8 lines = unsigned 8-bit) integer, a U16 (2 ports = 16 lines = unsigned 16-bit) integer, or a U24 (3 ports = 24 lines = unsigned 24-bit) integer.  So, the status of each of the lines is actually coded into the numbers being outputted by the DAQmx Digital Read VI.  To get the status of each line, all you need to do is convert the U32 integer into an array of boolean indicators (basically an array of on/off lights that represent the status of each line).  Under the Boolean Palette in LabVIEW 7.1, there is a function called 'Number to Boolean Array' that does this conversion automatically.  From there, you can use the functions on the Array Palette, such as the 'Index Array' function to manipulate your array of booleans and perform your conversion. 

I hope this helps!

Regards,
Travis Gorkin
Applications Engineering
National Instruments
www.ni.com/support
0 Kudos
Message 6 of 6
(6,082 Views)