10-24-2015 01:59 PM
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
Solved! Go to Solution.
10-24-2015 02:58 PM
10-24-2015 03:03 PM
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
10-24-2015 03:24 PM
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
10-24-2015 04:03 PM
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.
10-24-2015 04:09 PM
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!
10-24-2015 08:55 PM
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.
10-24-2015 09:14 PM