Results 1 to 6 of 6

Thread: 1.5 ms PWM via parallel port for servo control

Hybrid View

  1. #1

    Default 1.5 ms PWM via parallel port for servo control

    Hi,
    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.

    Thanks.

    Milind

  2. #2
    Senior Member Cyborg devpriya's Avatar
    Join Date
    Jul 2005
    Location
    Seattle, WA, USA
    Posts
    275

    Default

    Write a DLL in VC++ and call it in Java........but I dont know whether there would be any latency in the response :?:

  3. #3
    Administrator T-1000 vikas's Avatar
    Join Date
    Feb 2004
    Location
    Delhi
    Posts
    1,922
    Blog Entries
    14

    Default

    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 .

  4. #4

    Default

    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.

  5. #5
    Senior Member Cyborg devpriya's Avatar
    Join Date
    Jul 2005
    Location
    Seattle, WA, USA
    Posts
    275

    Default

    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

  6. #6

    Default

    hey guys. I finally figured out the nanosecond sleep timer
    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();

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •