|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
printf isn't printf-ing. Help!
the wierdest thing is happening. When I do this;
Code:
/*way up at the beginning of the file...*/
char counter = 0;
/*in process_data_from_master_uP*/
gyroin = get_analog_value(rc_ana_in_01);
if (counter > 40) {
printf("%d, %d \n",gyroin,get_analog_value(rc_ana_in_01));
counter=0;
}
counter++;
Code:
printf("%d, %d \n",gyroin,get_analog_value(rc_ana_in_01));
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? Last edited by Meandmyself : 12-02-2004 at 22:08. |
|
#2
|
||||
|
||||
|
Re: printf isn't printf-ing. Help!
Quote:
|
|
#3
|
|||||
|
|||||
|
Re: printf isn't printf-ing. Help!
just put:
Code:
extern char counter; |
|
#4
|
||||
|
||||
|
Re: printf isn't printf-ing. Help!
Quote:
just put "extern" variable declarations at the beginning of an individual file. |
|
#5
|
|||||
|
|||||
|
Re: printf isn't printf-ing. Help!
Quote:
Back on topic: Code:
unsigned long longvar = 0xFAAABBBB; unsigned int shortvar = 0; shortvar = longvar; Code:
shortvar = (unsigned int)(longvar >> 16); |
|
#6
|
|||||
|
|||||
|
Re: printf isn't printf-ing. Help!
Quote:
Do this instead. Code:
/* all in process_data_from_master_uP*/
static char counter = 0;
gyroin = get_analog_value(rc_ana_in_01);
if (counter > 40) {
printf("%d, %d \n", (int)gyroin, (int)get_analog_value(rc_ana_in_01));
counter=0;
}
counter++;
Last edited by Mark McLeod : 13-02-2004 at 09:39. |
|
#7
|
||||
|
||||
|
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*/
{
current.theta += ((gyroin + gyroprev - 1023) * CGYRO * deltat) + 2000; /* finds our current direction cgyro converts to degrees/100, find average and multiply by time, dt converted to seconds by dt/1000*/
deltat = 0; /*modified in user_routines_fast with the internal timer*/
// if (current.theta < 2000) {current.theta += 36000;}
// current.theta -= 2000;
// if (current.theta > 360) {current.theta -= 36000;}
// gyroprev = gyroin;
}/*end findcurrentpos()*/
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? |
|
#8
|
||||||
|
||||||
|
Re: printf isn't printf-ing. Help!
As others have said, using floating point calculations on the PIC is like playing with fire.
|
|
#9
|
|||||
|
|||||
|
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? |
|
#10
|
||||
|
||||
|
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? Last edited by Meandmyself : 14-02-2004 at 13:40. |
|
#11
|
|||||
|
|||||
|
Re: printf isn't printf-ing. Help!
Quote:
e.g., current.theta += (unsigned long) ((gyroin + gyroprev - 1023) * deltat * 8 / 100) + 2000; |
|
#12
|
||||
|
||||
|
Re: printf isn't printf-ing. Help!
Quote:
for example, what if I had this: Code:
unsigned long longvar = 0xFAAABBBB; unsigned int shortvar = 0; shortvar = longvar; 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. |
|
#13
|
|||||
|
|||||
|
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+ Last edited by Mark McLeod : 16-02-2004 at 08:28. |
|
#14
|
||||
|
||||
|
Re: printf isn't printf-ing. Help!
Quote:
|
|
#15
|
|||||
|
|||||
|
Re: printf isn't printf-ing. Help!
Quote:
Hope this helps! |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| clear printf box? | telefragger2000 | Programming | 6 | 05-02-2004 17:40 |