Hall sensors and AttachInterrupt()

Thanks for the response, but I'm still having trouble.

If you have declared the recPulse method static

I know how to declare an individual variable as static, but I've not tried this with a method before, and when I do it just seems to generate more errors. As you can see from the sketch I've actually managed to work around the problem by setting up the interrupt in the sketch and causing it to call a function from the library, but I'd still like to know how to do this properly!

I've attached a stripped down, but working version of the files (working except for the compile error!)

Here's the full .h file...

#ifndef HallPulseCounter_h                                   // These lines (together with the #endif at the end of the file) prevent
#define HallPulseCounter_h                                   // any problems occuring if this library should be included twice.

extern "C" {
  #include <string.h>
}

#include <stdlib.h>                                          // needed for 'free'
#include "WProgram.h"                                        // needed for 'Serial'
#include <avr/pgmspace.h>                                    // Needed for PROGMAN stuff
#include <ProgmemConst.h>                                    // Global progmem constants

const int HALL_ARRAY_SIZE=6;                                 // Size of array that holds pulse timestamps 
const int MAX_AGE=6000;                                      // Maximum age of any recorded pulse.

// If defined, data will be writen to a logfile as well as displayed on screen
//#define DEBUG_LOG

class HallPulseCounter
{
  public:
    HallPulseCounter();                                      // Constructor
    void begin(int pin);                                     // Set the pin that the probe is connected to
    //int getFreq(void);                                       // Return the pulse frequency in RPM
    void recPulse();                                         // Record the moment a pulse occurs

  private:
    // Member variables
    char * _info;                                            // Temporary storage used for holding strings (normally error messages) 
                                                             // for logging to SD card.
    unsigned long _pulse[HALL_ARRAY_SIZE];                   // array of timestamps of most recent pulses.

};

#endif

And the full .cpp file....

extern "C" {
  #include <string.h>
}

#include <stdlib.h>                        // needed for 'free'
#include "WProgram.h"                      // needed for 'Serial'
#include "HallPulseCounter.h"              // header for this library
#include <avr/pgmspace.h>                  // Needed for PROGMAN stuff
#include <ProgmemConst.h>

#ifdef DEBUG_LOG
SingLog2 *logComp = SingLog2::GetLogger();  // Global (to this class) singleton logger.
#endif


/**************************************************************************
  Constructor
**************************************************************************/
HallPulseCounter::HallPulseCounter()
{
  _info = gMedBuff;                    // link the local info buffer to the global buffer (defined in ProgmemConst.cpp)
}


/**************************************************************************
  Set the pin that the probe is connected to.
**************************************************************************/
void HallPulseCounter::begin(int pin)                       
{
  int interrupt =0;

  // define the pin as an INPUT
  pinMode(pin, INPUT);

  // attach the appropriate interrupt
  attachInterrupt(interrupt,recPulse,FALLING);
  //attachInterrupt(interrupt,HallPulseCounter::recPulse,FALLING);
  //attachInterrupt(interrupt,HallPulseCounter.recPulse,FALLING);
  //attachInterrupt(interrupt,HallPulseCounter->recPulse,FALLING);
  //attachInterrupt(interrupt,this->recPulse,FALLING);

}


/**************************************************************************
  Record the moment that a pulse was detected by the hall probe
**************************************************************************/
void HallPulseCounter::recPulse()
{

  
  // Load the timestamp for this pulse into the top of the array. 
  _pulse[0] = millis();

}

And sketch to test....

#include <stdlib.h>                        // needed for 'free'
#include "WProgram.h"                      // needed for 'Serial'
#include <Wire.h>                          // Library to control I2C comunications
#include <avr/pgmspace.h>                  // Needed for PROGMAN stuff
#include <ProgmemConst.h>                  // Global progmem constants
#include <HallPulseCounter.h>              // Rev-counter library based on hall-effect probe.

int rpm = 0;

HallPulseCounter cadence1;                

void setup() 
{
  Serial.begin(115200); // start serial communication at 9600bps 

  Serial.println("##################################################################");
  Serial.println("####################     START     ###############################");
  Serial.println("##################################################################");
  
  cadence1.begin(3);  // Connect hall sensor to pin 3 (interrupt 1)
  
  attachInterrupt(1,recordPulse,FALLING);
  
}

void loop() 
{
  //rpm=cadence1.getFreq();

  Serial.print("rpm <");  Serial.print(rpm);  Serial.println("> (revs per min)");
  delay(100); // wait for half a second
}

void recordPulse()
{
  cadence1.recPulse();
}