new and delete operators in Teensy 3.0

Status
Not open for further replies.

Pedvide

Senior Member+
Hello,

I'm trying to use the IntervalTimer library with the adc to get periodic readings. I want to create a new IntervalTimer object with:

Code:
timerPin[i].timer = new IntervalTimer();

That line is inside a function in the ADC library (ADC.cpp). timerPin is a struct defined in the ADC.h header file:

Code:
typedef struct{
            int pinNumber = -1; // the timer is deactivated
            IntervalTimer *timer; // timer
            RingBuffer *buffer; // circular buffer to store analog values

} IntervalTimerPin;

IntervalTimerPin timerPin[MAX_ANALOG_TIMERS];

The linker gives an error:
Arduino: 1.0.5 (Windows 7), Board: "Teensy 3.0"
ADC\ADC.cpp.o: In function `ADC::startAnalogTimer(unsigned char, unsigned int)':
C:\Users\User\Arduino\libraries\ADC/ADC.cpp:508: undefined reference to `operator new(unsigned int)'
collect2.exe: error: ld returned 1 exit statuss


In a simple sketch (Blinker) I can do:

Code:
  int *p;
p = new int(3);

So I have no idea what the problem is. I'm not an expert C++ programmer, so I don't know what to do. Can you help me?
 
I'm only slightly dangerous in using C++ on small micros...

I'd create the object once and never delete it. Declare it as static so it instantiates only once, at startup.

new() and delete() are uncommon on small-RAM processors. If you do the above, you'll not need to call new() explicitly.
 
Do you have #include "Arduino.h"? The only reason I can see for that error is not having the right headers included.

For example, this code works within the VirtualWire library:

Code:
#elif defined(__arm__) && defined(CORE_TEENSY)
    // on Teensy 3.0 (32 bit ARM), use an interval timer
    IntervalTimer *t = new IntervalTimer();
    t->begin(TIMER1_COMPA_vect, 125000.0 / (float)(speed));
 
Thanks for the answers. I'm looking into it, but it looks like I need to change the approach to this problem...
I'll make a new post as it is a completely different thing.
 
Status
Not open for further replies.
Back
Top