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

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.

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.

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.

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!

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

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.

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

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

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

Two things:

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

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.

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

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…

Good point!

So then, the proper code would be:

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

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).