![]() |
Code error causing robot to go into programming mode.
For some weird reason, our code seems to error out on the 2007 RC and causes it to fall into programming mode. It usually takes between 100-200 seconds to happen, and once its in programming mode, IFI's dashboard doesn't show any errors either. Does anyone know potentially issues that would cause this? Please don't ask for the code as I am not allowed too post it anywhere as we are busy working on something (hopefully) unique. We are considering releasing the finished product.
|
Re: Code error causing robot to go into programming mode.
The master CPU is in charge of putting the robot in program mode. Without specific additional hardware, there is not supposed to be any way for the user program, misbehaving or otherwise, to do it.
Is something intermittently grounding the PROG pin on the RC? Make sure the three-pin PROG/RESET connector is free of metal shavings. Is your master code corrupt? Try reloading it (and remember to reload your user code immediately afterward). |
Re: Code error causing robot to go into programming mode.
We have had code faults/freezups that lit the program
light, but it wasn't really in program mode. We have had to hold the program button down for the usual amount of time to get it into program mode, not being able to see the light change, to load a new program to recover the RC. Given the "uniqueness" of what you are doing, and the stated fact that you don't want to expose it to get help, you are handicapping those who might be able to help. Eugene |
Re: Code error causing robot to go into programming mode.
"The master CPU is in charge of putting the robot in program mode."
Out of curiosity, how is this done? It doesn't appear to be using the ICSP programming as that requires the RB5/PGM pin to be dedicated to programming mode and therefore cannot be used as general io bit, but it is available on the user processor so... Also, the rs232 port used to download data is connected to the user processor, does this mean that it is connected to both the master and shared processor? The SPI port communications between the master and slave only communicate the fixed size data io controller tx/rx packets via double buffering... there doesn't appear to be anything else communicated via this path when I looked at the SPI port, although it is possible there is more code for this port other than the high priority interrupt routine. I was always under the impression that the boot block in 0..800h contained the program download bootloader within the user processor and once put into program mode, this code within this boot block on the user processor was running. |
Re: Code error causing robot to go into programming mode.
After some investigation, we have arrived at a couple conclusions:
As I can't post the code, I realize we have to track down the issue ourselves. Other then that, does anyone else have an idea why the robot can fall automatically in programming mode from code? If we find any other methods, we will report back. |
Re: Code error causing robot to go into programming mode.
Quote:
|
Re: Code error causing robot to go into programming mode.
The most likely cause is a random jump/call into the bootloader code in lower memory where I believe the program load code lives.
Look for computed jumps or function calls. These are the most likely culprits. Its possible if you are doing something like: Code:
Another option is poor power conditioning resulting in drop outs, brown outs, or noise spikes that could cause strange execution results... but this would be low on my list of suspects. Try printing out the address of any computed function calls like above or any computed jumps. Computed jumps are sometimes used for case and other tables by computing and offset and then directly writting to the PC<low> address register. Print out the computed address before invoking the jump. |
Re: Code error causing robot to go into programming mode.
After some intensive investigation, we tracked down the issues to the interrupts. The default code has this defined:
Code:
#pragma codeCode:
#pragma code |
Re: Code error causing robot to go into programming mode.
There are conditions for which you may also need to save MATH_DATA,
depending on just what is in the functions you are using. #pragma interruptlow InterruptHandlerLow save=PROD,section("MATH_DATA"),section(".tmpdata") |
Re: Code error causing robot to go into programming mode.
Can someone explain what exactly the line
#pragma interruptlow InterruptHandlerLow save=PROD,section("MATH_DATA"),section(".tmpdata") actually does.. i've always wondered |
Re: Code error causing robot to go into programming mode.
Code:
#pragma interruptlow InterruptHandlerLow save=PROD,section("MATH_DATA"),section(".tmpdata") |
Re: Code error causing robot to go into programming mode.
Thanks!
|
Re: Code error causing robot to go into programming mode.
Quote:
Code:
#pragma code InterruptVectorLow = LOW_INT_VECTORCode:
#define LOW_INT_VECTOR 0x818This might seem weird as the hardware vector addresses for the PIC18F are: Code:
0000 - resetSee section 2.8 of the compiler user's guide. Pragmas tend to be hints to the compiler and linker as to the programmer's intent. A #pragma code indicates that the following contains executable code, vs a #pragma romdata which would indicate the following contains variables and data. This section of the manual is a little misleading. The #pragma interrruptlow is used to declare a low priority interrupt handler, but what it REALLY does is change how the compiler works for the named routine. It inserts a context save at the beginning of the routine, a context restore at the end of the routine, and changes return not to a PIC18F RETURN instruction as it would for "normal" functions, but a RETFIE (return and enable interrupts). Code:
025E4 InterruptHandlerHigh Quote:
This is just one facet of interrupt routines that make it so interesting to make bullet proof interrupt handlers that always works. Other registers that could/might need to be saved are the table registers, FSRs, and others that are used by the compiler for various purposes including array computions and accesses. The safest thing to do is add a long list of things to save... but that slows down the interrupt routine by increasing the size of the context that needs to be saved... but it is the safest. To save a minimum context requires the programmer to analyze the interrupt routine code generated to see which registers and ram are used and make sure they are in the saved context. There are lots of games that can be played to reduce context save time. One way is to save a minimum context for the main interrupt routine and then save a different/fuller context for each specific handler. Code:
#pragma interruptlow __InterruptHandlerLow save=PROD /* You may want to save additional symbols. */As I said, lots of different games can be played with the pragmas but all require programmers to understand what they are asking the compiler to do and why. Its one of the reasons that the save list tends to grow to fairly extensive lengths. |
Re: Code error causing robot to go into programming mode.
In the code example above, the PROD registers are saved/restored in a nested manner although from the discussion this was not intended.
The W,BSR, and STATUS registers are also saved/restored in a nested manner when the strategy described above is used and you might be better off writing your own version of whatever math routine that you need, with its own internal state, that does not require saving/restoring MATH_DATA if performance is an issue. In addition to the business of saving/restoring data that the interrupt handler uses you also have to worry about race conditions when communicating multi-byte data between the interrupt handler and the main program. The individual bytes of a multi-byte value are read/written one at a time on the micro-controller and the interrupt can strike between these individual reads/writes, leading to a corrupt multi-byte value being transferred between the interrupt handlers and the main program. So, write that interrupt code and associated accessor routines with care... Eugene |
Re: Code error causing robot to go into programming mode.
The real gotcha is upon returning from HandlerInt2() in the example, interrupts are turned back on by the RETFIE at the end of HandlerInt2. Not too much of a problem unless the machine is saturated with interrupts and then a stack overflow condition may randomly occur due to nesting of the main interrupt handler. Turning interrupts back off in the main isr upon return would limit the exposure to this problem to only 1-2 instruction cycles. But there are better methods that can be used to avoid this althogether.
|
| All times are GMT -5. The time now is 14:10. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi