Revision 975af07c toolbox/current.c

View differences:

toolbox/current.c
4 4
#include <math.h>
5 5

  
6 6
#define CYCLES_PER_SECOND 60 // wall power
7
#define SAMPLES_PER_CYCLE 10
8
#define N_SAMPLES 20
7
#define SAMPLES_PER_CYCLE 16
8
#define N_SAMPLES 48
9 9

  
10 10
unsigned int samples[N_SAMPLES];
11 11
int sample_idx;
......
93 93
  sei();
94 94

  
95 95
  /* calculate the variance using sum and sum_sq */
96
  return (N_SAMPLES*_sum_sq - _sum*_sum) / (N_SAMPLES*(N_SAMPLES-1));
96
  return (N_SAMPLES*_sum_sq - (unsigned long)_sum*_sum) /
97
    (N_SAMPLES*(N_SAMPLES-1));
97 98
}

Also available in: Unified diff