1 Sketch crashes IDE

I’m building an optical tachometer that I found on the net, but every time I try to compile the sketch, windows throws me an error. I’ve compiled several other sketches without issue before and after. I’ve also ran two cleaning programs (that I use regularly anyway) just to make sure it wasn’t a temp folder issue.

The original sketch was a pde file and I’m running IDE 1.6.5. on xp sp3 and I’m programming a nano 328.

It’s a windows error that closes down ID.exe. I’ve attached the sketch and the only logfile I could find.

Does anyone know whats wrong, here?

/*
 * Optical Tachometer
 *
 * Uses an IR LED and IR phototransistor to implement an optical tachometer.
 * The IR LED is connected to pin 13 and ran continually. A status LED is connected
 * to pin 12. Pin 2 (interrupt 0) is connected across the IR detector.
 *
 * 
 */

int ledPin = 13;                // IR LED connected to digital pin 13
int statusPin = 12;             // LED connected to digital pin 12

volatile byte rpmcount;
volatile int status;

unsigned int rpm;

unsigned long timeold;

 void rpm_fun()
 {
   //Each rotation, this interrupt function is run twice, so take that into consideration for 
   //calculating RPM
   //Update count
      rpmcount++;
      
   //Toggle status LED   
   if (status == LOW) {
     status = HIGH;
   } else {
     status = LOW;
   }
   digitalWrite(statusPin, status);
 }

void setup()
 {
   Serial.begin(9600);
   //Interrupt 0 is digital pin 2, so that is where the IR detector is connected
   //Triggers on FALLING (change from HIGH to LOW)
   attachInterrupt(0, rpm_fun, FALLING);
   
   //Turn on IR LED
   pinMode(ledPin, OUTPUT); 
   digitalWrite(ledPin, HIGH);
   
   //Use statusPin to flash along with interrupts
   pinMode(statusPin, OUTPUT);

   rpmcount = 0;
   rpm = 0;
   timeold = 0;
   status = LOW;
 }

 void loop()
 {
   //Update RPM every second
   delay(1000);
   //Don't process interrupts during calculations
   detachInterrupt(0);
   //Note that this would be 60*1000/(millis() - timeold)*rpmcount if the interrupt
   //happened once per revolution instead of twice. Other multiples could be used
   //for multi-bladed propellers or fans
   rpm = 30*1000/(millis() - timeold)*rpmcount;
   timeold = millis();
   rpmcount = 0;
   
   //Write it out to serial port
   Serial.println(rpm,DEC);
   
   //Restart the interrupt processing
   attachInterrupt(0, rpm_fun, FALLING);

  }

bc26_appcompat.txt (6.96 KB)

rpm = 30*1000/(millis() - timeold)*rpmcount; timeold = millis(); rpmcount = 0;

so....

rpm = 30*1000/(millis() - 0;

or is that

rpm = 0

or

rpm = 30*1000/ 0;

multiplying by zero can confuse me.

Sketch as written compiles ok in 1.0.6 in Win7 Pro for an Uno.

Thanks crossroads. Any idea why you think it might compile fin in 1.0.6/win7 but not 1.6.5/xp?

It's only this code in particular that throws an error on my computer.

Dave-in-Nj, it doesn't devide by zero; iit increments rpmcount and after 1000ms it runs the calculation, then resets timeold to the current time and rpmcount to 0, waits 1000ms, and does it again, etc.

I have not tried versions after 1.0.6, so I have no guesses to hazard.

Your code compiles fine for me with 1.6.4 and Windows 7, and 1.6.5 and Windows 10.

Hi, Fine on 1.6.5 on Win 7.

Tom... :)

Thanks, y'all!

I'm due for a system reinstall anyway. I'll report back after I reload my machine, but that could be a month or so before I do.

Try making a new sketch, and then just copy paste the text into the new sketch. Save it, and see if it loads. The file itself just might have a corrupt part or something.