The PWM HW block will be turned off when the device sleeps. With SDK 1.0.1, sleep was disabled globally, while with SDK 1.1.0, sleep is enabled for all applications. Disable sleep using the mechanism in uart_firmware_upgrade sample app using devlpm_registerForLowPowerQueries (if you are running a state machine when using the PWM, you may also return max time to sleep from the callback you register here if you know when in the future the PWM will start and disable sleep by returning 0x00 only when the PWM needs to be active to conserve power).
Just to clarify we have these issues:
We could not get PWM to work on P13 and P14. Although We can get it to work on pins P26, P27, and P28. This is regardless of the SDK version.
The PWM signal does not come out right (on the working pins i.e. P26, P27, and P28) if I use SDK 1.1.0 while the same code produces a PWM signal as expected if SDK 1.0.1 is used. The PWM signal using SDK 1.1.0 has inconsistent pulse width and changes frequency after a while. This issue is reproducible on broadcom tag as well running the hello_sensor sample code. If SDK 1.1.0 is used the buzzer sounds distorted.
I wanted to check in to see if you were still having problems getting the PWM to work correctly.
If this is still a problem, take a look at the PWM sample app called pwm_tones in SDK 2.0.1 as this is a good reference for how to configure and use the PWM block. Note that this sample will work with SDK 1.1 as well.
pwm_tones sample app is not very helpful here since they chose pins/PWMs that nobody has a problem with. Is there any other reference showing how to use PWM on the faulty P13/P14 ?
And yes, I tried to change pins in pwm_tones app to use P13/P14 but it did not work.
I will work with the firmware team to see if we can get this resolved.
As it turns out, P13 and P14 are somewhat unique and the PWM output needs to be enabled a little bit differently on these two.
First enable/start PWM:
pwm_start(PWM2, LHL_CLK, toggle_value, init_value); //// OR PWM3
Then output it on a GPIO:
If you want it on P28:
gpio_configurePin(28/16, 28%16, GPIO_OUTPUT_ENABLE, GPIO_OUTPUT_LOW); ///// OR 29/16, 29%16 when P29 is available in the package.
If you want the PWM output on P14:
gpio_configurePin(14/16, 14%16, (2 << 4), GPIO_OUTPUT_LOW); ///// OR 13/16, 13%16 when using PWM3
PWM2 is also available on P6 in which case the additional output to GPIO step should be:
gpio_configurePin(6/16, 6%16, (1 << 4) | GPIO_OUTPUT_ENABLE , GPIO_OUTPUT_LOW);
Note that this procedure will be documented in the next SDK release.
This occurs because sleep was disabled in 1.0.1, but enabled with 1.1.0 (and you will see the same behavior in 2.x). PWM does not function when sleeping. There are two options:
1. Disable sleep by registering a callback and then returning 0x00 when invoked for sleep.
2. Use LHL_CLK parameter when starting the PWM instead of PMU_CLK like in the sample. You may have to re-calculate the init and toggle values. The reference LHL clock is ~128KHz, so higher frequencies are not possible.