View Full Version : 1.5 ms PWM via parallel port for servo control

06-08-2006, 04:28 PM
I have made a straight forward controller for servo motors using the parallel port via optocouplers. The programing is in JAVA and I am sending a PWM using a sleep timer. However the accuracy of time control that I have been able to achieve is only of 1ms. ie, I am able to send a 1ms pulse width for extreme CW and 2ms pulse for extreme CCW rotation but there is no control for angles between the two extremes.
The JAVA command for the delay is :
java.lang.Thread.sleep(d); // d is a double type variable for the number of milliseconds
I also tried :
java.lang.Thread.sleep(0,(int)n); // n is an intereger variable for number nanoseconds
but my computer is rounding off any number of nanoseconds to 1ms.

Is there a way to get a 0.1 ms accuracy control. Even better, has anyone written a class for a 0.1ms accuracy PWM which I can directly incorporate in my program.



06-08-2006, 07:16 PM
Write a DLL in VC++ and call it in Java........but I dont know whether there would be any latency in the response :?:

06-08-2006, 07:56 PM
Sleep :) .... minimum is 1ms

Heres what u got to do

Like devpriya said write a dll ... which uses Windows Query Performance Timer to do the time syncing ... And then call it from java .

06-08-2006, 08:42 PM
Thanks for the suggestion. However i have had no experience in dll writing.

Isnt there a more straight forward way out? Is the precision of the serial port also only 1ms? Also since java has provided a nanosecond option there must be a way to utilise it.

06-09-2006, 12:53 AM
Look I dont have much experience in Java but in VB the timer works very accurately......It should work in Java also, may be somewhere you are going wrong.

Try the Timer bundled with the GUI making tools like swing

06-13-2006, 12:54 AM
hey guys. I finally figured out the nanosecond sleep timer :D
The problem was that versions of java older than 1.5 dont support nanosecond accuracy.
I installed javaSDK1.5, and my problem is solved.
The command I used was :
long currentTime = System.nanoTime();