> it seem like 10 times of avg reading loop of each analog input, > taking up 30% total flash memory in 4Kword That seems an awful lot of memory for what seems a simple function > is there a way for optimize adc avg reading method ? If by 'average' you mean arithmetic mean, then add the 10 samples to a 16-bit accumulator and divide by 10. Or to simplify, take 8 and right-shift 3 times, or take 16 and right-shift 4 times. There are also 'moving averages', where you'd re-calculate the mean after discarding sample1 from the queue/array and adding the latest Finding a mode might take a little more work, but you can narrow the range to limit the number of each number and its frequency Similarly, other methods exist when looking for other "expected" values http://en.wikipedia.org/wiki/Arithmetic_mean -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist