Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Generating a PWM using USB 6008

Hi,
I am a student working on a project in which I am generating a PWM using the USB 6008 with the NI-DAQmx
sub-vis. Using a Write to Digital Channel sub-vi, I am able to generate a PWM by passing true or false boolean values to it. The vi uses the Wait until millisecond timer to control the duration of the high and low pulses. But when I graph the PWM using an oscilloscope, the graph does not look anything close to a uniform PWM that I am trying to generate.

Our goal is to control the motion of a DC motor using the PWM. The PWM is supplied to a motor controller which is connected to a power source and the motor. When I supply the PWM to the controller and power up the motor, it stalls from time to time and I am not able to control how fast or slow the motor is moving. So, I am pretty much sure that the PWM is not uniform. I was told that software-timed method of generating PWM is not the best way to go but I don't think there should be this much of a signal distortion that I don't see two similar pulses consecutively.

I have attached a screenshot of the oscilloscope so that you can have an idea of how bad the signal is.

Thanx.

Message Edited by Subodh on 09-28-2006 11:06 AM

Message Edited by Subodh on 09-28-2006 11:07 AM

0 Kudos
Message 1 of 19
(25,407 Views)

Hello Subodh,

I have written and attached code (in LabVIEW 8.0) for the USB-6008 that also generates an adjustable PWM on a digital line.  I output 100 points per cycle at 1ms per point so the output waveform is only 10Hz.  You can give it a shot if you want but I wouldn't expect much better performance.  Based on how much other code is in your loop and how many other applications are running on your computer, you can expect some serious jitter in your loop times.  This is not a limitation of LabVIEW or the USB-6008 but of your operating system.  For this reason, as you have already heard, the USB-6008 is not designed for this kind of application.  Your best option is to use the counter functionality on one of our USB M Series devices or the PCI-6601 counter card. 

Best Regards,

Jeff Tipps
Applications Engineer
National Instruments

 
Message 2 of 19
(25,377 Views)
Thanx Jeff.
I should have mentioned this earlier so this is my mistake. We are using Labview 7.0 and I am wondering if the vi in Labview 8 .0 is backwards compatible. Is there any way to reduce this "jitter" caused by the operating system? We have progressed far into the project and being in this stage in the project, I would like to try all of my options with this method before I start to ponder over other hardware for generating PWM. 

Thank you for your help once again.

Subodh

0 Kudos
Message 3 of 19
(25,338 Views)
To minimize jitter, then shutting down all unused services in Windoze would help but not toally eliminate it.
 
~~~~~~~~~~~~~~~~~~~~~~~~~~
"It’s the questions that drive us.”
~~~~~~~~~~~~~~~~~~~~~~~~~~
0 Kudos
Message 4 of 19
(25,334 Views)
An upgrade to LabVIEW might help as well. Since 7.1, LabVIEW has included a structure called a timed loop.
0 Kudos
Message 5 of 19
(25,330 Views)
Hi Subodh,

VIs in LabVIEW can be saved one version back.  For example a VI made in 8.2 can be saved to run in 8.0. I have LabVIEW 7.0 and newer installed on my computer, so I went ahead and saved Jeff's VI for you in LabVIEW 7.0 by opening in each preceding version LabVIEW. Let me know if you have any further problems, so I can make sure to stay on top of your issues.

Have a great day,

Michael Denton

Message Edited by Mike_D on 10-04-2006 12:07 PM

0 Kudos
Message 6 of 19
(25,311 Views)
Thanx everyone who have responded (and read the post but did not respond). And yes!!! The PWM is not as distorted as it was before...Just one more questions regarding the vi. Is there a way I could change the frequency of the PWM? When I transmitted the PWM to the motor controller, there was no response from the motor except for a second of movement which happened once in a while. I am guessing it is because the frequency of the PWM is too low. I was looking at the vi and thought decreasing the number of points per cycle would increase the frequency. But that did not help. Ideally, I would like to have the frequency running at 40-60 Hz.

Best
Subodh

0 Kudos
Message 7 of 19
(25,250 Views)
Hey Subodh,

The question will be how much fine control you need over the PWM signal. When you say you decreased the number of points, what exactly did you do? I lowered the Factor the duty cycle was multiplied by to 10. I also lowered the Subtraction that determines the number of low values to 10. With both of these set to 10 I was able to generate a 100 hz signal. I just wanted to verify you were able to do this. The difficulty with this is that you would only have the ability to change the PWM from a duty cycle of 0.1 to 0.2, you would not be able to set it at 0.13 for instance. Please let me know if you need any further help increasing the frequency of your PWM.

Have a great thermocouple thursday,

Michael
Applications Engineering
National Instruments
Message 8 of 19
(25,240 Views)
Thanx MIke _D,
When I said that I decreased the number of points, I lowered the value from which the N-high values were being subtracted.
 
This is what I think the vi is doing to create the PWM: The duty cycle gives the number of high values. It is subtracted from 100 to give the number of low values. The value 100 used in the subtraction is (I think) the intervals into which one  time period is divided. So, 40% duty cycle would mean 40 of the 100 divisions would be high and the rest would be low. Since each division is executed for 1 ms(using the millisecond timer), the time period is 100 ms and this means 10 Hz. So, reducing the 100 to 50 would give a time period of 50 ms and 20 Hz frequency.
 
Please correct me if I am misunderstanding the working of the vi.
 
Yes, I was able to repeat what you had done. But for our project, we need the frequency to be around 40-60 Hz since our motor behaves strangely at very low frequencies. Ideally we would like to vary the frequency from  0- 100 Hz. Is there any other way I can modify the program to increase the frequency?
 
Best
Subodh
 
0 Kudos
Message 9 of 19
(25,180 Views)
Hey Subodh,

It seems like you have a good grasp of what the VI is doing.

The main problem with changing the frequency to higher speeds, is that your loop is already running as quickly as software timing will allow. So the only way to speed it up is to run fewer loops. We could create an enum, which will allow you to set the frequency you want to run your program at by changing the number of intervals that are calculated. I attached code that shows how you could set this up. I didn't put in the value for every case in the case structure, but I think you can get the idea from how it is set up.

The 6008 just doesn't have any hardware correlated digital output, so it isn't possible to make this work with a hardware counter.

Let me know if I can help you further with this issue,

Have a great weekend,

Michael
Message 10 of 19
(25,157 Views)