Revision e8960789

View differences:

toolbox/current.c
33 33
   * MUX = 8, PB3(ADC8)
34 34
   */
35 35
  ADMUX = _BV(MUX3);
36
  DIDR1 |= _BV(ADC8D);
37 36

  
38 37
  /*
39 38
   * ADLAR = 0, right adjust result
......
69 68
  /* keep a running total of samples and samples squared */
70 69
  sum += new;
71 70
  sum -= old;
72
  sum_sq += new*new;
73
  sum_sq -= old*old;
71
  sum_sq += (unsigned long)new*new;
72
  sum_sq -= (unsigned long)old*old;
74 73
}
75 74

  
76
/*unsigned char isqrt(unsigned int x) {
77
  unsigned int sqrt, mulmask;
78
  sqrt = 0;
79
  mulmask = 0x80;
80
  if (x > 0) {
81
    while (mulmask) {
82
      sqrt |= mulmask;
83
      if (sqrt * sqrt > x)
84
        sqrt &= ~mulmask;
85
      mulmask >>= 1;
86
    }
87
  }
88
  return sqrt;
89
}*/
90

  
91 75
unsigned int current_read() {
92 76
  unsigned int _sum;
93 77
  unsigned long _sum_sq;

Also available in: Unified diff