Thats the min time between reads, hence my 250mS, but you have to send it 16 clock pulses at min 250nS/clock to read the data in...
Looked at the max6675 library and a read takes ~320uS at 20uS/bit, but that could be sped up if need be.
Basically this should work much better. The max6675 library doesn't disable interrupts but thats not a problem if read done inside the ISR as nothing can interrupt it there.
So an even better ISR is:
The ISR is the only place the MAX6675 is read.
The main loop is now:
Looked at the max6675 library and a read takes ~320uS at 20uS/bit, but that could be sped up if need be.
Basically this should work much better. The max6675 library doesn't disable interrupts but thats not a problem if read done inside the ISR as nothing can interrupt it there.
So an even better ISR is:
Code:
int tempError = false; // global error flag
void zero() {
counter++;
if (counter == 24) {
digitalWrite(triac, LOW);
}
else if (counter >= 25) {
counter = 0;
pottemperature = analogRead(potentiometer);
pottemperature = map(pottemperature, 0, 1023, 150, 400);
realTemperature = thermocouple.readCelsius();
temperature = 0.779828 * realTemperature - 10.3427;
if (tempError || isnan(temperature) || temperature >= 432) { // on error kill power & set global error flag
digitalWrite(relay, LOW); // turn off power to iron
tempError = true; //set error flag. can only be unset outside ISR. Once set no further action taken till unset in main loop.
}
else { //reading valid
if (temperature <= pottemperature) { // not sure about = here,
digitalWrite(triac, HIGH);
}
}//if(isnan...
}//if(counter == 25...
} //zero()
The main loop is now:
Code:
void loop() {
if (tempError) {
// do error stuff, reset tempError and turn on relay as appropriate
}
else {
updateDisplay();
}
delay(200); delay between screen updates
} //loop
Last edited: