I have a motor, controlled via an rc esc using the servo library, that spins a wheel. The wheel has a hall effect sensor on it, that triggers an interrupt on arduino mega pin 18 (interrupt 5). The two programs, one to spin the wheel, and the example for rpm reading on the arduino playground, work when used alone. But when I put them together, the interrupt doesn't trigger. Here's my code (ignore the lcd stuff):
#include <Servo.h>
#include <UTFT.h>
extern uint8_t BigFont[];
const int throttlePin = A11;
Servo esc;
const int escPWRSwitch=16;
const int escPWR=A13;
volatile byte revolutions;
unsigned int rpm;
unsigned long timeold;
float voltage;
const int voltagePin=A10;
float current;
const int currentPin=A9;
UTFT myGLCD(ITDB32S,38,39,40,41);
void setup()
{
attachInterrupt(18, rpm_count, FALLING);
revolutions = 0;
rpm = 0;
timeold = 0;
esc.attach(45);
pinMode(escPWR, OUTPUT);
digitalWrite(escPWR, LOW);
myGLCD.InitLCD(PORTRAIT);
myGLCD.setFont(BigFont);
}
void loop()
{
/////////
current = ((analogRead(currentPin)));
/////////
voltage = (analogRead(voltagePin)) * (0.02441) ;
/////////////////
if (revolutions >= 10) {
//Update RPM every 10 counts, increase this for better RPM resolution,
//decrease for faster update
rpm = 60*1000/(millis() - timeold)*revolutions;
timeold = millis();
revolutions = 0;
}
int throttle = analogRead(throttlePin);
throttle = map(throttle, 0, 1023, 0, 179);
esc.write(throttle);
//////////////
myGLCD.clrScr();
myGLCD.fillScr(255, 0, 0);
myGLCD.setColor(255, 255, 255);
myGLCD.setBackColor(255, 0, 0);
myGLCD.printNumF(voltage, 3, CENTER, 10);
myGLCD.printNumI(rpm, CENTER, 140);
myGLCD.printNumF(current, 3, CENTER, 280);
delay(50);
}
void rpm_count()
{
revolutions++;
//Each rotation, this interrupt function is run once
}
If you guys could give me any reasons why the interrupt may not be triggering, that would be great. rpm stays at 0 and never