LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Newbie needs help with PWM, DAQ, good reference guides, and life

Hey everybody,

THE SETUP:
I am a senior electrical engineer at the University of Alabama who is in the middle of a senior design project, trying to balance an inverted pendulum. I have been given labview as my programing environment; I have a PCI 6229 M DAQ card (that has yet to be installed on my machine by the powers that be.) What I will soon have to do is take the information off 2 encoders, run that through my DAQ card, through a contoller, and send out a PWM singal to drive a motor back and forth.

THE PLEA:
I do not know where to start. I have been through some of the startup materials and I can happily convert Fahrenheit degrees to Celius degrees, but I need a little more than that. I have to program a PWM algorithmn and convert the encoders signals into meaningful information. Where can I find examples that might point me in the right direction? Can anyone recommend any good reference materials on the basic (or advanced) LabVIEW applications? Any help will be greatly appreciated.

peace

Eric
0 Kudos
Message 1 of 27
(5,113 Views)
I would recommend that you buy this book :

"LabView 7 Express" by Robert H. Bishop, NI

and use Express VIs for analog input and analog outputs.

it's not really that hard, just keep reading and experimenting.

good luck,

Ed
0 Kudos
Message 2 of 27
(5,088 Views)
Eric,
Some general info that might be of some help.
Installation should be in this order:
1) Software (LabVIEW)
2) Driver (NI-DAQ 7.3.1 is the most recent version) If you don't have it on a CD, you can get it free here:
http://digital.ni.com/softlib.nsf/webcategories/85256410006C055586256BBB002C128D?opendocument&node=132060_US
3) Hardware (6229)
If LabVIEW is installed before the driver, NI-DAQ will automatically install DAQ examples into LabVIEW's Example Finder (Help>>Find Examples). You will probably want to take a look at some of the DAQmx counter examples. There are already examples that perform frequency and period measurements, as well as pulse train output. Good Luck!
-Alan A.
Message 3 of 27
(5,076 Views)
Eric,
1. Stay on the folks who are going to install the DAQ for you. It is a simple process - I just did it myself and I'm relatively clueless when it comes to PCs, take it over yourself if you must. Don't let others bottleneck your process, take the lead whenever necessary. If you step on someones toes, politely say "excuse me, I was just trying to help." 😉
2. Read all the spec sheets on all of your equipment, be mindfull of your equipment's limitations. 🙂 It will save you valuable time later . . .
3. Read the manuals on your DAQ, be mindful of its limitations (what can I say, it was worth repeating). It will save you valuable time later . . .
4. Work on it everyday, especially in the beginning of the project. You have some formidable learning curves ahead, get moving now! Tell your friends and loved ones you care about them but that you will be busy for the next couple months and can't be as much fun as you used to be. My wife was beside herself when I did my senior project . . .
5. Know when the point of diminishing returns has been reached and take a break. I like walking best. And above all else drink lots of pure, fresh water. Avoid fast food, don't smoke anything, don't drink alchoholic beverages more than once a week and then in moderation, wash your hands often. These kinds of things are easy to forget when you are working on a project, but you don't want to get sick, its a waste of valuable time.
6. I think you might need to study PID stuff, control loops and the like and how LabVIEW can help you. Sounds like Alan's post will get you started. For the most part, you will fall into a groove and what you need will come to you when you need it physically and intellectually. Any technical advice or personal ideas should be analyzed in detail, if you don't understand it, it could hurt your project.
7. Don't be afraid to start over . . . its always easier the nth time.
8. If you get stuck, post to this group. You'll probably figure it out as you try to explain it textually, that's what always seems to happen to me. 😄
9. Press on!

-Rick
Message 4 of 27
(5,055 Views)
Eric,

Encoder signals: your board has 2 counters and both can interface directly to a quadrature encoder. The "measurement" you get can be a signed quadrature position, including scaling into physical units like mm, rad, deg, or whatever.

PWM: your board can use a counter to generate a PWM signal. It's possible to load in a new set of freq & duty cycle parameters on the fly to change the duty cycle without interruption of the pulse train.

The rest of this post is kind of an early warning. You've got some weeks of learning basics about LabVIEW syntax and DAQ programming before these things would be an obstacle. But they'll probably be rearing their heads eventually.

Problem: Your board only has a total of 2 counters. If you use them for the 2 encoders, you can't also generate PWM. Maybe part of the project is for you to design and build some interface circuitry. I think you'll be best off if you use the counters of the 6229 for the encoder measurements and find another way to generate your control signal. Analog output seems natural if that's allowed.

