Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   integer print not making any sense. (http://www.chiefdelphi.com/forums/showthread.php?t=64103)

windell747 14-02-2008 19:53

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:
Quote:

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

(outside of any of the functions in custom_routines.c)
extern unsigned int yminus1,yminus2,yminus3,yminus4,yminus5,yminus6,ym inus7;
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+ym inus5+yminus6+yminus7;
yminus7=yminus6;
yminus6=yminus5;
yminus5=yminus4;
yminus4=yminus3;
yminus3=yminus2;
yminus2=yminus1;
yminus1=p1_y;

printf("tempy %d\r",tempy);

esquared 14-02-2008 23:21

Re: integer print not making any sense.
 
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

windell747 14-02-2008 23:32

Re: integer print not making any sense.
 
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.


All times are GMT -5. The time now is 00:54.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi