Society of Robots - Robot Forum

Software => Software => Topic started by: Admin on January 11, 2009, 06:57:08 AM

Title: request for programming help, latest gcc breaks Axon
Post by: Admin on January 11, 2009, 06:57:08 AM
The latest Axon code worked fine on my Axon until I upgraded to the latest gcc. Now my Axon resets randomly as if the WDT was turned on or the battery was failing. Tried several batteries, and the WDT is definitely off. Turning brownout detection off doesn't fix it, leading me to believe its definitely not a power issue.

Can those with the latest WinAVR and AVR Studio versions try and run the latest Axon code as-is? I've spent hours on the code and can't figure out whats happening . . .

I can't even seem to narrow it down at all in the code . . .
Title: Re: request for programming help, latest gcc breaks Axon
Post by: yerbie on January 11, 2009, 07:20:43 AM
That's odd. i've been using the 2008-12-05 version without any issues.  Of course I'm only using a small subset of your code.
Title: Re: request for programming help, latest gcc breaks Axon
Post by: Admin on January 11, 2009, 07:23:36 AM
What are your gcc and AVR Studio versions?


I just tried the code on multiple Axons, still the same problem.

I also uploaded .hex files from previous versions, and the problem doesn't appear.
Title: Re: request for programming help, latest gcc breaks Axon
Post by: yerbie on January 11, 2009, 07:28:27 AM
i'm not using avr studio, but just gcc 1205-2008.

i'm using emacs with just make in dos. never really liked any other ides except emacs  :)

here's my code.
Title: Re: request for programming help, latest gcc breaks Axon
Post by: Admin on January 11, 2009, 07:51:24 AM
hmmm your code is giving me the same problem . . . can you upload the Axon.hex of my latest version and tell me if it resets on you?

If it works for you then its definitely both my batteries are screwed up . . . I think I'm going to go out and buy a multimeter tomorrow . . .
Title: Re: request for programming help, latest gcc breaks Axon
Post by: yerbie on January 11, 2009, 07:54:02 AM
i dont see where the 1.03 release is
http://www.societyofrobots.com/axon/axon_function_list.shtml
Title: Re: request for programming help, latest gcc breaks Axon
Post by: yerbie on January 11, 2009, 08:00:22 AM
i uploaded the 1.02 axon.hex file and that is working just fine for me
Title: Re: request for programming help, latest gcc breaks Axon
Post by: Admin on January 11, 2009, 08:03:56 AM
oops, forgot to upload it.

look again . . .
Title: Re: request for programming help, latest gcc breaks Axon
Post by: yerbie on January 11, 2009, 08:04:54 AM
um, why is it still pointing to 112808.zip?
Title: Re: request for programming help, latest gcc breaks Axon
Post by: yerbie on January 11, 2009, 08:07:45 AM
interesting... that version 1.03 i just download keeps on reseting  :o

i tried my servo.hex again and it works fine.
how are you compiling my code?
make -f makefile.avr all

avr-gcc: c:\WINAVR-20081205
Title: Re: request for programming help, latest gcc breaks Axon
Post by: Admin on January 11, 2009, 08:28:33 AM
to complicate things . . . I turned on the WDT watchdog fuse using AVR Studio to see what would happen.

The Axon then started restarting super fast. As expected.

But when I remove the fuse, the super fast restarting doesn't stop happening . . . its as if AVR Studio can't turn off the WDT fuse or something even though the checkbox says so . . .

The super fast restarting won't stop . . .
Title: Re: request for programming help, latest gcc breaks Axon
Post by: yerbie on January 11, 2009, 08:47:21 AM
ok, i just verified.  i get the same problem when using your axon 1.03 code with your makefile.
here's how i fixed it.

1. did a make all with your makefile... axon restarts all the time
2. copied my makefile.avr over and did a make... get redefine warnings on F_CPU & PIN... axon restarts all the time
3. removed those #defines to get rid of the warnings... axon still restarts
4. removed buffer.c uart4.c and used my library  (libuart4.a) of those version... axon works!

i've attached the fixed myaxon.hex
Title: Re: request for programming help, latest gcc breaks Axon
Post by: Admin on January 11, 2009, 11:04:20 AM
hmmmm i guess that means the problem is in one of three places:
makefile
buffer.c
uart.c

I haven't touched buffer.c in any version . . . so its either the makefile or uart.c . . . but the resets seem random to me . . . I'd really like to figure out where the problem is actually happening, and why only after upgrading WinAVR and AVR Studio . . .

