More intelligent Triac setting.
authorFredrik Tolf <fredrik@dolda2000.com>
Thu, 5 Jul 2007 00:05:42 +0000 (00:05 +0000)
committerFredrik Tolf <fredrik@dolda2000.com>
Thu, 5 Jul 2007 00:05:42 +0000 (00:05 +0000)
kokare.c

index 38662bb..f3c65b6 100644 (file)
--- a/kokare.c
+++ b/kokare.c
@@ -263,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);
@@ -346,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;