----- Original Message ----- From: "Jens Boos" <webmas...@jb-electronics.de>
To: "neonixie-l" <neonixie-l@googlegroups.com>
Sent: Thursday, October 14, 2010 6:46 PM
Subject: [neonixie-l] Re: Weird MAX1242 ADC behaviour


And the c source:

http://www.jb-electronics.de/tmp/voltmeter_source.c

static int TimeCounter, WertADC, oldADC, Spannung, mean;
// calculate mean
  mean_counter++;
mean += WertADC * (0.3215 + 0.004); // 0.3215 out of calculation, additional term is tweaked
  if (mean_counter >= 50) {
   Spannung = mean / mean_counter;
   mean = 0;
   mean_counter = 0;
  }

WertADC is an integer. Then you multiply by a float constant (0.3215+0.004), which gives an internal float result. This float is then rounded downwards to an integer again (mean).

Perhaps you should declare mean as a float, not an int.
static float mean;

Or something like this:
mean += WertADC;

and
  if (mean_counter >= 10) {
       Spannung = (mean * 0.3215) /  mean_counter) ;

Just to save a bit of time on all those floating point calculations...


Best wishes,
Frank




--
You received this message because you are subscribed to the Google Groups 
"neonixie-l" group.
To post to this group, send an email to neonixi...@googlegroups.com.
To unsubscribe from this group, send email to 
neonixie-l+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/neonixie-l?hl=en-GB.

Reply via email to