Arduino IDE, Uno3 and eclipse[SOLVED]

Hi,
I've been writing a library for the Arduino Uno3 using the Arduino IDE. I have downloaded the latest version and I am running on a Windows 7 64bit system. Unfortunately the IDE seems to be riddled with minor bugs, mostly display bugs. I would like to use eclipse as I have experience with it and like using it.

However I've tried several times to get it working with the tutorial found on this site and so far I haven't made much progress. I have the AVR installed. In the tutorial I get to the section on configuring the AVRDude, but I don't see the Uno3 listed as a target and they're seem to be quite a few options that aren't mentioned.

I would use the Arduino IDE, but I have hit a problem which I cannot figure out why it isn't working, so I really need to debug the source. The library I'm writing will allow you to create timer objects then an interrupt will check the timers and flag a timer as expired so its callback can be called.

Here is the definition, Timer.h

/**
 * File:
 *  Timer.h
 *  
 * Notes:
 *  This file contains the prototype for the class clsTimer.
 *  
 * Methods:
 *  clsTimer      Class constructor
 *  ~clsTimer     Class destructor
 *  expire        Flags that a timer should be serviced 
 *  expired       Called when timer expires 
 *  interval      Returns the interval either m_intInitial or m_intRepeat 
 *  next          Returns pointer to next timer in linked list   
 * 
 * Members:
 *  m_blnCalled   Flag to indicate if timer has been called 
 *  m_intInitial  The initial time(ms) before the timer expires
 *  m_intRepeat   Optional, repeat time(ms) before the expiration, 0 = not used
 *  m_pCallback   Call-back routine to call when timer expires
 *  m_pData       Data to associate with this instance  
 *         
 * History:
 *  22/01/2012  Created by Simon Platten
 */            
#ifndef TIMER_MANAGER_H
  #define TIMER_MANAGER_H
  
  #include <Arduino.h>
  
  class clsTimer {
  private:  
// Flag to indicate if timer has been called
    bool m_blnCalled;
// true if timer ready to be service, false it not    
    bool m_blnExpire;
// The initial time(ms) before the timer expires  
    int m_intInitial;
// Optional, repeat time(ms) before the expiration, 0 = not used
    int m_intRepeat;    
// Call-back routine to call when timer expires
    void (*m_pCallback)(clsTimer* pTimer);
// Data to associate with this instance
    void* m_pData;
// Next timer in Linked-list
    clsTimer* m_pNext;
// Called to expire timer object    
    void      expire();
// Returns the interval either m_intInitial or m_intRepeat    
    int       interval();
// Returns next timer in linked list
    clsTimer* next();    

  public:
    static void checkTimers();
    static void serviceTimers();
          
  public:
    clsTimer(int intInitial,               
             void (*pCallback)(clsTimer* pTimer), 
             void *pData = NULL,
             int intRepeat = 0);
    ~clsTimer();    
  };
#endif

Here is the implementation, Timer.cpp:

/**
 * File:
 *  Timer.cpp
 *  
 * Notes:
 *  This file contains the implementation of the class clsTimer.
 *
 * History:
 *  22/01/2012  Created by Simon Platten
 */  
#include "Timer.h"
// Pointer to all timers linked list
static clsTimer* pAllTimers = NULL;
// Counter used by ISR, incremented every interrupt
static volatile int intTmrISRctr;
/**
 * Interupt Service Routine, called every 1ms to check all timers
 */ 
ISR(TIMER2_OVF_vect) {
  TCNT2 = 0x06;
// Increment the counter and check timer resources
  intTmrISRctr++;
  clsTimer::checkTimers();
};
/**
 * Timer constructor
 *  
 * Paramters:
 *  intInitial, the initial expiration time in ms
 *  pCallback,  the routine to call when the timer expires
 *  pData,      pointer to data block accessible for this timer  
 *  intRepeat,  optional, repeat time in ms for subequent calls
 */         
