PwmIn library, Errorhandling?

How do I detect that the input signal is lost when using PwmIn.pulsewidth() ?
The lib keeps returning the last correct value even after I remove the input signal.
I need some kind of error indication.
I still work in the classic IDE, with a NXP1768.


I have no experience with PwmIn (it is probably this one - PwmIn | Mbed ), but it seems to be very simple library.
Yea of course, the values of variables what are returned via some few methods are changed only during interrupts on the pin. So when you disconnect the signal, there are no interrupts, so the values do not change.

So, you need to do some changes in the library.

  • you can periodically check the timer if the value is not too high…
  • you can implement a TimeOut and periodically reattach it during interrupt of the pin. No interrupt = No reattaching = no reset of timeout and that will tell you it is out
  • you can add a simple boolean flag. The flag can be repeatedly set to true during interrupt. While reading of the pulse width just check the flag.
    If flag is true set it back to false and return real value.
    If flag is false return an error value or something.
  • maybe exist another variants

BR, Jan

Thank you for your replay.

I was hoping you would say, “Use this lib instead…” but I will follow one of your suggestions and fix an error detection method.

Brest regards, Stefan