On the FRDM-KL25Z, when I declare pins PTA5 and PTD2 as PwmOut pins, they are locked together and can not be independently controlled. It doesn't matter if I change the PWM of PTA5 or PTD2. Whichever one is changed, the other one follows it. The simple code below should keep pin PTD2 at 0% pwm while pin PTA5 should switch between 50% and 0% every 0.5 seconds. Pin PTA5 does alternate between 50% and 0% pwm, but instead of staying at 0% pwm, pin PTD2 follows pin PTA5.

Dependencies:   mbed

Fork of frdm_rgbled by Freescale

Committer:
skanderian
Date:
Fri Jul 08 23:10:16 2016 +0000
Revision:
9:76be39e5d5ab
Parent:
8:47c89e2ae2e6
Test PwmOut of pins PTA5 and PTD2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
skanderian 9:76be39e5d5ab 1 /*Can not independently PWM control pins PTA5 and PTD2.
skanderian 9:76be39e5d5ab 2 When pins PTA5 and PTD2 are declared as PwmOut pins, they are locked together and can not be independently controlled.
skanderian 9:76be39e5d5ab 3 This code should keep pin PTD2 at 0% pwm while pin PTA5 should switch between 50% and 0% every 0.5 seconds.
skanderian 9:76be39e5d5ab 4 Pin PTA5 does alternate between 50% and 0% pwm, but instead of staying at 0% pwm, pin PTD2 follows pin PTA5.
skanderian 9:76be39e5d5ab 5 by Sami Kanderian 7/8/2016
skanderian 9:76be39e5d5ab 6 */
chris 0:cf8a48b1fb23 7 #include "mbed.h"
chris 0:cf8a48b1fb23 8
skanderian 9:76be39e5d5ab 9 PwmOut pwmPelCooler(PTA5);
skanderian 9:76be39e5d5ab 10 PwmOut pwmCapHeater(PTD2);
chris 0:cf8a48b1fb23 11
sam_grove 7:ad8295723268 12 int main()
sam_grove 7:ad8295723268 13 {
skanderian 9:76be39e5d5ab 14 double dt=0.5f;
skanderian 9:76be39e5d5ab 15 pwmPelCooler.period(0.001f);
skanderian 9:76be39e5d5ab 16 pwmCapHeater.period(0.001f);
skanderian 9:76be39e5d5ab 17 wait(0.5);
skanderian 9:76be39e5d5ab 18 pwmPelCooler=0.5f;
skanderian 9:76be39e5d5ab 19 pwmCapHeater=0.0f;
skanderian 9:76be39e5d5ab 20 bool mySwitch = false;
skanderian 9:76be39e5d5ab 21 while(true) {
skanderian 9:76be39e5d5ab 22
skanderian 9:76be39e5d5ab 23 mySwitch=!mySwitch;
skanderian 9:76be39e5d5ab 24 if (mySwitch) {
skanderian 9:76be39e5d5ab 25 pwmPelCooler=0.5f;
skanderian 9:76be39e5d5ab 26 } else {
skanderian 9:76be39e5d5ab 27 pwmPelCooler=0.0f;
skanderian 9:76be39e5d5ab 28 }
skanderian 8:47c89e2ae2e6 29 wait(dt);
chris 1:eabc6f5b51d6 30 }
skanderian 9:76be39e5d5ab 31 }