We have been fortunate (or is it rather unfortunate?) there have been already some Freezes since this latest change (analogRead -> digitalFastRead):
The new test started at 10:36 and the first 3 Freezes within one minute occurred at 11:05 (2nd 17 loops later, 3rd 19 loops after the second). Those Freezes were no longer between ZeitStopB & ZeitStopC (both show identical ms values) . However, the first Freeze still happened in the same sub, but not longer between ZeitStart and ZeitStopD, as all show identical millisecond reading. The Freeze happened between ZeitStopD and the end of the routine (ZeitStop -ZeitStart= 1767018546).
This simple subroutine is this (showChange is set true, but no print out recorded at time of Freezes):
Code:
void poll_Switches_and_Hell(boolean showChange)
{
unsigned long t1=micros();
KNXCounterInInput = KNXCounter;
ZeitStart=millis();
i_SwitchUp+=digitalRead(SwitchUp); ZeitStopA=millis();
i_SwitchDw+=digitalRead(SwitchDw); ZeitStopB=millis();
i_Hell+=digitalReadFast(HellSensor)*1023; //digitalReadFast(HellSensor);
ZeitStopC=millis();
if(counterSwitch==max_counterSwitch-1)
{
fHell = float(i_Hell)/float(max_counterSwitch);
if(i_SwitchUp==0) iSwitchUp=1;
else if(i_SwitchUp==8) iSwitchUp=0;
if(i_SwitchDw==0) iSwitchDw=1;
else if(i_SwitchDw==8) iSwitchDw=0;
iHell = int(fHell);
counterSwitch=0; i_SwitchUp=0; i_SwitchDw=0; i_Hell=0;
}
else
{
counterSwitch++;
}
ZeitStopD=millis();
if(showChange)
{
boolean Change=false;
if(old_iSwitchUp!=iSwitchUp)
{
Serial.print("new SwitchUp: "); Serial.print(iSwitchUp);
old_iSwitchUp=iSwitchUp;
Change=true;
}
if(old_iSwitchDw!=iSwitchDw)
{
Serial.print("\tnew SwitchDw: "); Serial.print(iSwitchDw);
old_iSwitchDw=iSwitchDw;
Change=true;
}
if( abs(old_iHell-iHell)>15 )
{
Serial.print("\tnew iHell: "); Serial.print(iHell);
old_iHell=iHell;
Change=true;
}
if(Change) Serial.println();
}
if(micros()-t1>100) {Serial.print("dt_us>100(Inputs):"); Serial.println(micros()-t1);}
ZeitStop=micros();
}
The second and third Freeze happened inside the routine, which checks if a client is available. Whilst this is a lengthy routine, it writes out, if a client was detected - which wasn't the case. Therefore the "active" part in this instance was merely this:
Code:
void PCContact()
{
if(PC_Contact_Established) {Serial.println("already inside PCContact"); return;}
//Arbeitsparameter
char ReadText[100];
ReadText[0]=0;
byte Count=0;
byte Action=99;
boolean ClientWasDetected=false;
unsigned long t1=micros(); //Dauer der Routine
Ethernet.setRetransmissionCount(2); //<-------------------------------------------------------------------------------------------------------------------
Ethernet.setRetransmissionTimeout(50); //<-------------------------------------------------------------------------------------------------------------------
EthernetClient client = server.available();
client.setConnectionTimeout(100);
//Wir prüfen, ob sich jemand mit uns in Verbindung gesetzt hat. Ist jemand mit Arduino verbunden?
if (client)
{
unsigned long t2=micros(); Serial.print("PCC client t2-t1:"); Serial.print(t2-t1);
CODE REMOVED as no client detected
} //end if(client)
if(ClientWasDetected) // && micros()-t1 > 3000)
{
Serial.print("\tt(PC_us)): "); Serial.println(micros()-t1);
}
PC_Contact_Established=false;
}
Now, interestingly, at 11:18 the very same Freezes sequence happened, only difference the 3rd Freeze happened 18 loops after the 2nd [before 19], whilst the 2nd happened equally 17 loops after the first.
Does this tell us anything?
I will next remove the SDI OLED from the sketch, although this is at present only written to once per minute. Are they any other suggestions?