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

Revision:
9:76be39e5d5ab
Parent:
8:47c89e2ae2e6
--- a/main.cpp	Fri May 13 19:04:14 2016 +0000
+++ b/main.cpp	Fri Jul 08 23:10:16 2016 +0000
@@ -1,49 +1,31 @@
+/*Can not independently PWM control pins PTA5 and PTD2.
+When pins PTA5 and PTD2 are declared as PwmOut pins, they are locked together and can not be independently controlled.
+This code 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.
+by Sami Kanderian 7/8/2016
+*/
 #include "mbed.h"
 
-PwmOut r(LED_RED);
-PwmOut g(LED_GREEN);
-PwmOut b(LED_BLUE);
-double rn1;
-double rn2;
-double rn3;
-
-double dt=0.025f;
-double tau=0.125;//0.55
-double gain = 0.2;
-double c0=exp(-dt/tau);
-double c1=1-c0;
-int N=(int)(3*tau/dt);
+PwmOut pwmPelCooler(PTA5);
+PwmOut pwmCapHeater(PTD2);
 
 int main()
 {
-    r.period(0.001f);
-    g.period(0.001f);
-    b.period(0.001f);
-    rn1=0;
-    rn2=0;
-    rn3=0;
-    
-    while (true) {
-        
-        
-        rn1=rand()/(float)RAND_MAX;
-        rn2=rand()/(float)RAND_MAX;
-        rn3=rand()/(float)RAND_MAX;
-        rn1=gain*rn1+(1-gain);
-        rn2=gain*rn2+(1-gain);
-        rn3=gain*rn3+(1-gain);        
-        
-        for(int i=0; i<N; ++i){
-        
-        r=c0*r+c1*rn1;
-        g=c0*g+c1*rn2;
-        b=c0*b+c1*rn3;
-        
+    double dt=0.5f;
+    pwmPelCooler.period(0.001f);
+    pwmCapHeater.period(0.001f);
+    wait(0.5);
+    pwmPelCooler=0.5f;
+    pwmCapHeater=0.0f;
+    bool mySwitch = false;
+    while(true) {
+
+        mySwitch=!mySwitch;
+        if (mySwitch) {
+            pwmPelCooler=0.5f;
+        } else {
+            pwmPelCooler=0.0f;
+        }
         wait(dt);
-        }
-          
-        
     }
-    
-    
-}
+}
\ No newline at end of file