Go Down

Topic: Problem with ISR(TIMER0_OVF_vect) (Read 4583 times) previous topic - next topic

.grey

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

Here is my code:
Code: [Select]

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

mellis

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

.grey

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

.grey

I changed timer0 to timer1:
Code: [Select]

ISR(TIMER1_OVF_vect){...}

and
Code: [Select]

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

Coding Badly

#4
Nov 26, 2010, 08:12 pm Last Edit: Nov 26, 2010, 08:13 pm by bcook Reason: 1
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?

.grey

@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?

Coding Badly


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

Bear in mind that example manipulates Timer 2.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy