integer print not making any sense.

Hi, We are implementing a simple digital moving average filter of the output of the p1_y and p1_x. We are pretty much summing 8 numbers that should be in the range of 0-30 therefore should get an output of around 0-240…however this isn’t the case for us. We are getting an output of something in the 7000s.

Thanks for your help!
Windell

Below is the code:

(at top of user_routines.c)
unsigned int yminus1,yminus2,yminus3,yminus4,yminus5,yminus6,yminus7;
unsigned int tempy;

(outside of any of the functions in custom_routines.c)
extern unsigned int yminus1,yminus2,yminus3,yminus4,yminus5,yminus6,yminus7;
extern unsigned int tempy;

//
/implement a moving average filter to eliminate some of the noise of the p1 ADC/
/
/
tempy=(int)p1_y+yminus1+yminus2+yminus3+yminus4+yminus5+yminus6+yminus7;
yminus7=yminus6;
yminus6=yminus5;
yminus5=yminus4;
yminus4=yminus3;
yminus3=yminus2;
yminus2=yminus1;
yminus1=p1_y;

printf(“tempy %d\r”,tempy);

To print unsigned integers, use %u instead of %d.

Very odd things can occur when printf uses the wrong specifier for the format, the least of which are unexpected values being printed.

–Eric

Thanks esquared! That makes a lot of sense! I’m so used to only %f,%d,%s from writing C programs on Linux boxes that I didnt think of that.