9 years, 2 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);
}

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

1 Answer

9 years 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.

Accepted Answer

Looks like you account has a LPC1768 registered to it. I've tested with the latest version (96) of the mbed library and your program and cannot reproduce. If updating the library doesnt work for you, please publish an example (crtl + shift + u) from the IDE

posted by Sam Grove 14 Apr 2015