4 Replies Latest reply on Dec 25, 2014 12:49 PM by MichaelF_56

    How to get all 4 PWMs working at the same time on BCM20736S

      I've been having some difficulty getting all four PWMs working at once on the BCM20736S.

       

      To the best of my knowledge, there is only once configuration that can get all four PWMs out:

       

      PWM0     P26     pin 42

      PWM1     P27     pin 1

      PWM2     P14     pin 40

      PWM3     P13     pin 39

       

      I've learned about having to configure P14 and P13 *after* calling pwm_start, and I have 3 of the four working. However, pin 42 (PWM0) seems to output a signal which is low approx. 0.45 uSec, with a period of approx 43 uSec.

       

      The period of PWM1 - PWM3 seems to be correct, about 24000 Hz. The duty cycle of PWM1 - PWM3 corresponds to the value passed for the "toggleCount" parameter in "pwm_start".

       

      It seems that the period of PWM0 is also 24000 Hz, but the duty cycle seems to be stuck at 1/1024. For the code shown in our "initialize_pwm" below, PWM0 should be low for approx 4.5 uSec, not 0.45 uSec. Also, changing the PWM "toggleCount" parameter in the call to "pwm_start" doesn't change the PWM0 output waveform.

       

      I've included code from a modified "hello_sensor" application for the PWM initialization. For reference, I've also included the initial GPIO configuration, which doesn't try to set the PWM GPIOs.

       

      How can I get all four PWMs to output their appropriate signals at the same time?

       

      void initialize_pwm(void)

      {

       

      // Disable sleep when PWM is active.

        devlpm_registerForLowPowerQueries(timme_charger_device_lpm_queriable, 0);

       

        aclk_configure(24000000, ACLK1, ACLK_FREQ_24_MHZ); //

       

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

        pwm_start(PWM0, PMU_CLK, 104, 0); // 10% duty cycle

       

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

          pwm_start(PWM1, PMU_CLK, 208, 0); // 20% duty cycle

       

          pwm_start(PWM2, PMU_CLK, 312, 0); // 30% duty cycle

       

          // For PWM2 output on P14, GPIO must be configured *after* setting PWM

       

          // If you want the PWM2 output on P14:

          gpio_configurePin(14/16, 14%16, (2 << 4), GPIO_OUTPUT_LOW);

       

          pwm_start(PWM3, PMU_CLK, 416, 0); // 40% duty cycle

       

          // If you want the PWM3 output on P13:

          gpio_configurePin(13/16, 13%16, (2 << 4), GPIO_OUTPUT_LOW);

      }

       

       

      #define TIMME_ADC_INPUT_PIN 15 // P15 is ADC input

      #define TIMME_ADC_INPUT_CHANNEL ADC_INPUT_P15 // should be = adc_convertGPIOtoADCInput(TIMME_ADC_INPUT_PIN)

       

      #define DIAG_CONNECTOR_PIN_1 1

      #define LED_CTRL_PIN 33

       

      #define A0_GPIO_PIN 2

      #define A1_GPIO_PIN 4

      #define A2_GPIO_PIN 8

       

      // The following structure defines GPIO configuration used by the application

      const BLE_PROFILE_GPIO_CFG hello_sensor_gpio_cfg =

      {

          /*.gpio_pin =*/

          {

          1,      // Pin 1 of DIAG connector

          3,  // Pin 2 of DIAG connector

          25,     // Pin 3 of DIAG connector

          24, // Pin 4 of DIAG connector

          LED_CTRL_PIN,  // Controls external LED, 1 => LED on

          0, 32, 33, // CHARGER_SHUTDOWN, TIMME_OFF, LED_CTRL

          A0_GPIO_PIN,

          A1_GPIO_PIN,

          A2_GPIO_PIN,

          -1, -1, -1, -1, // 26, 27, 14, 13, // PWM0 thru PWM3

          -1 // TIMME_ADC_INPUT_PIN,

          // -1, -1, -1 // enter -1 for any unused GPIOs

          },

          /*.gpio_flag =*/

          {

          (GPIO_OUTPUT | GPIO_INIT_LOW),

          (GPIO_OUTPUT | GPIO_INIT_LOW),

          (GPIO_OUTPUT | GPIO_INIT_HIGH),

          (GPIO_OUTPUT | GPIO_INIT_HIGH),

          (GPIO_OUTPUT | GPIO_INIT_HIGH),

          (GPIO_OUTPUT | GPIO_INIT_HIGH), (GPIO_OUTPUT | GPIO_INIT_HIGH), (GPIO_OUTPUT | GPIO_INIT_HIGH),

          (GPIO_OUTPUT | GPIO_INIT_HIGH), // A0_GPIO_PIN

          (GPIO_OUTPUT | GPIO_INIT_LOW), // A1_GPIO_PIN

          (GPIO_OUTPUT | GPIO_INIT_HIGH), // A2_GPIO_PIN

          0, 0, 0, 0,

          0 // (GPIO_OUTPUT | GPIO_INIT_LOW), // ADC input pin

          // 0, 0, 0

          }

      };