Sketch works with IDE 1.6.x, doesn't with IDE 1.8.5

I use timer1 to multiplex a 4 digit, led display, read switches on the segment bus and to increment a counter to keep track of time.

I also use Delay() and Tone().

I set up the timer1 in the sketch.

The counter in the interrupt routine is used to time how long a switch is pushed closed.

When I compile the Sketch with IDE 1.6.5 everything works as it should.
When I compile the Sketch with IDE 1.8.5 (which it does with no errors), when I push a switch, the program locks up.

Anyone know why there would be a difference between the two versions of the IDE when compiling the timed switch routine? I'm starting to believe it assigns the delay function to a different timer in 1.8 then it did in 1.6. I guess I'll just have to try different timers for my display until I find the one which is free again.

This was so much easier when I wrote directly in Assembly and knew exactly what was going on!

ISR (TIMER1_COMPA_vect) {TIMER1_SERVICE_ROUTINE();}

noInterrupts();

       TCCR1A = 0;
       TCCR1B = 0;
       TCNT1 = 0;

       OCR1A = 238;
       TCCR1B = 0x0b; 
       TIMSK1 |= (1 << OCIE1A);

interrupts();  


void TIMER1_SERVICE_ROUTINE() 

{  

       ++tcount; 
       ++ digit_counter;
   if (digit_counter == 6 ) {(digit_counter = 1);}
      switch(digit_counter) 
 -
 -//write four digits
 -
 -
 
case 5:  //this reads the switches which are on the display segment bus (and isolated with diodes)

      digitalWrite(SLED4, LOW); 
  
      DDRD = 0x00;
      PORTD= 0Xff; 

     digitalWrite(8, LOW);
     
for (int i = 0; i < 10; i++) {sw_inputs = PIND;} //read the switches 10 times to debounce 

     digitalWrite(8, HIGH); 

break;  

}

void timebutton()

 {
        duration = 0;  //clear button duration counter
        time0 = tcount; //set base time to current counter value

do {time1 = tcount; duration = time1- time0; //calculate how long the button has been pushed

      if (duration > 1000) {digit4 = LED_n; digit3 = 0xff; digit2 = 0xff; digit1 = 0xff;} //1 second push message

      if (duration > 2000) {digit4 = LED_C; digit3 = LED_N_0; digit2 = LED_d; digit1 = LED_E;} 

delay(1); //for some reason a delay call has to be done here or it locks up. 

       }

while (bitRead(sw_inputs,R_sw) == 0); // wait until the bit goes high.

      duration = time1- time0; 

    if (duration >2000){int_cw_mode(); duration = 0;} 
    if (duration >1000){Memory(); duration = 0;}
    if (duration >50)  {RIT(); duration = 0;}
}

Here's the reverent code snippets:

Here is a snippet of an answer, then. You need to ...,

Always post ALL the code, using code tags.

Thanks for all the great help.

I tried using timer0 instead of timer1 to the same effect. Looks like timer2 is dedicated to the tone() routine.

I have come to the conclusion that there is nothing wrong with my code and it's the IDE version 1.8.5 which shreds the timer routines. I have another sketch for a board using similar timed switches / multiplexed display and 1.8.5 makes the timers in that sketch go nuts too. Looks like I need to stick with version 1.6.5 for anything to work right.

You can have several versions of the IDE on the same PC.

Unfortunately the Arduino folks are not good at backward compatibility.

...R

Okay, I found out what the problem was.

I failed to declare all the variables used in the interrupt routine as "volatile". Apparently IDE 1.6.5 didn't care but IDE 1.8.5 did and therefore treated the variables differently.

One of those little nit picking details which is easy to overlook - and hard to find the answer to.