X-Git-Url: http://dolda2000.com/gitweb/?p=kokare.git;a=blobdiff_plain;f=kokare.c;h=f3c65b6fb11042187fc62fb296ff30020ad5e706;hp=64c3754f6225f06593899ab0c58bb8a17fe8f818;hb=1eabd7a93fe49a288464ebd686c3853cb838cfa9;hpb=174dfeb50a8d3408adf44ecb882d88ab9884dbe0 diff --git a/kokare.c b/kokare.c index 64c3754..f3c65b6 100644 --- a/kokare.c +++ b/kokare.c @@ -149,7 +149,16 @@ void disphex(unsigned char num) unsigned long getticks(void) { - return(TCNT1 + (((unsigned long)oticks) << 16)); + uint16_t v; + unsigned long r; + + cli(); + v = TCNT1; + r = v + (((unsigned long)oticks) << 16); + if((TIFR1 & 0x01) && !(v & 0x8000)) + r += 0x10000; + sei(); + return(r); } void ledcycle(void) @@ -254,12 +263,13 @@ void convcycle(void) int main(void) { - int state, cur, run; + int state, cur, run, rstate, delta; unsigned long utime; state = 0; cur = 100; run = 0; + rstate = 0; init(); sei(); display(0); @@ -337,22 +347,26 @@ int main(void) * 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; + delta = cur - (tempk - 273); + if(rstate == 0) { + if(delta > 0) { + tron = 1; + if(delta > 8) { + /* For some reason, the Triac currently doesn't + * trigger on one of the AC half-cycles below 0.7 + * ms. */ + trdelay = 7; + } else { + trdelay = 79 - (delta * 9); + } } else { - trdelay = 70; + tron = 0; + rstate = 1; } - } else { + } else if(rstate == 1) { tron = 0; + if(delta >= 2) + rstate = 0; } } else { tron = 0;