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@7:ad8295723268, 2014-07-16 (annotated)
- Committer:
- sam_grove
- Date:
- Wed Jul 16 10:20:45 2014 +0000
- Revision:
- 7:ad8295723268
- Parent:
- 5:14891bb08b35
- Child:
- 8:47c89e2ae2e6
update formatting and mbed library
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); |
chris | 0:cf8a48b1fb23 | 5 | |
sam_grove | 7:ad8295723268 | 6 | int main() |
sam_grove | 7:ad8295723268 | 7 | { |
sam_grove | 7:ad8295723268 | 8 | r.period(0.001f); |
sam_grove | 7:ad8295723268 | 9 | g.period(0.001f); |
chris | 1:eabc6f5b51d6 | 10 | |
emilmont | 2:03e5c29343d1 | 11 | while (true) { |
sam_grove | 7:ad8295723268 | 12 | for (float i = 0.0f; i < 1.0f ; i += 0.001f) { |
chris | 1:eabc6f5b51d6 | 13 | float p = 3 * i; |
sam_grove | 7:ad8295723268 | 14 | r = 1.0f - ((p < 1.0f) ? 1.0f - p : (p > 2.0f) ? p - 2.0f : 0.0f); |
sam_grove | 7:ad8295723268 | 15 | g = 1.0f - ((p < 1.0f) ? p : (p > 2.0f) ? 0.0f : 2.0f - p); |
sam_grove | 7:ad8295723268 | 16 | wait (0.0025f); |
chris | 1:eabc6f5b51d6 | 17 | } |
chris | 1:eabc6f5b51d6 | 18 | } |
sam_grove | 7:ad8295723268 | 19 | } |