Other problem: this is supposed to be a real-time control system. Unless you're using LabVIEW Real-Time, you'll be running under Windows. So your control loop will *not* always run at a constant rate, and is at risk of becoming unstable as a result.
Personal experience: I had a motion system designed for LabVIEW real-time that needed to track a smooth periodic signal (not exactly a sinusoid, but not too far off). The device moved about 3-4 feet on a linear track at a 1-2 Hz rate. Under LabVIEW RT, it controlled nicely with a 500 Hz control loop rate. When I tried running the same program under standard LabVIEW in Windows, the motion would become erratic -- smooth for a while, then a hesitation and an extreme adjustment. I doubt it could have kept an inverted pendulum from falling.
I didn't need or try to optimize it for running under Windows so I suspect there were ways to improve it significantly. But there'd probably always be a risk of the motion going erratic or unstable at any time. At a minimum you'd want to close other applications, keep your actual control loop in a high priority thread, and put your user interface (inputs, display) in a separate thread.
There's a bunch of info on threads, priorities, and execution systems here on ni.com when you are far enough along to need it, but that'll probably be a few weeks.

Good luck with the project. You'll be able to find quite a bit of info by searching both the forums and the official support resources here on ni.com, then posting specific questions you can't find answers for.

-Kevin P.
CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
Message 5 of 27
(5,039 Views)
I am also a NEWBIE. I have a PCI 6025E DAQ card. I am trying to generate and control a PWM signal of between 0 to 10 Volts. I have been through numerous examples. All of them are complicated. Can you give me a very basic simple easy PWM for me. I just need a SIMPLE PWM that generates and control 0 to 10 VOLTS. THANKS!
0 Kudos
Message 6 of 27
(4,971 Views)
Well LV1958, a SEARCH IN LV HELP finds a PWM-Analog Output vi that works for the PCI-6025. Go figure.
~~~~~~~~~~~~~~~~~~~~~~~~~~
"It’s the questions that drive us.”
~~~~~~~~~~~~~~~~~~~~~~~~~~
0 Kudos
Message 7 of 27
(4,962 Views)
A bit more advice, if you are up for it.

LabVIEW allows you to easily get up and running with virtually no program structure. However, this is disastrous down the road. Take the time to design your system before you start programming it. A few hours now can easily equal days later. Remember, LabVIEW is a data flow language which makes multi-threaded operation trivial. Unfortunately, that means you can get race conditions trivially. You will want to use parallel loops to solve this problem (one for control, one for UI, ...). Make sure you synchronize them cleanly. Get a good book on LabVIEW to help you out.

Strange as it may sound, I don't recommend using Express VIs for this application. You will be pushing the limits of your hardware and Express VIs are typically inefficient. Use them to write your original code (saves lots of time and looking up references on how to do things), then convert them to regular VIs and pare the code down to just what you need.

Good luck! Let us know if you need more help.
0 Kudos
Message 8 of 27
(4,934 Views)
LV1958

There are numerous references on our site in regards to PWM. I would suggest you start there instead of posting to every link talking about PWM to try and get help. I think many of the suggestions by Analog2DigitaKid an others should get you started. A little reading will save a lot of time.

StuartG
0 Kudos
Message 9 of 27
(4,932 Views)
Hello,

I would like to thank everyone for all their help; we are making good progress. The encoder acquiring linear data is working perfectly and the angular encoder should be up and running soon. However we have run into a road block with the PWM. Since we are using both onboard counter for the encoders we are attempting to implement a PWM using an Analog output. I wrote a little .vi using the basic square waveform vi outputting to an analog channel. It worked fine, with a little bit of attenuation, for low frequencies (<100Hz), but I need an output on the order of 20kHz. at those frequencies my output was a triangle wave. I have this sneaking feeling that the some hardware cannot keep up with the frequency requirement. Next we tried the same approach but using a digital output channel. Here we could get the high frequency but when we stopped the program and adjusted the duty cycle nothing happened to the waveform and when we changed the duty cycle to 75% or higher all output vanished. So here are my questions.

1. Is this programming logic seem sound?
2. Is my problem, when I use the analog output channel, running the program under Windows? Would I be better served to get my realtime setup in place and then rerun these tests?
3. Has anyone ever done this sort of thing without a counter and made it work? All I need is a 5V 20kHz squarewave output with a duty cycle that can be changed on the fly without interrupting the pulse train.

I have been looking at the analog PWM example VI's. I just thought the simple one I described would save processor resources, perhaps my answer lies with one of those.

Thanks again for all your help thus far.

Eric
UA EE Senior
attached is the analog file described above
0 Kudos
Message 10 of 27
(4,895 Views)