FRDM KL25Z ComparatorIn: using a member function

27 Jun 2017

Hello!

I am trying to implement ComparatorIn class for KL25Z: https://developer.mbed.org/users/frankvnk/code/ComparatorIn/#e6a4cd28e217

I have to use in an interrupt a function that is a class member, but ComparatorIn class seems to accept only static functions. Is there any possibility to overcome this problem?

Here is a piece of my code:

Sampler.cpp

#include "Sampler.h"
#include "mbed.h"

volatile int CompiTime;
volatile int CompiCounter;
volatile uint8_t Flag;


Sampler::Sampler(MC23LCV1024& _sram, PinName CompIn, PinName ADCIn): sram(_sram), ADC(ADCIn)
{
    compi = new ComparatorIn(CompIn, NC);
    timeout = new Timeout;
    
}


void Sampler::ISR_Timeout(void)
{
    compi->rising(NULL);
    Flag |= (1<<FREQUENCY_MEAS);
}

void Sampler::ISR_Compi(void)
{
    if(CompiCounter == 0) timer.start();
    else
    {
        CompiTime = timer.read_us();
        CompiCounter++;
    }
}


void Sampler::GetFrequency(void)
{    
    compi->treshold(0.5);                       
    compi->FilterPeriod(250);
    compi->FilterCount(3);
    CompiTime = 0;
    CompiCounter = 0;
    timer.reset();
    
    timeout->attach(callback(this, &Sampler::ISR_Timeout), 10.0);
    compi->rising(this, &Sampler::ISR_Compi);         
   
    while(!(Flag & (1<<FREQUENCY_MEAS)));
    
    Frequency = (1000000.0*(float)CompiCounter) / (float)CompiTime;
    SamplingPeriod = (1/Frequency) / 204.8;  
}

Line 44 of above code results in error Error: Argument of type "Sampler *" is incompatible with parameter of type "void (*)()" in "Sampler.cpp"

I will be very grateful for any possible solutions.