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@8:47c89e2ae2e6, 2016-05-13 (annotated)
- Committer:
- skanderian
- Date:
- Fri May 13 19:04:14 2016 +0000
- Revision:
- 8:47c89e2ae2e6
- Parent:
- 7:ad8295723268
- Child:
- 9:76be39e5d5ab
Digital equivalent of an RC filter where the inputs are three random numbers and the output is the intensity of the built in RGB LEDs.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chris | 0:cf8a48b1fb23 | 1 | #include "mbed.h" |
chris | 0:cf8a48b1fb23 | 2 | |
Kojto | 5:14891bb08b35 | 3 | PwmOut r(LED_RED); |
Kojto | 5:14891bb08b35 | 4 | PwmOut g(LED_GREEN); |
skanderian | 8:47c89e2ae2e6 | 5 | PwmOut b(LED_BLUE); |
skanderian | 8:47c89e2ae2e6 | 6 | double rn1; |
skanderian | 8:47c89e2ae2e6 | 7 | double rn2; |
skanderian | 8:47c89e2ae2e6 | 8 | double rn3; |
skanderian | 8:47c89e2ae2e6 | 9 | |
skanderian | 8:47c89e2ae2e6 | 10 | double dt=0.025f; |
skanderian | 8:47c89e2ae2e6 | 11 | double tau=0.125;//0.55 |
skanderian | 8:47c89e2ae2e6 | 12 | double gain = 0.2; |
skanderian | 8:47c89e2ae2e6 | 13 | double c0=exp(-dt/tau); |
skanderian | 8:47c89e2ae2e6 | 14 | double c1=1-c0; |
skanderian | 8:47c89e2ae2e6 | 15 | int N=(int)(3*tau/dt); |
chris | 0:cf8a48b1fb23 | 16 | |
sam_grove | 7:ad8295723268 | 17 | int main() |
sam_grove | 7:ad8295723268 | 18 | { |
sam_grove | 7:ad8295723268 | 19 | r.period(0.001f); |
sam_grove | 7:ad8295723268 | 20 | g.period(0.001f); |
skanderian | 8:47c89e2ae2e6 | 21 | b.period(0.001f); |
skanderian | 8:47c89e2ae2e6 | 22 | rn1=0; |
skanderian | 8:47c89e2ae2e6 | 23 | rn2=0; |
skanderian | 8:47c89e2ae2e6 | 24 | rn3=0; |
skanderian | 8:47c89e2ae2e6 | 25 | |
emilmont | 2:03e5c29343d1 | 26 | while (true) { |
skanderian | 8:47c89e2ae2e6 | 27 | |
skanderian | 8:47c89e2ae2e6 | 28 | |
skanderian | 8:47c89e2ae2e6 | 29 | rn1=rand()/(float)RAND_MAX; |
skanderian | 8:47c89e2ae2e6 | 30 | rn2=rand()/(float)RAND_MAX; |
skanderian | 8:47c89e2ae2e6 | 31 | rn3=rand()/(float)RAND_MAX; |
skanderian | 8:47c89e2ae2e6 | 32 | rn1=gain*rn1+(1-gain); |
skanderian | 8:47c89e2ae2e6 | 33 | rn2=gain*rn2+(1-gain); |
skanderian | 8:47c89e2ae2e6 | 34 | rn3=gain*rn3+(1-gain); |
skanderian | 8:47c89e2ae2e6 | 35 | |
skanderian | 8:47c89e2ae2e6 | 36 | for(int i=0; i<N; ++i){ |
skanderian | 8:47c89e2ae2e6 | 37 | |
skanderian | 8:47c89e2ae2e6 | 38 | r=c0*r+c1*rn1; |
skanderian | 8:47c89e2ae2e6 | 39 | g=c0*g+c1*rn2; |
skanderian | 8:47c89e2ae2e6 | 40 | b=c0*b+c1*rn3; |
skanderian | 8:47c89e2ae2e6 | 41 | |
skanderian | 8:47c89e2ae2e6 | 42 | wait(dt); |
chris | 1:eabc6f5b51d6 | 43 | } |
skanderian | 8:47c89e2ae2e6 | 44 | |
skanderian | 8:47c89e2ae2e6 | 45 | |
chris | 1:eabc6f5b51d6 | 46 | } |
skanderian | 8:47c89e2ae2e6 | 47 | |
skanderian | 8:47c89e2ae2e6 | 48 | |
sam_grove | 7:ad8295723268 | 49 | } |