Go to Post i openly welcome our large game piece overlords - Chexposito [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 27-02-2007, 00:05
PhilBot's Avatar
PhilBot PhilBot is offline
Get a life? This IS my life!
AKA: Phil Malone
FRC #1629 (GaCo: The Garrett Coalition)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Maryland
Posts: 747
PhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond repute
How do I know if I'm overloading the RC program?

I'm an experienced embedded programmer, but I'm still getting to know the IFI RC. I'm getting the feeling that I'm on the hairy edge of what the RC is capable of.

Despite my best efforts to partition the program into neat modular sections, I'm starting to see erratic behaviour that is hard to explain from simple bugs.

I get different behavior just from adding a simple (fully tested) function call. Printf's stop working for no apparent reason. I'm now able to crash the program simply by flicking a switch, and I can even put the RC into a fault mode that is only recoverable by powering it down (resetting it won't fix the problem).

So, I have some basic debugging questions:

1) What causes the Program State light to flash? Is it detecting that my code is not doing something in particular (like servicing the shared memory)?

2) Could I be exceeding my stack size (from nesting my calls to deep)? Is there an easy way to increase the stack allocation, or will it just use available memory until it runs into data? I see the size set to 0x0100 in the linker but I'm not sure how to change it.

3) I've limited my use of floats to only the essential functions, but I assume that I could be burning all my CPU time in PID loops etc. Will the program crash if I don't service all my code in the allotted 28ms click time?

4) I'm using 4 analog inputs and the Gyro and the Camera... Any way to tell if I'm getting too many interrupts or other critical elements?

Thanks for any advanced "generic" debugging help.

Phil.
__________________
Phil Malone
Garrett Engineering And Robotics Society (GEARS) founder.
http://www.GEARSinc.org

FRC1629 Mentor, FTC2818 Coach, FTC4240 Mentor, FLL NeXTGEN Mentor
  #2   Spotlight this post!  
Unread 27-02-2007, 00:16
whytheheckme's Avatar
whytheheckme whytheheckme is offline
Registered User
AKA: Jacob Komar
no team
 
Join Date: Feb 2006
Rookie Year: 2005
Location: Providence, RI
Posts: 1,320
whytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond repute
Send a message via ICQ to whytheheckme Send a message via AIM to whytheheckme Send a message via MSN to whytheheckme Send a message via Yahoo to whytheheckme
Re: How do I know if I'm overloading the RC program?

In a quick regard to 4.) I am using all 6 interupts, the camera, the gyro and the accelerometer, not to mention an ultrasonic and some limit switches, pots, etc... I don't think that this is the problem.

This sounds weird. Can you post a copy of your code in a zip? Or if you don't want to give this away, can you give us an idea of the flow of the program? I doubt that there is *too much stuff*, unless you are doing a SERIOUS amount of math. Even in this case, the printf's would just be slow, not stopped. And the program state light would not be blinking either O.o...

Jacob
  #3   Spotlight this post!  
Unread 27-02-2007, 01:11
psquared89's Avatar
psquared89 psquared89 is offline
Registered User
AKA: Pat Pannuto
FRC #0245 (Adambots)
Team Role: Driver
 
Join Date: Mar 2005
Rookie Year: 2004
Location: Rochester Hills, MI
Posts: 73
psquared89 is a jewel in the roughpsquared89 is a jewel in the roughpsquared89 is a jewel in the roughpsquared89 is a jewel in the rough
Re: How do I know if I'm overloading the RC program?

I'd be wary about anything floating point. The 18F's don't have any hardware float processing capability, it's all software emulated, so accuracy, speed, etc are all less than spectacular.

If you can, I'd suggest re-writing and either bit-shifting it to integer math or simplyfying the results (less precision). Otherwise, I'd suggest the use of a coprocessor. We have a nice Python implementation using GUMSTIX. If you like, you can see more details on our website ( www.adambots.com , click on "Co-processor" ) or PM me.
__________________
At the end of the game, the King and the Pawn both go back into the same box.
~ Italian Proverb
---------------------------------
adambots.com
  #4   Spotlight this post!  
Unread 27-02-2007, 02:07
Eldarion's Avatar
Eldarion Eldarion is offline
Electrical Engineer / Computer Geek
AKA: Eldarion Telcontar
no team (Teamless Orphan)
Team Role: Alumni
 
Join Date: Nov 2005
Rookie Year: 2005
Location: Númenor
Posts: 558
Eldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond repute
Send a message via AIM to Eldarion Send a message via Yahoo to Eldarion
Re: How do I know if I'm overloading the RC program?

