Pages: [1]   Go Down
Author Topic: Arduino-0016 Bug with external interrupts  (Read 582 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
mmmm..... Monocopters
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
mmmm..... Monocopters
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: June 08, 2009, 12:59:01 am by darkirby » Logged

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

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.
Logged

Pages: [1]   Go Up
Jump to: