Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: PWM precision servomotor movement

  1. #1

    PWM precision servomotor movement

    HI everybody,

    I use pwm control servomotor.
    Range is 0..180, so I put 1 by 1 (89,90,91...) degre.

    How can I do to obtain 0.1 by 0.1 degre movement ?
    I have try increase by 0.1 starting at 87 movement appear at 88 not in 87. to 87.9.

    Seem the pwm servo library is set with 4096 (12bits) so I should obtain 180/4096=0.044 increment a least.
    I redo this in setup using analogWriteResolution(12);
    Seem that with int you have'nt 0.1...

    My clock speed is 96MHz.

    Sample code :
    #define axeX_PWM_PIN 5
    #define axeY_PWM_PIN 6
    float valeurCdeX=90,valeurCdeY=90;
    void setup (){
      analogWriteResolution(12);  // analogWrite value 0 to 4095, or 4096 for high
    //sample use  in loop
    Last edited by LaurentDelaon; 02-12-2021 at 11:30 AM.

  2. #2
    Senior Member
    Join Date
    Jul 2020
    servo.writeMicroseconds (...)
    is used in the standard Servo library for higher precision. 1500 microseconds
    corresponds to mid-travel (90 degrees) by convention, and 544 and 2400 microseconds for 0 and 180 seems
    to be the default scaling in the Servo library.

    This is all from the standard Arduino Servo library, not sure if Teensy version differs much for this, or which servo
    library you are suing anyway as you didn't say (the forum rule exists for a reason!)
    Its possible some libraries allow float as arg to write().

  3. #3

    Seem this library as you speak about Servo library it is not compatible with Teensy3.2.

    Servo.h:77:2: error: #error "This library only supports boards with an AVR, SAM, SAMD, NRF52 or STM32F4 processor."
     #error "This library only supports boards with an AVR, SAM, SAMD, NRF52 or STM32F4 processor."
    I have use this one:

    #include <PWMServo.h>

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Quote Originally Posted by LaurentDelaon View Post
    Servo library it is not compatible with Teensy3.2.
    Arduino must be using the wrong library, because the Teensyduino installer definitely does give you a copy of the Servo library which works with Teensy 3.2 (and all Teensy models).

    Look in the console panel for info about duplicate library. Arduino should always show this when you have a compiler error. Without an error, it only appears if you have turned on verbose output while compiling in File > Preferences.

    The duplicate library info will tell you the full pathname of the Servo library is used, and the pathnames of any others it ignored. You probably just need to move or delete the copy Arduino is erroneously choosing, so it will then use the copy which came from the Teensyduino installer.

  5. #5
    Hi Paul
    Thanks to your reply and advice. You're right.
    After destroy an arduino library I can compile writeMicroseconds function...

    Seem much precise with Modelcraft servo RS2MG I can obtain 0.5 against 1.

    sample code:

    //code precis writeuseconde
         float valeurCdeXus=(valeurCdeX/180*1000)+1000; //convertit en useconde 180=1000us pour arange suposed 1000..2000
         if (sbpa_add_sortie=='X')  {myservoX.writeMicroseconds(valeurCdeXus);};

Posting Permissions

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