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