Quote:
Originally Posted by PhilBot View Post
1) What causes the Program State light to flash? Is it detecting that my code is not doing something in particular (like servicing the shared memory)?

I have run into a similar situation with the RC. Try commenting out ALL of your printfs and see if you get the red light of death. Also, the processor hates the use of long data types (don't ask me why, but replacing all longs with ints magically made a program of ours work). I think that under certain circumstances the user code can corrupt the I2C datastream that links the user and master processor, confusing the master. It would probably be helpful to have the IFI I2C link's source code to figure out what is happening, but I don't think there is any way to obtain that!

As a side note, did you try protecting GPR14 (the old 8.2V bug fix)?
__________________
CMUCam not working? Tracks sporadically? Try this instead: http://www.falconir.com!
PM me for more information if you are interested (it's open source!).

Want the FIRST Email blasts? See here: http://www.chiefdelphi.com/forums/sh...ad.php?t=50809

"The harder the conflict, the more glorious the triumph. What we obtain too cheaply, we esteem too lightly; it is dearness only that gives everything its value."
-- Thomas Paine

If it's falling apart it's a mechanical problem. If it's spewing smoke it's a electrical problem.
If it's rampaging around destroying things it's a programming problem.

"All technology is run on 'Magic Smoke' contained within the device. As everyone knows, whenever the magic smoke is released, the device ceases to function."
-- Anonymous

I currently speak: English, some German, Verilog, x86 and 8051 Assembler, C, C++, VB, VB.NET, ASP, PHP, HTML, UNIX and SQL
  #5   Spotlight this post!  
Unread 27-02-2007, 08:03
Qbranch Qbranch is offline
wow college goes fast.
AKA: Alex
FRC #1024 (Kil-A-Bytes)
Team Role: Alumni
 
Join Date: Apr 2006
Rookie Year: 2006
Location: Indianapolis
Posts: 1,174
Qbranch has a reputation beyond reputeQbranch has a reputation beyond reputeQbranch has a reputation beyond reputeQbranch has a reputation beyond reputeQbranch has a reputation beyond reputeQbranch has a reputation beyond reputeQbranch has a reputation beyond reputeQbranch has a reputation beyond reputeQbranch has a reputation beyond reputeQbranch has a reputation beyond reputeQbranch has a reputation beyond repute
Re: How do I know if I'm overloading the RC program?

When you say you used all 6 interrupts, did you put encoders on all six of these pins? Make sure you watch your interrupt rates...

If you're questioning how long it takes a routine to run you can always set a pin in the beginning then clear it at the end, just use a scope to time it. Or, if you want to see how often your procesor is idle, just toggle a pin in process_data_from_local_IO() and watch how much time you get a constant frequency compared to how long you have constant up/down states (this would mean your doing something else, not toggling your pin).

I had an issue with encoders having too high an interrupt rate myself, so we switched to a different encoding technology. Remember the ISR that the compiler puts in also takes time, can't quite remember how long.

Remember that floating point operations use the same two registers, so if you interrupt a floating point operation and start doing one in the interrupt, you'll get junk data when you return from the interrupt. Stack overflows on rare occasion will not cause the processor to crash, however usually this will cause the 'code error' light to flash.

If you need anything I havent listed here just give me a pm/email.

-q
__________________
Electrical Engineer Illini
1024 | Programmer '06, '07, '08 | Driver '08
  #6   Spotlight this post!  
Unread 27-02-2007, 08:47
PhilBot's Avatar
PhilBot PhilBot is offline
Get a life? This IS my life!
AKA: Phil Malone
FRC #1629 (GaCo: The Garrett Coalition)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Maryland
Posts: 747
PhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond repute
Re: How do I know if I'm overloading the RC program?

Thaks for the good insights... (I'll have to track down that "protecting GPR14" fix... we do/did have the 8.2 bug).

I found part of my real bug. It was a very nastie case of code reentrancy gone wild. It wasn't planned reentrancy, but a certain state transition was causing A to call B who called A who called B etc.... until all memory was used up. Not very smart.

Now that's fixed I can continue to look for the odd behavior bug.

Phil.
__________________
Phil Malone
Garrett Engineering And Robotics Society (GEARS) founder.
http://www.GEARSinc.org

FRC1629 Mentor, FTC2818 Coach, FTC4240 Mentor, FLL NeXTGEN Mentor
  #7   Spotlight this post!  
Unread 27-02-2007, 09:41
PhilBot's Avatar
PhilBot PhilBot is offline
Get a life? This IS my life!
AKA: Phil Malone
FRC #1629 (GaCo: The Garrett Coalition)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Maryland
Posts: 747
PhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond repute
Smile Re: How do I know if I'm overloading the RC program?

Quote:
Originally Posted by Eldarion View Post
As a side note, did you try protecting GPR14 (the old 8.2V bug fix)?
Oh Boy, that was a great tip. It took me a while to find the reference but I did... Here is the link to the actual file.

http://www.chiefdelphi.com/forums/sh...3&postcount=96

I have disovered that I am using the V2.0 version of Kevin's camera code, which does not have the GPR14 protected. I see that V2.1 does have it protected. That will teach me to be afraid of the "Latest version" of code.

This explains a LOT of the strange behaviour that I was seeing (inputs on the wrong channels etc)

Maybe I'll get some sleep now
__________________
Phil Malone
Garrett Engineering And Robotics Society (GEARS) founder.
http://www.GEARSinc.org

FRC1629 Mentor, FTC2818 Coach, FTC4240 Mentor, FLL NeXTGEN Mentor
  #8   Spotlight this post!  
Unread 28-02-2007, 15:24
dcbrown dcbrown is offline
Registered User
AKA: Bud
no team
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Hollis,NH
Posts: 236
dcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud of
Re: How do I know if I'm overloading the RC program?

Also be aware that the hardware call (PC address) stack is limited. The 256 bytes of allocate stack space in ram/bank memory is for allocation of automatic variables at function call time.

"After the PC is pushed onto the stack 31 times (without popping any values off the stack), the STKFUL bit is set. The STKFUL bit is cleared by software or by a POR (Power-On-Reset)." [PIC Spec]

Typically the processor will reset when the STKFUL bit is set, but the behavior depends on the state of the STVREN (Stack Overflow Reset Enable) configuration bit. This should be enabled to allow the resets in FIRST environments. Runaway re-entrant functions will cause bad behavior including resets as a result of stack overflow. Moreover, out of the stack depth must be reserved call space for low and high interrupts. If the chip isn't being reset because STVREN is clear, then you should be able to check the STKFUL bit in the STKPTR hardware register as the bits will remain on until POR condition or software resets them.

Code:
The high priority interrupt is a two deep stack on the slave processor:
     . (1) InterruptHandlerHigh
         . (2) Prep_SPI_4_First_Byte
         . (2) Handle_Spi_Int
Code:
The low priority interrupt is at least another 4 stack levels in the MPLAB default environment:
     . (1) InterruptHandlerLow
         . (2) CheckUartInts
              . (3) Handle_Panel_Data
              . (3) Process_TX
                   . (4) DisableXmitInts
              . (3) Serial_Char_Callback

So at LEAST 6 stack frames must be reserved for interrupts, maybe more.

Bud
  #9   Spotlight this post!  
Unread 03-03-2007, 20:23
kaszeta's Avatar
kaszeta kaszeta is offline
Registered User
FRC #0095 (Grasshoppers)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Lebanon, NH
Posts: 334
kaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of light
Re: How do I know if I'm overloading the RC program?

Quote:
Originally Posted by PhilBot View Post
Despite my best efforts to partition the program into neat modular sections, I'm starting to see erratic behaviour that is hard to explain from simple bugs.
I'm convinced that there are a lot of gremlins in RC, since in the years since 2003 I've seen a lot of bizarre stuff. The biggest one was the "8.2V" data alignment bug, which basically killed our bot for the entirety of BAE last year (and a bizarre scene in which one of the IFI guys insisted it was our code at fault when we had the default code loaded).

This year, I've had two times where editing a portion of code caused a completely different section of code to stop working. For example, today we added a single check of a limit switch in our non-autonomous code (test rc_dig_in10 and limit a single pwm, either with our own code or with the IFI-supplied routine), and that completely broke the PID loop in autonomous mode which doesn't even call that limit switch code. All I can think of is that somewhere hiding in the code something is trampling on the variables for another variable, like a 16 bit value being written atop an 8 bit value.

Similarly, we had an issue during the Aces High scrimmage where random spurious values would appear on a variable that was tied directly to p1_wheel, even though I could monitor p1_wheel directly and verify it was constant.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Anyone know how fast the Solenoids on the MINI RC can turn on and off? Generalx5 Control System 1 06-01-2007 07:39
How do you program the Photoswitch nekng Programming 2 27-11-2006 13:41
how to add steps in the provided encoder program for the edu Zaramel2002 Programming 3 11-02-2004 08:35
i'm in the charleston area, and i'm looking to help out a team near here... dickymon General Forum 2 05-08-2002 16:40
does anybody know how to program a potentimeter (<--spelling mistake) chrisw Technical Discussion 4 25-01-2002 20:29


All times are GMT -5. The time now is 00:21.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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