Arduino Forum upgrade scheduled for Monday, October 20th, 11am-4pm (CEST). Sorry for the inconvenience!
Pages: [1]   Go Down
Author Topic: Problem with ISR(TIMER0_OVF_vect)  (Read 4123 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I want to write a program that allows me to read a sum signal from my RC-receiver.

Here is my code:
Code:
volatile unsigned char cSumSig[8]; //Array to store the channels
volatile uint8_t iCounter=0,iValid=0;

//***************************************************************
//If I delete this code then Arduino compiles
ISR(TIMER0_OVF_vect) {
  iCounter=0;                        // Reset Counter on Overflow
  iValid=0;                        // "disable" Timer 'till next rising
}
//***************************************************************

ISR(INT0_vect) {
  if(iValid==1) {                        // don't count before first pulse
    cSumSig[iCounter] = TCNT0;            // save pulse length
      iCounter++;                  // increase counter
  } else {
    iValid = 1;                        // "enable" Timer after first pulse
  }
  TCNT0 = 0;                        // reset Timer
}

 void setup() {
  Serial.begin(9600);
  TIMSK0 |= (1<<TOIE0);                        // Overflow Interrupt enable
  TCCR0A |= ((1<<CS00) | (1<<CS02));            // Prescaler 128
  TCNT0 = 0;                              // Overflow between 2,2ms & 3,8ms
  EIMSK |= (1<<INT0);                        // INT0 enable
  EICRA |= ((1<<ISC01) | (1<<ISC00));              // external Interrupt on rising
  sei();                              // enable global interrupts

 }
 
 void loop() {
   Serial.println('test');   //just a test - i want to display the channels here later
 }

arduino gives me the following debug information:

Quote
/tmp/build3799302546627044279.tmp/core.a(wiring.c.o): In function `init':

/usr/share/arduino/hardware/arduino/cores/arduino/wiring.c:160: multiple definition of `__vector_16'

o:/tmp/build3799302546627044279.tmp/susi.cpp:26: first defined here

Can somebody help me please? I just cant see any reason why it is not working...

Greets
Damian
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Timer 0 is used for the time calculation used by millis(), etc.  The timer 0 overflow handler is defined in the core.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks - so this means I have to use Timer2 right? Ill give it a try right away.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I changed timer0 to timer1:
Code:
ISR(TIMER1_OVF_vect){...}
and
Code:

 TIMSK1 |= (1<<TOIE0);                        // Overflow Interrupt enable
 TCCR1A |= ((1<<CS00) | (1<<CS02));            // Prescaler 128
 TCNT1 = 0;

With this changes I am able to compile the code, but it seems not to be working.
I guess the problem lies within the prescaler or so because this code is from a tutorial for a "ATMega128 with 14,745600MHz" as said in the tut.
I am using the Arduino Dueminlanove - so this is a ATMega328 right? I tried to get some information from the Atmel Datasheet but was not able to figure it out.

Would be nice if someone has a clue.

Damian
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 216
Posts: 13140
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
TIMSK1 |= (1<<TOIE0);                        // Overflow Interrupt enable
What are the values for the other bits?  Is it possible the other bits in the TIMSK1 are set to the wrong values?

Quote
TCCR1A |= ((1<<CS00) | (1<<CS02));            // Prescaler 128
What are the values for the other bits?  Is it possible the other bits in the TCCR1A are set to the wrong values?
« Last Edit: November 26, 2010, 02:13:06 pm by bcook » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@Coding Badly: I have to admit that I have no clue what the other bits are set to. As I already said, I just copied the code from some tut and modified the timer used. Could you please give me an example how they should be set?
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 216
Posts: 13140
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Does this help...
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1289879390/4#4

Bear in mind that example manipulates Timer 2.
Logged

Pages: [1]   Go Up
Arduino Forum upgrade scheduled for Monday, October 20th, 11am-4pm (CEST). Sorry for the inconvenience!
Jump to: