12 Replies Latest reply on Oct 17, 2014 4:10 PM by ArvindS_76

    Different Frequencies for PWM

      In using the PWM pins is it possible to set the pins to run at different frequencies?

      Say, I want PWM0 to run at 20kHz and PWM1 to only run at 300Hz, is this possible?

       

      I played around with LHL_CLK, PMU_CLK, ACLK0, ACLK1, and the aclk_configure function, but was unable to get what I would like.

       

      Thanks.

        • 1. Re: Different Frequencies for PWM
          ArvindS_76

          Yes, you can. You have to make sure that you configure the ACLK to a frequency that can be divided down to generate both frequencies you need.

           

          Here is an example to generate 1K and 8K on the two channels.

           

          // Configure ACLK for 512KHz.

          aclk_configure(512000, ACLK1, ACLK_FREQ_24_MHZ);

           

          // Configure channel0 for 1.01KHz.

          pwm_start(PWM0, PMU_CLK, 0x2FF, 0x200);

           

          // Enable Output on P26 == PWM0.

          gpio_configurePin((26) / 16, (26) % 16, GPIO_OUTPUT_ENABLE, 0);

           

          // Configure channel1 for ~8KHz

          pwm_start(PWM1, PMU_CLK, 0x3E0, 0x3BF);

           

          // Enable Output on P27 == PWM1.

          gpio_configurePin((27) / 16, (27) % 16, GPIO_OUTPUT_ENABLE, 0);

           

           

          The max value the PWM HW will count to before starting from init value is always 0x3FF. The counts are incremented at the ACLK edges starting at init value. When the count reaches toggle value, the PWM channel output is inverted and when the count reaches 0x3FF, the output is inverted again and the count wraps around to init value and so on.

           

          If you need a 50% duty cycle, make sure that the init value is the same distance from the toggle value as toggle value is from 0x3FF.

          1 of 1 people found this helpful
          • 2. Re: Different Frequencies for PWM

            Thanks, I got everything up and running with your help!

            • 3. Re: Different Frequencies for PWM

              my gpio config is

              const BLE_PROFILE_GPIO_CFG hello_sensor_gpio_cfg =

              {

                  /*.gpio_pin =*/

                  {

                      GPIO_PIN_WP,      // This need to be used to enable/disable NVRAM write protect

                      GPIO_PIN_BUTTON,  // Button GPIO is configured to trigger either direction of interrupt

                      GPIO_PIN_LED,     // LED GPIO, optional to provide visual effects

                      GPIO_PIN_BATTERY, // Battery monitoring GPIO. When it is lower than particular level, it will give notification to the application

                      GPIO_PIN_BUZZER,  // Buzzer GPIO, optional to provide audio effect

                      -1,-1, -1, -1, -1, -1, -1, -1, -1, -1, -1 // other GPIOs are not used

                  },

                  /*.gpio_flag =*/

                  {

                      GPIO_SETTINGS_WP,

                      GPIO_SETTINGS_BUTTON,

                      GPIO_SETTINGS_LED,

                      GPIO_SETTINGS_BATTERY,

                      GPIO_SETTINGS_BUZZER,

                      0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0

                  }

              };

               

              the GPIO_PIN_BUZZERis 28;

              if GPIO_PIN_BUZZERis 28 ,means I use PWM2 is ritght?

              this function bleprofile_BUZBeep() use PWM2 to driver buzer?

              why i config the pwm2 like this:

              pwm_setClock(PWM2,LHL_CLK);

              pwm_setInitValue(PWM2,976);
              pwm_setToggleCount(PWM2,1000);

              But it does not work well,why??

              • 4. Re: Different Frequencies for PWM
                ArvindS_76

                Please have a look at the PWM sample app called pwm_tones in SDK 2.0.1 for an example for how to configure and use the PWM block. This sample will work with SDK 1.1.0 too.

                • 5. Re: Different Frequencies for PWM

                  why i can`t measure the  24 MHz Ref Xtal when it work?

                  I use BCM920732TAG_Q32 board!

                  • 6. Re: Different Frequencies for PWM
                    ArvindS_76

                    You should be able to measure the 24MHz xtal with an oscilloscope at one of the terminals of Y1. Since this is turned off in sleep, you will see it oscillating only when the chip is awake.

                     

                    > why i can`t measure the  24 MHz Ref Xtal when it work?

                    I don't understand the question. Could you please explain what you are trying to do?

                    • 7. Re: Different Frequencies for PWM

                      when i call  bleprofile_PWMBUZFreq(PWMBUZ_2000,0,0) in hello_sensor_create(void), why it does not work well?

                      • 8. Re: Different Frequencies for PWM
                        hachc_2137126

                        I got same issue on calling bleprofile_PWMBUZFreq() to change the frequency periodically.

                        Any comment?

                        • 9. Re: Different Frequencies for PWM
                          MichaelF_56

                          I will ask the developers to respond as it appears that 2 of you are experiencing the same issue with bleprofile_PWMBUZFreq(), one of you on an older TAG2 20732 based board, while the other is on the newer TAG3 20737 based board.

                           

                           

                          • 10. Re: Different Frequencies for PWM
                            ArvindS_76

                            Can you try disabling sleep using the callback registered with devlpm_registerForLowPowerQueries(see uart_firmware_upgrade/ws_upgrade_uart.c for example)? This function uses the PMU clock as the reference which will be shut down in sleep. There are some posts that list the options you have - disable sleep or use the LHL clock as the reference and provide your own implementation of controlling the buzzer.

                            1 of 1 people found this helpful
                            • 11. Re: Different Frequencies for PWM
                              hachc_2137126

                              Hi arvinds,

                               

                                I'm using 20732 as well for PWM testing. And just tried disabling sleeping, but it was still failed that only around 4.7 kHz square pulse is generated no matter what *preset* is set to function 'bleprofile_PWMBUZFreq'.

                              • 12. Re: Different Frequencies for PWM
                                ArvindS_76

                                Have you tried bleprofile_PWMBUZFreq(PWMBUZ_FREQ_MANUAL, init_value, toggle_value)? The bleprofile_PWM* API uses the aux clock at 256KHz and so this is what will be divided down to the PWM frequencies. If you want higher or more control, you should use your own methods to control the PWM using the sample in the first response above (or look at pwm_tones sample app).