7 Replies Latest reply on Sep 16, 2016 10:54 AM by Thomas Kirven

    Edison PWM Fine-Control

    V1N0

      Hello everyone!

       

      I am working on a project that requires the control of a brushless motor through Edison's PWM output.
      So far i had a great success in regards to controlling the motors except for one issue.

      The change in PWM frequency does not give me enough control over the motor speed.

       

      I am using the Servo library's write microseconds function.

      What i know is that the ESCs usually read a range of 1-2ms w/20ms period, with 1ms being 0% throttle and 2ms being 100% throttle.

      When i writeMicroseconds(2000) then writeMicroseconds(700) to the ESC signal pin on ESC boot-up, the ESC is calibrated to read signals from the range of 700-2000us.

      Now, the motor starts spinning at 746, however, as i increment it, nothing happens at 747,748,749,760,..etc until it reaches some point above or just under 800 then it jumps in speed, it does not increase gradually. In-fact, during the 700-2000 range it only has 13-14 "jumps" in speed with no changes in between.

       

      The closest reference i could find was this thread that pointed out the inconsistencies with the PWM generator in Edison. However, i am not sure how true it is to my case as i am using the Edison Arduino Kit.

       

      Point is: I need a finer control over the ESCs.

      Is there another way to get a finer control (other than the Servo Library) or is this a hardware issue like the one mentioned in the measurement thread?

      Also. if it is a Hardware issue that i cannot get around, would this solve the problem or are there any better solutions?

      Or am i misunderstanding the way PWM and ESCs work?

       

      EDIT:

      I don't know if this will help pin down the issue but i took a sample of the changing periods.

      The changes happen at:
      746 <<= Start

      820

      895

      969

      1044

       

      This shows increments of 74-75 for a change in speed to happen, but it is not a smooth change either, it is a jump in speed.

       

       

      I would appreciate any insight on the matter!

       

      Thank you.

        • 1. Re: Edison PWM Fine-Control
          DiegoV_Intel

          Hi V1N0,

           

          I noticed that behavior before when trying to use a Servo. As you pointed, it's an issue with the Edison PWM generator. I'm afraid that there isn't a workaround for it, it's simply how it works. If you have a Logic Analyzer or Oscilloscope, check the PWM signal with the following code: Edison/setPWM_Edison.ino at master · MakersTeam/Edison · GitHub. It's an Arduino sketch that sets the frequency and duty cycle of the PWM signal. You will notice that there aren't changes in the signal at some frequency intervals.

           

          My suggestion would be to use an external PWM controller to achieve the accuracy you need.

           

          Regards,

          Diego

          • 2. Re: Edison PWM Fine-Control
            V1N0

            Diego, you never disappoint!
            Thank you very much for your response.

             

            I want to add that after reading around, it actually makes sense.

            Apparently a part of it is due to the resolution of the PWM signal on the Edison.

            This theory made a lot of sense to me, correct me if i am wrong but it appears that the Edison's resolution is 8-bit, allowing for 2^8 = 256 adjustments. Since the ESCs readings are in the range of 5-10% duty cycle this allows for 5% usable settings, which is about 13 adjustments (also 100%/256~=0.39%, so the Edison has steps of 0.39% and there is about 13 of those in a 5%), now with a little calibration i managed to increase those settings (by calibrating the ESC to read a minimum of 700 microseconds - it does not read anything under that- and a maximum of 2000 microseconds) up to a few more settings, but still, 15-16 settings is not enough to have a precise control over the motors. So i ordered an independent 12 bit resolution PWM generation shield allowing for 4096 steps (200+ are usable in the ESC range).

            I will report back on how it goes in case anyone is interested!

            • 3. Re: Edison PWM Fine-Control
              DiegoV_Intel

              Hi V1N0,

               

              Your analysis is correct. The only option would be using an external PWM controller.

               

              I invite you to post your results after testing the external PWM generator.

               

              Regards,

              Diego

              • 4. Re: Edison PWM Fine-Control
                V1N0

                Hello everyone!

                This is a little update in-case anyone is looking for this kind of information.

                 

                I have acquired the PCA9685 and tested it with the Edison Arduino.

                Turns out that it is true, the reason for the lack of control was the resolution of the PWM generators in the Arduino (8-bit)

                The 12-bit PWM driver offered a lot finer control over the speed of the motors.

                 

                This is the setup i am using:

                 

                ESCtoPCA_bb_wm.png

                 

                PCA9685-MPU6050-Edison3_bb_wm.png

                 

                With the following library:
                GitHub - adafruit/Adafruit-PWM-Servo-Driver-Library: Adafruit PWM Servo Driver Library

                 

                100% compatible with the Edison, no issues so far!

                • 5. Re: Edison PWM Fine-Control
                  H_E_L_P

                  Yup, for those who may be interested I used the Sparkfun PWM block which is 12 bit with a frequency range from 24Hz to 1526Hz, so you should be able to use an ESC with fast PWM protocol like Oneshot125 using half of the period for the throttle signal. That's half of 12 bits, so half of 4096. The Sparkfun PWM board also uses the PCA9685 PWM controller over i2c. Had to learn how to use i2c, but its working now. I used the examples on sparkfun in c++ to write a program in python 2.7 to control a brushless motor with fine control at a high rate over i2c using this board. IF anyone reading this needs code let me know and I will post it somewhere.

                  • 7. Re: Edison PWM Fine-Control
                    Thomas Kirven

                    Hi V1NO I was wondering how I would go about using this library in an arbitrary c++ script run from the command line of the intel Edison. I am using the miniBreakout board, and have a level shifter to interface with the hardware.

                     

                    Thanks!

                     

                    Thomas