Go Down

Topic: Arduino-0016 Bug with external interrupts (Read 697 times) previous topic - next topic

darkirby

When using any external interrupts with the arduino 0016 software for the pro mini 8mhz you get an error when you compile.

mellis

Hmm, I didn't have any problems with the sample program I just tried.  Can you post your code and the error you get?  Which boards give you the error and which don't?

darkirby

#2
Jun 08, 2009, 07:54 am Last Edit: Jun 08, 2009, 07:59 am by darkirby Reason: 1
mellis,

Thanks for the quick reply.  The code I am having trouble with is a three tab file.  This code does fully compile with zero errors in the Arduino-0015 environment for an Arduino Pro or Pro Mini (3.3V, *MHz) w/ ATMega168.  Hopefully this will help.

Tab 1 Code:
Quote

//Variable Initialization, Setup, and Main loop

//Magnetometer and Period Variables
volatile int time=0;
volatile int period=0;
volatile int new_period=0;
volatile int last_period=0;
volatile byte count=0;
volatile int first_half=0;
volatile int second_half=0;

//Timer 2 ISR variables
int mode=1;
int isr_count=0;

void setup()
{
 pinMode(3,INPUT);   //mag data
 pinMode(4,OUTPUT);  //mag reset
 pinMode(8,OUTPUT);  //flap
 pinMode(9,OUTPUT);  //throttle
 pinMode(13,OUTPUT); //led
 
 degauss();
 degauss();
 
 Serial.begin(19200);
 
 TCCR2A=0x02;
 TCCR2B=0x07;
 TCNT2=0x00;
 OCR2A=0x9C;
 GTCCR=0x02;
 TIMSK2=0x02;
 
 attachInterrupt(1,getRPM,RISING);

}


void loop()
{
 if (count==30)
 {
   count=0;
   Serial.println(period);
   degauss();
 }  
}


Tab 2 Code:
Quote

//replaces get_RPM function

/*boolean blink=false;
void getRPM()
{
 if (millis()>80)
 {
 blink=!blink;
 if (blink) PORTB |= 1<<PB5;
 else PORTB &= ~(1<<PB5);      
 }
}*/

//set mode of timer2 isr in order to sync up flapping
void getRPM()
{
 time=millis();
 if (time>80)
 {
   mode=4;
   count++;
   new_period=time;
   last_period=period;
   period=((period<<2)-period+new_period)>>2;
   first_half=period>>1;
   second_half=period-first_half;
   timer_reset();
 }
}

void degauss()
{
     //assumes that the magreset pin is connected to 4
     PORTD|=1<<PD4;
     delayMicroseconds(2);
     PORTD&=~(1<<PD4);
}


extern volatile unsigned long timer0_clock_cycles;
extern volatile unsigned long timer0_millis;
void timer_reset()
{
     unsigned char oldSREG=SREG;
     cli();
     timer0_clock_cycles=0;
     timer0_millis=0;
     SREG=oldSREG;
}









//original getrpm
/*void getRPM()
{
     time=millis();
     if (time>80)
     {
           if (time>300) time=300;
               count++;
           new_period=time;
           last_period=period;
           period=((period<<2)-period+new_period)>>2;
           timer_reset();
     }
}*/



Tab 3 Code:
Quote

//ISR routine for translation
ISR(TIMER2_COMPA_vect)
{
 switch(mode)
 {
   
   case 1: //wait for half period
       isr_count++;
       if (isr_count==first_half)
       {
         mode=2;
       }
       else
       {
         TCCR2B=0x04;
         OCR2A=125;
         GTCCR=0x02;
         break;
       }
   case 2: //turn led off
       PORTB &= ~(1<<PB5);
       TCCR2B=0x04;
       OCR2A=125;
       GTCCR=0x02;
       mode=3;
       isr_count=0;
       break;
   case 3: //
       isr_count++;
       if (isr_count==second_half)
       {
         mode=4;
       }
       else
       {
         TCCR2B=0x04;
         OCR2A=125;
         GTCCR=0x02;
         break;
       }
   case 4: //turn led on
       PORTB |= 1<<PB5;
       TCCR2B=0x04;
       OCR2A=125;
       GTCCR=0x02;
       mode=1;
       isr_count=0;
       break;
   default:
       break;
 }
}



That is the end of the code and this is the list of errors that I am getting.

o: In function `timer_reset':
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build39811.tmp/Temporary_1953_2035.cpp:111: undefined reference to `timer0_clock_cycles'


C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build39811.tmp/Temporary_1953_2035.cpp:111: undefined reference to `timer0_clock_cycles'


C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build39811.tmp/Temporary_1953_2035.cpp:111: undefined reference to `timer0_clock_cycles'


C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build39811.tmp/Temporary_1953_2035.cpp:111: undefined reference to `timer0_clock_cycles'


Couldn't determine program size: C:\Documents and Settings\Administrator\Desktop\IARC\software and drivers\arduino-0016\arduino-0016\hardware/tools/avr/bin/avr-size: 'C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build39811.tmp\Translation_Debugging.hex': No such file

mellis

timer0_clock_cycles is (was) an internal / unsupported variable.  You'll have to take a look inside the wiring.c to find a equivalent technique for Arduino 0016.

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