Using interrupts in header files

Hi guys,

I am trying to implement an InterruptIn as a part of a PwmIn header file. When the .rise & .fall conditions occur I would like to call a function (also held within the header file) however, I am not sure of the correct methodology/syntax in OS 6 to achieve this. The lines _pwm.rise(&PwmIn::rise) and _pwm.fall(&PwmIn::rise) generate the following error:

No viable conversion from 'void (PwmIn::*)()' to 'Callback<void ()>'clang(typecheck_nonviable_condition)

my headerfile…

#ifndef PWMIN_H
#define PWMIN_H

#include "mbed.h"

class PwmIn{
    //create PWM input object
    PwmIn(PinName pwm);
    //returns the period of the signal in seconds
    float readPeriod();
    //returns the ducty cycle of the signal as a decimal percentage
    float readDutyCycle();

    InterruptIn _pwm;
    Timer _timer;
    void rise();
    void fall();
    float _period;
    float _pulseWidth;


#include "PwmIn.h"
#include <chrono>

PwmIn::PwmIn(PinName pwm) : _pwm(pwm){
                _period = 0.0;
                _pulseWidth = 0.0;

float PwmIn::readPeriod() {
    return _period;

float PwmIn::readDutyCycle() {
    return _pulseWidth / _period;

void PwmIn::rise() {
    _period = chrono::duration_cast<std::chrono::seconds>(_timer.elapsed_time()).count();

void PwmIn::fall() {
    _pulseWidth = chrono::duration_cast<std::chrono::seconds>(_timer.elapsed_time()).count();

Any help regarding how to call these functions correctly would be greatly appreciated!!

Thanks in advance,



this was already discussed and it is already done PWMIN library bugs - Mbed OS - Arm Mbed OS support forum

BR, Jan

Ah! Thank you very much!