     resetAdChannels(adArr,sizeof(adArr) / sizeof(struct ad));
   readAdChannels(adArr,sizeof(adArr) / sizeof(struct ad));
   cnt++;
-  if (cnt==AD_SAMPLECNT) {
+  if ((cnt % AD_SAMPLECNT)==0) {
     sched.oscillate(13,150, LOW,2);
     calcAdChannels(adArr,sizeof(adArr) / sizeof(struct ad));
     sendM2X(adArr,sizeof(adArr) / sizeof(struct ad));
-    cnt=0;
-  }
-}
-
-
+    resetAdChannels(adArr,sizeof(adArr) / sizeof(struct ad));
+  }
+  if ((cnt % (AD_SAMPLECNT * 3))==0) {
+    calcKw();
+  }
+}
+
+
+void calcKw()
+{
+  static unsigned int prevCnt=0;
+
+  if (prevCnt!=0) {
+    kw=(_kwCounter-prevCnt) / (digvalue * analogvalue);
+  }
+  prevCnt=_kwCounter;
+}
 
 void checkEthernet()
 {

  struct dig2a delta;
};


struct ad adArr[]= {          //prev   dif    min       max         meas    delta
  {0,"boiler",       0,0,     0,0.0, 0,0.5, 174,21.0, 935, 100.0,  0,0.0,  0,0.0},

  setSyncProvider(getNtpTime);
  sched.every(1000,processAD);
  sched.every(200,checkEthernet);
  attachInterrupt(1, elmeter, CHANGE);
}


