Clockdisplay not updated when I use my whole program. [SOLVED]

For a clock program (display and hammer strike) I use a main loop (with also other stuff) with under mentioned relevant routines.
The bell strike routine consist of two nested parts: the number of pings will be related to the hour/halfhour; the inner loop will give a pulse of 0,5 sec, and a wait period of 1,5 sec.

//Update display every second only row2 with date and time 
if (blnShowDateTime){
     Get_RTCtime();
     strLine2 = strDate + "  " + strTime;
     lcd.setCursor(0,1); lcd.print(strLine2);
     blnShowDateTime = false;
     }
 //=========================================================================================        
 //Activates the strike hammer every 30 minutes
 //if (blnSoundflag and (minute==0 or minute==30) and second==0){    //condition to strike the hammer               
 blnBellCycle = true; //Force a start of the bell
        
 //condition to strike the hammer               
      if (blnBellCycle = true){
            //Calculate the number of Pings
            if (hour==0){hour=24;}   //Midnight is presented as 0:00, but the bell has to ring 12 times
            if (hour >=1 and hour<=12) {numberPings = hour ;} else {numberPings = hour -12;}  //Fix number of beats for hours                         
            if (minute ==30){numberPings=1;}          //One beat for the half hours
                
            numberPings =12;  //Temporaly
            //Serial.println (numberPings); 
                      
            //Striking the hammer a number of pings  
            int i=0;
//          while(i <= numberPings){
//                blnBellStrike = true;                         //Enables counting cnt1 from Timer 1 (20 Hz)
//                //Serial.println (blnBellStrike);
//                switch (cnt1){
//                    case 1:
//                        Serial.println (String("Slag ") + i);
//                        digitalWrite(Bellpin, LOW);             //Signal to hammer, takes 500 ms
//                        break;
//                    case 10:
//                        digitalWrite(Bellpin, HIGH);            //Wait 1500 ms for the next strike 
//                        break;   
//                    case 40:
//                        blnBellStrike = false;              //disable counting cnt1 from Timer 1 (20 Hz)
//                        cnt1 =0;                            //reset counter
//                        i++;
//                    }   //End switch     
//
//               }    //End while
            blnBellCycle = false;
            }  //End if blnBellCycle

They make use of Timer0 (20 Hz) for the hammer strike and Timer1 (1 Hz) for updating display.

//===============================================================================================================
//Interrupt every 50 ms (20 Hz) with Timer0
ISR(TIMER0_COMPA_vect){
  if (blnBellStrike){cnt1++;}                     //Increment 50 ms counter
   }    //End interrupt service request

//===============================================================================================================
//Interrupt every 1 s (1 Hz) with Timer1
ISR(TIMER1_COMPA_vect){
  blnShowDateTime= true;
  Serial.println ("Secondepuls komt binnen");
   }    //End interrupt service request

PROBLEM:
With the commented lines the time display is working fine.
If i use my whole program, ISR(TIMER1_COMPA_vect) works (the second pulse comes through), but the LCD is not updated (it stocks).
The question is WHY?

I did experiences with delays en other loop-functions but they keep the micro TOO busy, the program crashes.

I suggest that you post your complete program.

This is not good in an ISR and may not function as you expect:
Serial.println ("Secondepuls komt binnen") ;

Timer 0 is used for millis(), delay() etc. Your timing intervals are relatively long (in MCU terms) so sou should see whether millis() etc. would be better in this case.

I solved my problem: my earlier program was continously busy with the loop “while(i <= numberPings)”.

Now I use of a 20 Hz timer and count the pulses (cnt1). Only if the counts within the loop changes, 
I make an action; so there rests time to do other actions like presenting the actual time.

For people who are interested to make a clock with strikes, herewith my code.
//Activates the strike cycle every 30 minutes
if (blnSoundflag and (minute==0 or minute==30) and second==0){blnBellCycle = true;  cnt1=0; int i=0;}     //condition to strike the hammer               
         
        //condition to strike the hammer               
        if (blnBellCycle = true){
            //Calculate the number of Pings
            if (hour==0){hour=24;}   //Midnight is presented as 0:00, but the bell has to ring 12 times
            if (hour >=1 and hour<=12) {numberPings = hour ;} else {numberPings = hour -12;}  //Fix number of beats for hours                         
            if (minute ==30){numberPings=1;}          //One beat for the half hours
                                 
           //Striking the hammer a number of pings  
           if (i <= numberPings){                         
                if (cnt1!=cnt1_previous){                     
                     if (cnt1 >= 1 and cnt1<=10){
                         //if (cnt1==1){Serial.println (String("Slag ") + i);}
                         digitalWrite(Bellpin, LOW);}             //Signal to hammer, takes 500 ms
                         else
                         {digitalWrite(Bellpin, HIGH);}            //Wait 1500 ms for the next strike 
                     if (cnt1 >=40){cnt1 =0; i++;}                      //reset counter
                     cnt1_previous = cnt1;              
                     }   //End if cntt1!=
                }  
                else
                {blnBellCycle = false;}  //End if

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.