Interrupt on Atmega 644P

Hello boys & girls.
When i use the code below on a standart Arduino Uno, it works just fine. When i move it to a standalone Atmega 644p or 1284p, it does no longer count the rpm. I have set the hall sensor pin to pin 0. I also tried pin 1, 2, 3 & 4 - no luck.
Its compiled in IDE 0023, as a Sanguino 644p or 1284p (tried both chips).
I have hooked AGnd up to Gnd and AVCC to VCC and AREF to GND through a 100nf cap.
Do you see any errors in the code below or is it on the hardware side i need to look.
Thnk you for your help!!

//code by Crenn from http://thebestcasescenario.com
//project by Charles Gantt from http://themakersworkbench.com

/*To

disable interrupts:
cli();                // disable global interrupts 
and to enable them:  
sei();                // enable interrupts
*/

#include <LiquidCrystal.h>   
LiquidCrystal lcd(26, 27, 28, 29, 30, 31);
int NbTopsFan;  //Varibles used for calculations
int Calc;

                                  //The pin location of the sensor
int hallsensor = 0;
int alarm1 = 13; // alarm output 1 (pin 8)
                        
typedef struct{                  //Defines the structure for multiple fans and their dividers
  char fantype;
  unsigned int fandiv;
}fanspec;

//Definitions of the fans
fanspec fanspace[3]={{0,1},{1,2},{2,8}};

char fan = 1;   //This is the varible used to select the fan and it's divider, set 1 for unipole hall effect sensor 
               //and 2 for bipole hall effect sensor 

void rpm ()      //This is the function that the interupt calls 
{ 
NbTopsFan++; 
} 

              //This is the setup function where the serial port is initialised,
             //and the interrupt is attached
void setup() 
{ 
pinMode(alarm1, OUTPUT);
  lcd.begin(16, 2);
  pinMode(hallsensor, INPUT); 
Serial.begin(9600); 
attachInterrupt(0, rpm, RISING); 

lcd.begin(16, 2);
} 
void loop () 
{
   NbTopsFan = 0; //Set NbTops to 0 ready for calculations
   sei(); //Enables interrupts
   delay (500); //Wait 0,5 second
   cli(); //Disable interrupts
   Calc = ((NbTopsFan * 120)/fanspace[fan].fandiv); //Times NbTopsFan (which is apprioxiamately the fequency the fan is spinning at) by 60 seconds before dividing by the fan's divider
   Serial.print (Calc, DEC); //Prints the number calculated above
   Serial.print (" RPM\r\n"); //Prints " rpm" and a new line
   lcd.setCursor(0,1); //set cursor upper left corne
   lcd.print (Calc, DEC); //Prints the number calculated above
   lcd.print (" RPM   "); //Prints " rpm" and a new line
if (Calc <= 1000) {
  digitalWrite (alarm1, HIGH);
}else{
  digitalWrite (alarm1, LOW);
}}

Are you using the correct pin for your interrupt? On the 644p, interrupt 0 is on digital pin 10. IIRC on the '328, interrupt 0 is on digital pin 2.

Hey!

You are so right. I was using the Sanguino pin out diagram, which stated pin 0 to be int0. The Atmel datasheet states this is pin actually pin 16 (D10). Now it works :slight_smile:

Thanks!