At the moment the watchdog still refuses to turn off . . . so gotta figure out that problem too:
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=528371#528371
Title: Re: request for programming help, latest gcc breaks Axon
Post by: Tomas on January 22, 2009, 04:21:33 AM
Im having the same problems with 1.03, the microcomputer just keeps on resetting. Seems like 1.01 doesnt have this problem, I think I had the same problem with 1.02. For now, Im just using 1.01.
Title: Re: request for programming help, latest gcc breaks Axon
Post by: Admin on January 22, 2009, 08:15:28 PM
I'm still in Singapore so haven't had much time to look at it. I'll try and resolve this next week. I'll just start with v1.01 software and slowly re-upgrade it until it breaks.

Tomas, you were asking about PWM in other posts. I believe you can get it to work for now by using v1.03 timer640.c and timer640.h with the v1.01 software. You also have to add both of these to the makefile.
Title: Re: request for programming help, latest gcc breaks Axon
Post by: yerbie on January 22, 2009, 09:40:45 PM
Admin,

Can you try this version of the source?  You'll need to recompile it.  I was able to get it to work on my axon finally after some brute force debugging.  You can take a look at my release notes for more information.
Title: Re: request for programming help, latest gcc breaks Axon
Post by: Admin on January 23, 2009, 03:49:27 AM
I'm such a nerd that I brought an Axon and everything I need to use it to Singapore with me . . .

I simply commented out timer4Init() and timer3Init() in main() and its working fine now.

So finally the problem has been narrowed down! I'll play around a little more and see what happens.

I'll also update the file on the code download page so people can use the latest PWM functions.
Title: Re: request for programming help, latest gcc breaks Axon
Post by: Admin on January 23, 2009, 05:33:50 AM
I've been thinking maybe it has something to do with the timer345 overflow interrupts.

For example, I have no idea what this below code does in timer640.h. I added stuff to the default AVRlib timer8x.h just to keep errors from popping up for the ATmega640, but it still doesn't really make sense to me:
Code: [Select]
// interrupt macros for attaching user functions to timer interrupts
// use these with timerAttach( intNum, function )
#define TIMER0OVERFLOW_INT 0

#define TIMER1OVERFLOW_INT 1
#define TIMER1OUTCOMPAREA_INT 2
#define TIMER1OUTCOMPAREB_INT 3
#define TIMER1INPUTCAPTURE_INT 4

#define TIMER2OVERFLOW_INT 5
#define TIMER2OUTCOMPARE_INT 6

#ifdef OCR0 // for processors that support output compare on Timer0
#define TIMER0OUTCOMPARE_INT 7
#define TIMER_NUM_INTERRUPTS 8
#else
#define TIMER_NUM_INTERRUPTS 7
#endif

//SoR Added
#define TIMER3OVERFLOW_INT 9
#define TIMER4OVERFLOW_INT 10
#define TIMER5OVERFLOW_INT 11
#define TIMER0OUTCOMPAREA_INT 12
#define TIMER0OUTCOMPAREB_INT 13
#define TIMER0INPUTCAPTURE_INT 14
#define TIMER2OUTCOMPAREA_INT 15
#define TIMER2OUTCOMPAREB_INT 16
#define TIMER2INPUTCAPTURE_INT 17

And then you see some of those values being used at the bottom of timer640.c:

Code: [Select]
#ifdef TCNT2 // support timer2 only if it exists
//! Interrupt handler for tcnt2 overflow interrupt
TIMER_INTERRUPT_HANDLER(SIG_OVERFLOW2)
{
Timer2Reg0++; // increment low-order counter

// if a user function is defined, execute it
if(TimerIntFunc[TIMER2OVERFLOW_INT])
TimerIntFunc[TIMER2OVERFLOW_INT]();
}
#endif

#ifdef TCNT3 // support timer3 only if it exists
//! Interrupt handler for tcnt3 overflow interrupt
TIMER_INTERRUPT_HANDLER(SIG_OVERFLOW3)
{
Timer3Reg0++; // increment low-order counter

// if a user function is defined, execute it
if(TimerIntFunc[TIMER3OVERFLOW_INT])
TimerIntFunc[TIMER3OVERFLOW_INT]();
}
#endif

#ifdef TCNT4 // support timer4 only if it exists
//! Interrupt handler for tcnt4 overflow interrupt
TIMER_INTERRUPT_HANDLER(SIG_OVERFLOW4)
{
Timer4Reg0++; // increment low-order counter

// if a user function is defined, execute it
if(TimerIntFunc[TIMER4OVERFLOW_INT])
TimerIntFunc[TIMER4OVERFLOW_INT]();
}
#endif


