Project

General

Profile

Revision 975af07c

ID975af07c01a0e83574762dca55eb6ca8e2fca3b6
Parent f4df665c
Child db11713d

Added by Thomas Mullins about 11 years ago

Fixed overflow in current calculation

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