5 Replies Latest reply on Apr 16, 2015 7:50 AM by userc_15612

    PWM or I/O setting



      i try actually pwm_tones from SDK v2.0.1. I know already how to set the PWM frequency. But i still don't understand, how can i set the pin.

      On the image we can see, that the pin for 5s always on (High) and 4s always off (low). The time is defined by a random generator.

      How/Where can i change it?


        • 1. Re: PWM or I/O setting

          This is probably because sleep is enabled by default in SDK 2.x and PWM with PMU_CLK as the reference clock will not function when sleeping.


          Change the pwm_tones app to use LHL_CLK instead (for example: pwm_start(PWM0, LHL_CLK, toggle_value, init_value); ), which has a fixed reference of ~128KHz instead of the aclk generated reference (so you may have to change the init and toggle values to generate the same PWM frequency). When reference clock is LHL_CLK, the PWM will continue to function in sleep.

          1 of 1 people found this helpful
          • 2. Re: PWM or I/O setting

            thanks for your reply. now it's work find.

            Can you tell me, how can i calculate the PWM freq (init & toggle value)? and how can i change the duty cycle?

            • 3. Re: PWM or I/O setting

              aclk_configure() and pwm_start() are used for PWM configuration.

              The base frequency can be defined by 1st argument of aclk_configure().

              Each clock (from the base frequency) increments internal counter.

              Ex.) below code defines base frequency as 2kHz.

                   aclk_configure(2000, ACLK1, ACLK_FREQ_24_MHZ);


              PWM frequency is generated by the base frequency and 4th argument of pwm_start() as InitCount.

              The internal counter starts from InitCount to 0x03ff. When it reaches 0x03ff, it will back to InitCount.

              Ex.) below code generates PWM frequency as 2Hz.

                   pwm_start(PWM0, PMU_CLK, 0x03eb, 0x0018);     // 1000 * 2kHz = 2Hz(500ms)

              Ex.) below code generates PWM frequency as 100Hz.

                   pwm_start(PWM1, PMU_CLK, 0x03ec, 0x03ec);     // 20 * 2kHz = 100Hz(10ms)


              Duty cycle can be changed by 3rd argument of pwm_start() as toggleCount.

              Ex.) 2Hz example shows 490ms and 10ms cycle     // (0x03ff-0x03eb=)20 * 2kHz = 10ms)

              1 of 1 people found this helpful
              • 4. Re: PWM or I/O setting

                Thanks. Now i can set the pwm as i want

                • 5. Re: PWM or I/O setting

                  Hi userc_6692 and dmiya


                  I am Also Working On PWM. I am able to generate the PWM At particular Frequency and duty cycle. But I am not able to Generate Frequently.


                  Say I waned to Send a data stream (e.g. 1001010 ) through PWM. But I was Not able to send those stream.
                  Will You please help me Out with Your guidance.






                  Thanking You.,