03-23-2009 03:32 PM
Hello,
I'm trying to hook up and control only the direction of a 12V DC geared motor using a Critical Velocty H-Bridge microcontroller which requires digital input from 3 lines of our NI USB 6008. I have been able to use the DAQ assistant to power the motor using 3 separate assistant functions to execute the 1 task of controlling the high/low output of each line separately, but this requires that I input manually the needed output of each line; i.e. 3 boolean switches must be selected the correct way to move the motor in one direction or the other.
What I aim to do is use a boolean control to cause the motor to turn clockwise or counter-clockwise but am having trouble converting this boolean control into the data form that the DAQ assistant requires. Do I need to take my input and then build the 1x3 array needed to drive the motor? But then how do I let the DAQ know that i want each value in the array to control a different digital output line of the DAQ?
Thank you for your help!
Solved! Go to Solution.
03-23-2009 03:40 PM
03-23-2009 06:36 PM
No problem. Specify your channels as shown in the following VI, build your digital array, and write it. I'm not a fan of any kind of Assistant since I like to know exactly what my code is doing, so this is not configured using the DAQ Assistant, but it should tell you what you need to know.
The keys here are:
Channel: Dev1/port0/line0:2 (specifies that you'll be writing to lines 0, 1, and 2...put your actual hardware lines in here)
"One channel for each line" (specifies that each of the lines above is its own separate channel, so that the number of channels in the task will agree with the number of Boolean elements in your array)
Hope this is helpful. You should also take a look at the shipping examples that come with LabVIEW, and consult the LabVIEW help for additional information correct syntax for specifying DAQ channels.
03-24-2009 03:22 PM
Hello DianeS,
I'm working with LabVIEW 8.0 so I could not open the 8.6 format that the VI you posted is written in. I'm also very new to LabVIEW so I'm having trouble understanding your key points without the visual VI in front of me. I'm trying to work on it now though, but any additional information would be greatly appreciated.
Thanks for your time,
Leanne
03-24-2009 11:18 PM
Hi Leanne,
Try this. If you have further questions, give a holler. Also, please do look at the DAQmx examples that ship with LabVIEW...under "Help", click on "Find Examples".
Diane
03-26-2009 03:50 PM
Hello DianeS,
Thank you for all your help! After visually seeing an example of the basis for our code I can better understand how LabVIEW works. I know see that the DAQ programming was not where I was going wrong, it was the use of the different programming structures.
I do have one more question about using a case structure. Right now the code that you wrote has a boolean input into the structure, but I should be able to change that to include as many cases that I want, correct? I thought that if I want to have more than 2 cases within the structure, I could just use a numeric control and then assign each case to a number in the loop of the case strucure. However, the data types are different and can't serve as an input. Do I need to convert the data before entering it in the case structure?
Thank you again!!
Best,
Leanne
03-26-2009 06:09 PM
Hi Leanne,
I'm glad my little example was helpful!
You are quite right that a case structure can have many different cases, depending upon what you use as a case selector. (in the vi I posted, the "case selector" is the Boolean that you asked about) If you use a number as a case selector, you can have an infinite number of cases. You can also use a string as your case selector, or an enumerated constant (my personal favorite).
I am not entirely certain what you mean when you say "the data types are different". The data types of what?
Diane
03-27-2009 09:39 AM
I thought that the different wire colors represent different types of data or the number of bits running through that wire. What I meant to say is that the wire coming out of a numeric control is orange, but the wire going into the case structure cannot be. Is this true?
Thanks,
Leanne
03-27-2009 11:09 AM
Why not give it a try and see what happens? 🙂
I'm not trying to be difficult -- I'm trying to encourage you to experiment and try things (particularly when they're really simple) and then ask questions if they don't work or behave strangely. That's the best way to learn LabVIEW.
In answer to your question, yes, a case structure will work fine with a DBL as the case selector. You'll get a coercion dot, though, because LabVIEW wants the numeric data type for a case selector to be I32.
Diane
03-28-2009 12:01 AM
DianeS wrote:
In answer to your question, yes, a case structure will work fine with a DBL as the case selector. You'll get a coercion dot, though, because LabVIEW wants the numeric data type for a case selector to be I32.
I wouldn't quite say that. Wiring a double to a case selector will probably work fine in most cases, but you can't guarantee it always will. A floating point number in a computer doesn't always precisely define an integer. There can be roundoff errors in the internal representation of the number. So you could run into problems whenever you are trying to comparing a double representation number with another number for equality. It is always better to define the control to be the matching datatype and stay away from the floating point number when working with a case selector.