clsTimer::clsTimer(int intInitial, 
                   void (*pCallback)(clsTimer* pTimer), 
                   void *pData,
                   int intRepeat) {
  if ( intInitial > 0 && pCallback != NULL ) {
// Disable interrupts    
    cli();
    
    if ( pAllTimers == NULL ) {
// Reset counter      
      intTmrISRctr = 0;
// Set-up interrupt      
      TCNT2 = 0x00;
      OCR2A = 250;		        // 1 ms @ Fosc = 16 MHz
      TCCR2A = 0x02;          // WGM: No wave generation
      TCCR2B = 0x04;          // START Timer, prescaler = 64
      TIMSK2 = (1 << TOIE2);  // Enable interrupt when Timer reaches OCRA
    }
// Configure this timer    
    m_intInitial = intInitial;    
    m_pCallback = pCallback;
    m_pData = pData;
    m_intRepeat = ( intRepeat > 0 ) ? intRepeat : 0;
    m_blnCalled = m_blnExpire = false;
// Insert this timer into the list of all timers
    m_pNext = pAllTimers;    
// Insert this timer at the beginning of the linked list    
    pAllTimers = this;
// Re-enable interrupts
    sei();    
  }
}
/**
 * Destructor
 */ 
clsTimer::~clsTimer() {
}
/**
 * Checks all timers to see if any have expired
 */ 
void clsTimer::checkTimers() {
// Disable interrupts whilst checking
  cli();
// Check all timers
  int intCounter = intTmrISRctr; 
  for( clsTimer* pTimer=pAllTimers; pTimer!=NULL; pTimer->next() ) {
    int intInterval = pTimer->interval();
    
    if ( (intCounter % intInterval) == 0 ) {
digitalWrite(12, HIGH);        
// Expire this timer, this will flag that its ready to be serviced
      pTimer->expire();
    }
  }
// Re-enable interrupts  
  sei();
}
/**
 * Sets flag to indicate that timer is ready to be serviced
 */        
void clsTimer::expire() {
  m_blnExpire = true;
}
/**
 * Gets the current timer interval
 */         
int clsTimer::interval() {
  int intInterval;
  if ( m_blnCalled == false ) {
    intInterval = m_intInitial;
  } else {
    intInterval = m_intRepeat;
  }
  return intInterval;
}
/**
 * Gets the next timer object in the linked list
 */        
clsTimer* clsTimer::next() {
  return m_pNext;
}
/**
 * Should be called in main loop to service any expired timers
 */  
void clsTimer::serviceTimers() {
  for( clsTimer* pTimer=pAllTimers; pTimer!=NULL; pTimer->next() ) {
    if ( pTimer->m_blnExpire == false ) {    
      continue;
    }    
// Timer has expired, clear flag
    pTimer->m_blnExpire = false;    
// Set initial call flag so we know the next call will be using the repeat time
    pTimer->m_blnCalled = true;
// Perform call-back  
    (*pTimer->m_pCallback)(pTimer);  
  }
}

Line 83, the digitalWrite for pin 12 turns on an LED, this is just a crude effort to see where the flow is getting to, it never comes on.

Here is some demo code to use the class:

#include <Timer.h> 

bool blnOn = false;

void led13(clsTimer* pTmr) {
  if ( blnOn == false ) {
    digitalWrite(13, HIGH);  
    blnOn = true;
  } 
  else {
    digitalWrite(13, LOW);      
    blnOn = false;
  }
}

clsTimer objTmr1( 5000, led13, NULL, 5000 );

void setup() {
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
}


void loop() {
  clsTimer::serviceTimers();
}

I have 3 LED's wired to pins 13, 12 and 11, the idea is that when the timer expires after 5000ms it will light the LED on pin 13, then toggle it every 5000ms there after.

I have played around with this but something strange is happening in the ISR, the logic:

    if ( (intCounter % intInterval) == 0 ) {

Never seems to evalulate to true.

Any ideas?

Thank you,

I'm confident that if I could get eclipse working correctly I could track down and solve this problem myself. However, I'm struggling to get eclipse configured correctly, I've tried to follow the instructions here:

http://arduino.cc/playground/Code/Eclipse#Eclipse_and_additional_plugins

However it doesn't quite work for me.

Does anyone have an example project that I could edit? I think I have eclipse configured ok and AVRDude set-up.

Thank you

Unfortunately it would seem that eclipse cannot debug arduino projects either...ATM.

So anyone any suggestions to what the problem could be in my interrupt handler?

I have found the problem, so simply, but now works well, will post library when I know where to post it.