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.
Fork of frdm_rgbled by
main.cpp
- Committer:
- skanderian
- Date:
- 2016-05-13
- Revision:
- 8:47c89e2ae2e6
- Parent:
- 7:ad8295723268
- Child:
- 9:76be39e5d5ab
File content as of revision 8:47c89e2ae2e6:
#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); 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; wait(dt); } } }