Teensy 3.0 and PIT interrupts

Status
Not open for further replies.

Infras

New member
Hi,
I'm new to MCU programmation and especially to Arduino. I have a Teensy 3.0 board and i would like to use a timer in order to read a sensor every t ms. I already searched thread about my problem over this forum but i didn't find the solution. I past you the code :
Code:
#include <avr/io.h>
#include <avr/interrupt.h>

void pit1_isr(void)
{
  Serial.println("Interrupt");
  PIT_TFLG1 = 1;
}

void setup()
{
}

void pit_init()
{
  SIM_SCGC6 |= SIM_SCGC6_PIT; // Activates the clock for PIT
  PIT_MCR = 0x00;    // Permet l'enable du PIT (Periodic Interrupt Timer)
  NVIC_ENABLE_IRQ(IRQ_PIT_CH1); // Another step to enable PIT channel 1 interrupts  (sur l'ARM)
  PIT_LDVAL1 = 0x2fa080; // Choisi la durée du timer 0 (voir p823 et 825 (36.4.1.1) de la datasheet pour changer la valeur)
  // ici on a 1s
  PIT_TFLG1 |= 0x01; // On clean le flag du timer 0
  PIT_TCTRL1 |= 0x02; // Autorisation des interrupts sur le timer 0
}


void loop()
{
}

When i compile, I got this error :

IntervalTimer.cpp.o: In function `IntervalTimer::disable_PIT()':
C:\Program Files (x86)\Arduino\hardware\teensy\cores\teensy3/IntervalTimer.cpp:40: multiple definition of `pit1_isr'
sketch_dec10b.cpp.o:C:\Program Files (x86)\Arduino/sketch_dec10b.ino:5: first defined here
collect2.exe: error: ld returned 1 exit status

If someone could help me, I would be grateful.

Thank you,

Infras
 
You can't use the PIT timers directly, because they're used by IntervalTimer. Well, unless of course you edit the code library and delete IntervalTimer, which you could certainly do.

The intention is to use the IntervalTimer API for access to the PIT timers.

http://www.pjrc.com/teensy/td_timing_IntervalTimer.html

The tone() function and several libraries use the IntervalTimer API. Having the PIT timers used by IntervalTimer allows all those libraries to share and dynamically allocate from the pool of 4 PIT timers, which couldn't be done if each library simply hard coded a specific PIT timer (as the tone function did before IntervalTimer was added).
 
Hi Paul,

Great ! I lost my entire day to solve this problem. It will be easier and lighter to use.

Thanks :)

Infras
 
Status
Not open for further replies.
Back
Top