Perhaps some interrupt is creating the reset somehow?


btw, the link to the latest working code:
http://www.societyofrobots.com/axon/downloads/Axon_Source_012309.zip
Not thoroughly tested, and timer 3 and 4 won't work, but no resets at least!

edit: fixed link
Title: Re: request for programming help, latest gcc breaks Axon
Post by: yerbie on January 23, 2009, 11:04:55 AM
I didn't realize the timezone in Thailand was 1 month ahead of the US.  ;D
Quote
Axon Source Code v1.04 (February 23rd, 2009 - timer3,4 broken)
Title: Re: request for programming help, latest gcc breaks Axon
Post by: Admin on January 23, 2009, 10:19:18 PM
I didn't realize the timezone in Thailand was 1 month ahead of the US.  ;D
Quote
Axon Source Code v1.04 (February 23rd, 2009 - timer3,4 broken)

lol . . . it was a year off just last night until I 'fixed' it . . . plus I'm in Singapore right now :P
Title: Re: request for programming help, latest gcc breaks Axon
Post by: yerbie on January 25, 2009, 10:20:30 AM
timer3 & timer4 issue is fixed.  You can see my changes here: http://axonavr.svn.sourceforge.net/viewvc/axonavr/SocietyOfRobots/
this site greatly helped figure out what the issue was and why the axon was resetting continuously: http://www.gnu.org/savannah-checkouts/non-gnu/avr-libc/user-manual/group__avr__interrupts.html
Quote
If an unexpected interrupt occurs (interrupt is enabled and no handler is installed, which usually indicates a bug), then the default action is to reset the device by jumping to the reset vector. You can override this by supplying a function named BADISR_vect which should be defined with ISR() as such.

after some more brute force debugging, I figured out the missing interrupt was due to INT0_vect which is connected to PD0.

Admin: Do you know what PD0 pin on the Axon is being used for?

You might want to add this to your FAQ about axon continuously resetting :)

BTW, timer640 is really out of date and does not use all the power of the ATmega640 timers.  I'm planning on rewriting all of the AVRlib code to be up-to-date with the latest gcc.  AVRlib uses a lot of deprecated methods.
Title: Re: request for programming help, latest gcc breaks Axon
Post by: Admin on January 26, 2009, 03:47:51 AM
I just replaced my timer640.c with yours and gave it a test run. Seems to be all working now. I uploaded it all as v1.05, and removed the other broken versions. Hopefully no other problems pop up!

(and a huge thanks to you, I was losing hair over this!)

Quote
Admin: Do you know what PD0 pin on the Axon is being used for?
SCL for I2C
http://www.societyofrobots.com/axon/images/640pinout.gif

Quote
BTW, timer640 is really out of date and does not use all the power of the ATmega640 timers.  I'm planning on rewriting all of the AVRlib code to be up-to-date with the latest gcc.  AVRlib uses a lot of deprecated methods.
Let me know what changes you make! AVRfreaks.net people complain about how outdated AVRlib is, but no one has rewritten anything . . . I had to rewrite a decent amount just to get it to work with the 640.

My major focus for Axon code development is to make it compatible with external hardware (ie souce code), and making complicated AVR features easy to use (ie PWM, interrupts, UART, etc). I'm not a professional programmer so my code will hardly be clean or efficient. :P
Title: Re: request for programming help, latest gcc breaks Axon
Post by: yerbie on January 26, 2009, 07:46:22 AM
Quote
I uploaded it all as v1.05, and removed the other broken versions. Hopefully no other problems pop up!
I also updated sf.net to reflect what you did.  And let me know if any other issues you may have.

Quote
(and a huge thanks to you, I was losing hair over this!)
no problem.  I wanted to look into this, since I have an Axon as well and it needed to be fixed anyways.

Quote
Let me know what changes you make! AVRfreaks.net people complain about how outdated AVRlib is, but no one has rewritten anything . . . I had to rewrite a decent amount just to get it to work with the 640.
My plan is create an AVRlib version that only supports the Axon (ATmega640) controller.  All the other stuff in his code is bloated and causes me grief.

Quote
My major focus for Axon code development is to make it compatible with external hardware (ie souce code), and making complicated AVR features easy to use (ie PWM, interrupts, UART, etc). I'm not a professional programmer so my code will hardly be clean or efficient. :P
Mine too, however I am a professional programmer, with a major in EE, so I will be able to go in there and clean up any code that isn't efficient :)