![]() |
printf isn't printf-ing. Help!
the wierdest thing is happening. When I do this;
Code:
/*way up at the beginning of the file...*/Code:
BTW, this is all happening in the context of a larger problem that is I can't get the Gyro from last year to send values to the Edubot. When it does print, it says 0,0 no matter what. It also has never printed the initialization message in user_initialization(). What's up with that? |
Re: printf isn't printf-ing. Help!
Quote:
|
Re: printf isn't printf-ing. Help!
just put:
Code:
extern char counter; |
Re: printf isn't printf-ing. Help!
Quote:
Do this instead. Code:
/* all in process_data_from_master_uP*/ |
Re: printf isn't printf-ing. Help!
All those are great suggestions, but I think the problem is deeper than that. I noticed today that the program state light stays yellow when I download. I tried changing around a few things, such as the last function I added. I ditched the if counter>40 thing, and just printfing every time doesn't even work.
Basically, this is the last function I added since it stopped working: Code:
void findcurrentpos(void) /*basically takes input from yaw rate sensor and integrates to find how much the direction has changed*/And this gives me either an overflow error, or the Program State LED on the Edubot blinks red. In the Edubot reference guide a blinking red light means an infinite loop. However, a funny thing happens when I comment out all the code in findcurrentpos(), It works! no blinking red light, no overflow error. I wonder if there is a limit for how large a math operation can be. I know on my calculator, if you multiply two very large values, you can get an overflow error. I also had another problem with a sin approximation giving an overflow error. I just replaced it with a lookup table. If there is such a limit, what is it? |
Re: printf isn't printf-ing. Help!
As others have said, using floating point calculations on the PIC is like playing with fire.
|
Re: printf isn't printf-ing. Help!
Any chance you're running out of program/data space?
That's one of the reasons you'll get the yellow light. Using the .08 value drags in additional s/w to perform floating point processing. What type is "current.theta" and what's a sample maximum deltat value? |
Re: printf isn't printf-ing. Help!
Quote:
Current.theta is an unsigned int, and deltat is incremented every 25ms, so generally like 1 or 2. I'm going to try playing around with the order of operations, see if i can get it to work. What if instead of multipying by .08, I divided by 1/.08? would that still force the pic to use floating point calculations? |
Re: printf isn't printf-ing. Help!
Quote:
e.g., current.theta += (unsigned long) ((gyroin + gyroprev - 1023) * deltat * 8 / 100) + 2000; |
Re: printf isn't printf-ing. Help!
Quote:
for example, what if I had this: Code:
and a second question about that, am I getting an overflow error because the pic does math on an int level, and when an operation goes higher than an int I get an overflow error? Thanks for all your help so far. |
Re: printf isn't printf-ing. Help!
Quote:
just put "extern" variable declarations at the beginning of an individual file. |
Re: printf isn't printf-ing. Help!
Quote:
Back on topic: Code:
unsigned long longvar = 0xFAAABBBB;Code:
shortvar = (unsigned int)(longvar >> 16); |
Re: printf isn't printf-ing. Help!
Quote:
Hope this helps! |
Re: printf isn't printf-ing. Help!
Quote:
Always use a type that will hold your largest possible final value. In this case you could shift right 16 bits. The PIC evaluates an expression based on the largest type variable used in the expression. You can add an explicit type, e.g., (long), to force the PIC to use a long for all calculations. [edit] You can also force the C compiler to use at least (int) for all calculations rather than defaulting to the types of the variables used in the expression. In MPLAB under Project -> Build Options... -> MPLAB C18 tab add the compiler option -Oi+ |
Re: printf isn't printf-ing. Help!
Quote:
|
| All times are GMT -5. The time now is 04:18. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi