1 2 3 4 5 6 Previous Next 84 Replies Latest reply on Feb 22, 2013 7:07 AM by userc_38527 Go to original post
      • 30. Re: Simple PWM
        meenakshisundaramr_71

        Bianchi,

           

         

           

        Not sure why you are using a pulse width value higher than period value; As those statements, will result in your PWM output to be high all the time (if Compare type is selected as Less than) and also for a 8-bit PWM, you can only write a period/pulsewidth of value >255;

           

         

           

        Now getting back to your requirement - Is it possible for you to send us the servo motor's datasheet? I can help you in getting the PWM configured properly for the same.

           

         

           

        Regards,

           

        MSUR

        • 31. Re: Simple PWM
          meenakshisundaramr_71

          A correction in the above statement - it is period/pulsewidth value CANNOT be >255 for a 8-bit PWM; the lines below will result in an error -

             

           

             

          /* set period to eight clocks */
              PWM8_1_WritePeriod(1299);

              /* set pulse width to generate a 33% duty cycle */
              PWM8_1_WritePulseWidth(1300);

          • 32. Re: Simple PWM
            userc_38527

            How can I develope this spec?
            Operating Speed (4.8V no load) : 0.131sec / 60 degrees

            • 33. Re: Simple PWM
              rajivv_36

              If the requirement is to achieve 60deg revolution in 0.131 sec, then motor needs to be moved by one step in (0.786/TOTAL_MOTOR_STEPS) sec. So, configure a timer to generate this much delay and at each timer interrupt, update the motor step sequence. 

                 

               

                 

              Also, you have to tune the PWM duty cycle to acheive the required torque. 

              • 34. Re: Simple PWM
                rajivv_36

                Please ignore my previous comment...I thought it is about stepper motor. 

                • 35. Re: Simple PWM
                  meenakshisundaramr_71

                  Hello Bianchi,

                     

                   

                     

                  I believe the spec you are mentioning is the rate at which the servo turns.

                     

                   

                     

                  We need the pulse timing details, for generating the PWM to hold the servo in a specific angle. If you let us know the datasheet or make of the servo you are using, it will be useful. For instance in the datatsheet of this servo, you can see the timing graph provided on Page 3. We would need a similar data for the servo you are using, to provide exact PWM configuration.

                     

                   

                     

                  For the motor in the mentioned link, you can use the PWM settings i provided in my previous comments. And most of the servos, have pulse frequency of 50Hz (20 ms) only the pulse duration for a particular angle would be different across servos and that is what is required here for PWM setting.

                     

                   

                     

                  Regards,

                     

                  MSUR.

                  • 36. Re: Simple PWM
                    dakn_263916

                    The operation of a PWM, Period, Compare Value, Duty Cycle occur as follows -

                       

                     

                       

                    1) PWM is a down counter, starts by loading the period value you set in its properties

                       

                    window or by using API. It counts down to 0, then reloads the period value, and keeps

                       

                    repeating. So if you put in 1 Khz, period = 10, then the PWM produces a 1,000/10

                       

                    rate = 100 Hz. Note the actual value you put in is N - 1, or 9.

                       

                     

                       

                    2) The counter has attached to it a comparitor, that is always looking at value in counter, and

                       

                    is comparing what the current counter value is against what you put in the compave value

                       

                    properties, or by writing to the compare register. The comparitor logic is setable to <= or <,

                       

                    so if set to <=, and your compare value setting is 4, then the compare output will be low as counter

                       

                    counts down from 10 until it hits 4, at which time it goes high and stays there until PWM counter reloads

                       

                    period value at end of cycle,, eg. 0 in the counter. So this is what you are doing when you set

                       

                    compare value, you are setting duty cycle of the output. Again compare value is N - 1.

                       

                     

                       

                    3) Your Servo has a relationship bbetween pulse width, eg. the compare output, and angle.

                       

                    Typical servos are null (0 degrees) at 1.5 mS, at - 60 @ 1 mS, + 60 @ 2 mS.

                       

                     

                       

                     

                       

                     

                       

                    Hope this helps.

                       

                     

                       

                    Regards, Dana.

                    • 37. Re: Simple PWM
                      userc_38527

                      I can't find the datasheet, only get this one from the seller website :

                      Operating Speed : 0.13sec / 60 degrees (6.0V no load) Stall Torque : 13 kg-cm (180.5 oz-in) at 4.8V

                      • 38. Re: Simple PWM
                        userc_38527

                        am I right for creating 130ms by default ?

                        • 39. Re: Simple PWM
                          userc_38527

                          I used this code, there's rotation but it's not 60 degree,

                             

                          do I make a right code and right setting ?

                             

                          thanks

                             

                          void GenerateOneThirdDutyCycle(void)
                          {
                              /* set period to eight clocks */
                              PWM8_1_WritePeriod(10);

                              /* set pulse width to generate a 33% duty cycle */
                              PWM8_1_WritePulseWidth(11);

                              /* ensure interrupt is disabled */
                              PWM8_1_DisableInt();

                              /* start the PWM8! */
                              PWM8_1_Start();
                          }

                          /* Divide by eight function */
                          void GenerateHalfDutyCycle(void)
                          {
                              /* set period to eight clocks */
                              PWM8_1_WritePeriod(129);

                              /* set pulse width to generate a 33% duty cycle */
                              PWM8_1_WritePulseWidth(130);

                              /* ensure interrupt is disabled */
                              PWM8_1_DisableInt();

                              /* start the PWM8! */
                              PWM8_1_Start();
                          }
                           

                          • 40. Re: Simple PWM
                            userc_38527

                            I tried to change with some values but I didn't see any change on the angle of the rotation, am I putting the wrong setting or a wrong code, can somebody explain ?

                               

                            I'll attach the project with it

                            • 41. Re: Simple PWM
                              JoMe_264151

                              Since you are a beginner, it will be very helpful for you not to try out everything, but focus on understanding what you are doing.

                                 

                              We are talking about a PWM which has several parameters that affect its performance.

                                 

                              Dana was talking about "Period" which as we suggested should be fixed at 20ms giving a frequency of 50Hz.

                                 

                              The PWM period for your application should be fixed and not cjhanged within the program. It is calculated by dividing the input-frequency of your PWM by (preiod-value +1) givint the output frequency. 1/frewquency is period , you hopefully know.

                                 

                               

                                 

                              Next parameter in a PWM is the "pulse width" which is often referred to as "Duty-cycle". In your appllication the Pulse width has to be between 1 ms and 2 ms and must vary between thos values to move the servo.

                                 

                              A simple calculation which I would like to leave in your hands will relieve the valid range of values which you can send to the PWM by using the API PWM8_1_WritePulseWidth().

                                 

                              The delay you used to watch motor movement is just a thenth of a second which might be too short for the device to reach its wanted position, I would suggest to use a much longer delay at first Do not stop the PWM! some servos are diving into a fixed position when the pulses are not updated every 20ms.

                                 

                              So putting it all together I would suggest you to read and understand the datasheets, understand the APIs, understand the math behind and use it accordingly.

                                 

                               

                                 

                              Happy coding

                                 

                              Bob

                              • 42. Re: Simple PWM
                                userc_38527

                                How to use this function then, for example I want to have 1ms ?

                                   

                                void GenerateZeroCycle(void)
                                {
                                    /* set period to eight clocks */
                                    PWM8_1_WritePeriod();

                                    /* set pulse width to generate a 33% duty cycle */
                                    PWM8_1_WritePulseWidth();

                                    /* ensure interrupt is disabled */
                                    PWM8_1_DisableInt();

                                    /* start the PWM8! */
                                    PWM8_1_Start();
                                }
                                 

                                • 43. Re: Simple PWM
                                  userc_38527

                                  The video:

                                     

                                  http://www.youtube.com/watch?v=Oi3joZJq0Yc&feature=youtu.be

                                     

                                   

                                     

                                  The code :

                                     

                                  void GenerateHalfDutyCycle(void)
                                  {
                                      /* set period to eight clocks */
                                      PWM8_1_WritePeriod(199);

                                      /* set pulse width to generate a 33% duty cycle */
                                      PWM8_1_WritePulseWidth(200);

                                      /* ensure interrupt is disabled */
                                      PWM8_1_DisableInt();

                                      /* start the PWM8! */
                                      PWM8_1_Start();
                                  }

                                  /* Divide by eight function */
                                  void GenerateZeroCycle(void)
                                  {
                                      /* set period to eight clocks */
                                      PWM8_1_WritePeriod(19);

                                      /* set pulse width to generate a 33% duty cycle */
                                      PWM8_1_WritePulseWidth(20);

                                      /* ensure interrupt is disabled */
                                      PWM8_1_DisableInt();

                                      /* start the PWM8! */
                                      PWM8_1_Start();
                                  }

                                  .

                                     

                                  .

                                     

                                  .

                                     

                                  .

                                     

                                  .GenerateHalfDutyCycle();
                                      Delay10msTimes(90);
                                      GenerateZeroCycle();
                                      Delay10msTimes(90);

                                     

                                   

                                     

                                  Is there anything I can do to make the angle bigger, I've done all the suggestions above but it doesn't work properly,

                                     

                                  any idea ?

                                     

                                  Please find the project attached in a previous post to check it..

                                     

                                   

                                     

                                  Thanks a lot

                                  • 44. Re: Simple PWM
                                    meenakshisundaramr_71

                                    Hello Bianchi,

                                       

                                     

                                       

                                    In the case that there are no timing diagrams provided, we can try 1.5 ms for center position and any position less than 1.5 ms is going to move the rotor angel to a position less than 90 and above 1.5 ms it will be more than 90 degrees. Since we do not know the exact values we need to figure the limits by experiments.

                                       

                                     

                                       

                                    Please try the below -

                                       

                                     

                                       

                                    Global settings -

                                       

                                    Power setting = 5.0 V/24MHz; VC1 = 6, VC2 = 4, VC3 source = VC2 and VC3 = 100; ==> VC3 = 10 KHz or 100 uS signal

                                       

                                     

                                       

                                    Place a PWM8 UM, and configure the parameters as in attached figure.

                                       

                                    Route the CompareOut signal to the Servo's control signal pin (most probably the white wire of the servo).

                                       

                                     

                                       

                                    Use the below code to move it to center position -

                                       

                                        /* set pulse width to generate a 1.5ms high pulse duty cycle */
                                        PWM8_1_WritePulseWidth(30);   

                                        /* start the PWM8! */
                                        PWM8_1_Start();

                                       

                                     

                                       

                                    Use the below code to move the servo rotor to less than 90 degree -

                                       

                                        /* set pulse width to generate a <1.5ms high pulse duty cycle */
                                        PWM8_1_WritePulseWidth(25);   

                                        /* start the PWM8! */
                                        PWM8_1_Start();

                                       

                                     

                                       

                                    Use the below code to move the servo rotor to more than 90 degree -

                                       

                                        /* set pulse width to generate a >1.5ms high pulse duty cycle */
                                        PWM8_1_WritePulseWidth(35);   

                                        /* start the PWM8! */
                                        PWM8_1_Start();

                                       

                                     

                                       

                                    You can play around with the pulse width values to see how far the rotor turns and make a note of the limits to use in your final design. Also note that the 1.5 ms center position pulse is arbitrarily chosen as that is the most common width for a center pulse in most servos. You can verify that too by observation.

                                       

                                     

                                       

                                    Let me know if this helps.

                                       

                                     

                                       

                                    Regards,

                                       

                                    MSUR