LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Generate PWM signal with 1.5 ms pulse width

Solved!
Go to solution

Hello all,

    I am working on a project where I need to generate a PWM with a pulse width between 1.3 and 1.7 ms to control a continuous rotation servo.  LabView is communicating with an arduino Uno microcontroller through LINX.  My initial plan was to use the wait milliseconds function in LabVIew to do this.  I would set the PWM pin High, wait 1.3 or 1.4 ms then set the pin low for 20 minus the pulsewidth ms.  before repeating.  This is the way that I gnereate a pulse width using the Arduino IDE, so I thought I would be able to do something similar here.  However, as I am sure is already evident to anyone reading this, the wait milliseconds finction in LabView only accepts integer inputs.  Arduino IDE is similar, but there is a delayMicrosecond function that can be used, so if I want 1.4 ms I can just use 1400 us snf then convert it to ms for the 20 minus part.  How can I do something similar in LabView?   Also. when I run the program as is with a 1 ms pulsewidth I get some strange behaviour.  It actually generates a PWM signal somewhere between 0.75 and 1.25 ms and with a period of between 50 and 54 ms, it changes in a pattern every about half a second.  I am using LabView 2014.  Any Ideas?

 

Chris

0 Kudos
Message 1 of 8
(4,995 Views)
Solution
Accepted by topic author christopherbrown0317
You can't get that sort of resolution with Windows and whatever delay you specify will have considerable jitter due to Windows. If you can pass the values with Linx and use the arduino to control them, stick with that.
0 Kudos
Message 2 of 8
(4,972 Views)
Solution
Accepted by topic author christopherbrown0317

Timing is done by Hardware.  The Timing functions that come with LabVIEW depend on the underlying PC (or Mac) and its operating system, which can introduce unexpected and non-trivial delays at any time.  The Delay functions in LabVIEW are not meant for "precision" work, hence they have a millisecond resolution -- rather, they are mainly intended to slow down sections of code so that parallel loops have a chance to operate without some routine hogging all of the CPU cycles.

 

To get sub-millisecond timing, you need "additional hardware" that has on-board clocks, counters, and timers.  NI's myDAQ (relatively inexpensive USB-powered Data Acquisition and Control peripheral NI makes for students) has a counter-timer with a MHz clock that could easily deliver the type of pulses you need.

 

Bob Schor

0 Kudos
Message 3 of 8
(4,964 Views)

Thanks to both of you.  I was afraid of that.  I will just have to find another way I guess.  Thanks again though.  I will look into that DAQ though, not sure if it will work for what this application is goint to eventually be, but I'm sure it will come in handy at some point Smiley Happy

0 Kudos
Message 4 of 8
(4,954 Views)

You should also take notice of data types.  The input to the wait ms function is a blue wire.  This means it's going to work with integer types.  Assuming Windows wasn't an issue, you'd still have 1ms or 2ms, but nothing in between as a possibility.  Any solution you'd find with LV would require you to use floating point, or orange, wires.

0 Kudos
Message 5 of 8
(4,945 Views)

Yes, I saw the coersion dot, that was what first alerted me the fact that I was going to have an issue.  I did end up getting it working, I didnt realize that LINX had added servo functions.  The code I used is attached in case anyone else runs into this problem! 

0 Kudos
Message 6 of 8
(4,940 Views)

I'm confused. Why aren't you using the actual PWM functionality built into the Arduino's hardware and just setting the duty cycle that you need for a given servo position? You can use the AnalogWrite() command or the servo library, both of which are supported in LINX. 

0 Kudos
Message 7 of 8
(4,907 Views)
I actually did end up using the servo library that is part of LINX, as you can see in the second VI I posted. I wasn't aware that LINX had servo support when I posted the question. So I am using the built in PWM functionality now, which is working quite well. Thank you for the comment though, I really do appreciate it.
0 Kudos
Message 8 of 8
(4,899 Views)