6 Replies Latest reply on Aug 27, 2015 1:55 PM by yp66

    Edison PWM accuracy


      I am using an Edison module with native linux programming in C++ using the mpaa libraries and PWM generation.  All goes well in the sense that I can generate a series of pulses but the pulsewidth is inconsistent.  I am trying to generate the typical servo/ESC type of signal (20 mSec period, pulse width between 500 and 2000 micro seconds) but I am getting inconsistent results.


      The relevant code is below:


      pPin = new mraa::Pwm(20);





      The table below shows the value of x and actual value (measured with a scope) on the pin








      The width is rock solid (so there is no drift of jitter) just the numbers don't add up which leads me to believe I am misinterpreting the meaning of the period/pulse width arguments to the mraa library.  I get similar issues with using a duty cycle - the period is off by a couple of milli-seconds.  Anyone has an idea on the specific meaning of the parameters?

        • 1. Re: Edison PWM accuracy
          • 2. Re: Edison PWM accuracy

            Edison PWM generator is not very accurate - mraa attempts to ask the hardware for what you're asking but the resolution of the pwm generator is just not very good.

            • 3. Re: Edison PWM accuracy

              The PWM generator does not look accurate

              I was trying to control some servos and at first when i set 1.5 ms the motor was not going to the middle (blame the motor)


              recently i got my hands on an oscilloscope and i looked at the signal

              us set  vs us measured

              500 = 598

              1000 = 1110

              1500 = 1706

              2000 = 2220


              going to the period i set it to

              20ms but i'm measuring 21.8 ms (stays fixed for any pulse width)


              now looking at your measurements looks like it gives the same values, so maybe we can add some software calibration in our code.



              even more data

              at 1880 i get 2050us

              for 1890 to 1960 i get 2134us

              at 1970  to 2030 i get 2218us

              at 2040 i get 2306us

              we can conclude that you need to work in ~70us increments/decrements

              • 4. Re: Edison PWM accuracy



                Is the PWM being done by the Linux kernel?  Is the ~70us discretization mentioned above a reflection of the scheduling capability of the default kernel?  Could this be improved by using the PREEMPT_RT kernel setup from PREEMPT_RT-enabled Linux Kernel 3.10.17 on Intel Edison?


                Might this get better when the Quark is enabled in a future Edison BSP release?



                • 5. Re: Edison PWM accuracy

                  No answer since April? C'mon!!

                  • 6. Re: Edison PWM accuracy

                    There doesn't seem to be a lot new on this.  I have more or less given up on the Edison for low level signaling; the CPU is too slow with hardware; the MCU is better but the serial link between the MCU and the main CPU is too slow to be useful.  In time, these two (MCU/CPU) will be a potent combination but until the software/hardware matures, I am using the Edison as a fast embedded CPU with wifi.