X-Git-Url: http://dolda2000.com/gitweb/?p=kokare.git;a=blobdiff_plain;f=kokare.c;h=f3c65b6fb11042187fc62fb296ff30020ad5e706;hp=b2c523715739dc16c79a17e6a0317b484842169e;hb=1eabd7a93fe49a288464ebd686c3853cb838cfa9;hpb=882c9ed28852a4d774f40e9c7a71dff82105a074 diff --git a/kokare.c b/kokare.c index b2c5237..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,11 +263,13 @@ void convcycle(void) int main(void) { - int state, cur; + int state, cur, run, rstate, delta; unsigned long utime; state = 0; - cur = 99; + cur = 100; + run = 0; + rstate = 0; init(); sei(); display(0); @@ -283,39 +294,42 @@ int main(void) 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; @@ -329,6 +343,34 @@ int main(void) sstate = 0; } } + /* + * Set Triac to match temperature + */ + if(run) { + 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 { + tron = 0; + rstate = 1; + } + } else if(rstate == 1) { + tron = 0; + if(delta >= 2) + rstate = 0; + } + } else { + tron = 0; + } #endif /* dsp[0] = bindisp((ttimea & 0xff00) >> 8);