int main(void)
{
- int state, cur;
+ int state, cur, run;
unsigned long utime;
state = 0;
- cur = 99;
+ cur = 100;
+ run = 0;
init();
sei();
display(0);
dsp[0] = dsp[1] = SEGG;
}
}
- if(pval != 0) {
+ if(pval != 0)
state = 1;
- utime = mnow;
- }
if(sstate == 2) {
sstate = 0;
- if(stime > 10) {
+ if(stime > 10)
state = 2;
- } else {
- tron = !tron;
- }
+ else
+ run = !run;
}
+ if(run)
+ dsp[1] |= SEGP;
+ else
+ dsp[1] &= ~SEGP;
} else if(state == 1) {
- /* Triac control */
+ /* Temp setting */
if(pval != 0) {
cur += pval;
pval = 0;
if(cur < 0)
cur = 0;
- if(cur > 99)
- cur = 99;
- display(cur);
- trdelay = 99 - cur;
+ if(cur > 100)
+ cur = 100;
+ if(cur < 100)
+ display(cur);
+ else
+ dsp[0] = dsp[1] = SEGG;
utime = mnow;
}
- if(mnow - utime > 1000000) {
+ if(mnow - utime > 1000000)
state = 0;
- }
if(sstate == 2) {
- tron = !tron;
+ run = !run;
sstate = 0;
}
} else if(state == 2) {
+ /* Display raw temp time reading */
if(ttimea < 20000) {
display((ttimea / 100) % 100);
dsp[0] |= SEGP;
sstate = 0;
}
}
+ /*
+ * Set Triac to match temperature
+ */
+ if(run) {
+ if(tempk - 273 < cur) {
+ tron = 1;
+ if(cur - (tempk - 273) > 5) {
+ /* For some reason, the Triac currently doesn't
+ * trigger on one of the AC half-cycles below 0.7
+ * ms. */
+ trdelay = 7;
+ } else if(cur - (tempk - 273) >= 3) {
+ trdelay = 20;
+ } else if(cur - (tempk - 273) >= 2) {
+ trdelay = 40;
+ } else {
+ trdelay = 70;
+ }
+ } else {
+ tron = 0;
+ }
+ } else {
+ tron = 0;
+ }
#endif
/*
dsp[0] = bindisp((ttimea & 0xff00) >> 8);