Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 9 months ago.
PwmOut: Reading without interrupting/stopping the output?
In using the PwmOut library function, if I set the PwmOut active, but then perform another method, such as PwmOut.read(), the method will execute correctly and return the duty cycle etc, but the PwmOut wave will stop.
Is a) this supposed to happen this way - because the impression I get from reading the docs is that you should be able to read duty cycle, alter period times etc with the output still active? b) There a way around this error?
For example, the following code will work fine:
Example of code working as expected
PwmOut out(LED1); int main() { out.period(1.0); out = 0.5; while(1); }
Whilst the following code will not give a flashing LED/PwmOut output, presumably because it stops being active when the instruction after the operator is executed
Example of code that is not working as expected
PwmOut out(LED1); int main() { out.period(1.0); out = 0.5; float duty = out.read(); while(1); }
1 Answer
9 years, 7 months ago.
David,
What board are you using? I have tried your sample code with both the K64F and the Nucleo 411 and have had no problems.
That really shouldn't happen. Can you verify your mbed library is updated (right click, update). If the problem persists I can have a look at it later. But it seems really weird to me. This is for the LPC1768?
posted by Erik - 20 Feb 2015