Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   internal demons? (http://www.chiefdelphi.com/forums/showthread.php?t=37938)

pagemauck 06-05-2005 09:23

internal demons?
 
We're at our wits end! Two of my C++ students and I are programming with the banner sensors to control wheel rpms. The program will run correctly for a few runs and then inexplicably decide to switch motor outputs ( from pwm01 to pwm02 or whatever we have them set to) and inputs from the light sensors . This has been happening for several weeks. I have redownloaded the master control program, swapped controllers, used different digital inputs ( 6 and 7 or 1 and 2) to no avail. Has anyone had this happen to them before?

Thanks!!

Team 539 programming group

Jack Jones 06-05-2005 10:42

Re: internal demons?
 
Runtime errors are seldom, if ever, inexplicable.

Usually occur when memory gets hammered. Check to see if a string or array is getting written to past its declared end.

kc8nod 06-05-2005 10:51

Re: internal demons?
 
It's very difficult to help you without any specifics. Please post the section of code where you think the problem is. Or better yet, zip up all the .c and .h files and attach them to your post.

The limited description you have given really sounds like a software problem. But you won't get any real help without posting the code.


Quote:

Originally Posted by pagemauck
We're at our wits end!...


Goldeye 07-05-2005 23:30

Re: internal demons?
 
First impulse is that you're using a high priority interrupt. Anything can go wrong when you do. Post any code related to interrupts, if you use them. This is assuming you're using interrupts with them, of course. I suppose there's no guarantee of this.

pagemauck 09-05-2005 09:35

Re: internal demons?
 
Thanks for the replies to my vague question. Specifically what I'm seeing is outputs switched in the printf statements. Does anyone know of a good place to find info on them?

Example :

(We are trying to print motor speed and banner sensor output)

printf ( "%d/n", " pwm01 = ", pwm01 );
printf ( "%d/n", " rc_dig_01 = ", rc_dig_01 );

Output

pwm01 = 1
rc_dig_01 = 145 // these numbers are switched

How do we rewrite the printfs to get what we want?

Thanks!

Alan Anderson 09-05-2005 10:42

Re: internal demons?
 
Quote:

Originally Posted by pagemauck
printf ( "%d/n", " pwm01 = ", pwm01 );
printf ( "%d/n", " rc_dig_01 = ", rc_dig_01 );

That doesn't look right at all. Try this instead:
Code:

printf(" pwm01 = %d/n", pwm01);
printf(" rc_dig_01 = %d/n", rc_dig_01);

Also, make sure you're not trying to do printf() inside any of the interrupt service routines.

Dave Scheck 09-05-2005 10:51

Re: internal demons?
 
Quote:

Originally Posted by Alan Anderson
That doesn't look right at all. Try this instead:
Code:

printf(" pwm01 = %d/n", pwm01);
printf(" rc_dig_01 = %d/n", rc_dig_01);


On top of that you want to use \n instead of /n.
Code:

printf(" pwm01 = %d\n", pwm01);
printf(" rc_dig_01 = %d\n", rc_dig_01);

Depending on what you're using to view the output, you may need to substitute a \r for the \n.

kc8nod 09-05-2005 10:57

Re: internal demons?
 
Quote:

Originally Posted by pagemauck
printf ( "%d/n", " pwm01 = ", pwm01 );
printf ( "%d/n", " rc_dig_01 = ", rc_dig_01 );

Two things:

First, that doesn't look like proper use of the printf function. I think you meant to write this:
Code:

printf ( "pwm01 = %d/n", pwm01 );
printf ( "rc_dig_01 =  %d/n", rc_dig_01 );

Is that really the code you are using? Because I wouldn't think that what you have shown above would even compile.

Secondly, you still haven't given very much information. You'll notice that all the replies so far (including my own) have been guesses and speculation. Please post the whole function at a minimum. However, if you post all the code, I guarantee that someone here will fix your problem for you right away.

kc8nod 09-05-2005 11:02

Re: internal demons?
 
Here is a pretty good explanation of the printf() function.
http://colton.byuh.edu/courses/tut/printf.pdf

eugenebrooks 09-05-2005 15:10

Re: internal demons?
 
Quote:

Originally Posted by kc8nod
Code:

printf ( "pwm01 = %d/n", pwm01 );
printf ( "rc_dig_01 =  %d/n", rc_dig_01 );


Don't forget to cast the "byte sized" arguments to printf,
intended to be formatted with %d, to an int. Byte sized
things get pushed on the stack as bytes, while printf
is expecting an int. This is a vagary of the C18 compiler
environment for the robot controller, and is non-standard.

This addresses bad values printed by printf, but probably
not the trouble you are trying to debug...

kc8nod 09-05-2005 16:00

Re: internal demons?
 
Quote:

Originally Posted by eugenebrooks
Don't forget to cast the "byte sized" arguments to printf...

Good point!

So then, the proper code would be:
Code:

printf ( "pwm01 = %d\r", (int)pwm01 );
printf ( "rc_dig_01 =  %d\r", (int)rc_dig_01 );


Dave Flowerday 09-05-2005 17:32

Re: internal demons?
 
Quote:

Originally Posted by kc8nod
Is that really the code you are using? Because I wouldn't think that what you have shown above would even compile.

Actually, it will. The compiler only knows that printf() takes a string as the first argument, and then zero or more arguments of any type. It does not type-check these arguments and the argument list is parsed at runtime. The way it was originally written, after the format string is another string, but the printf() function would try to interpret this as an integer (because of the %d in the format string).


All times are GMT -5. The time now is 04:42.

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