Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

RE: [AVR-Chat] Re: C Code weird behaviour help?

2007-01-30 by larry barello

Check out the libc FAQ it has many hints/tips for variable optimization (or
how to avoid it) and loop stuff.

In short you need to be very aware of variables that are modified outside
the scope of the C compiler: e.g. interrupts.  Then you need to use the
"volatile" keyword.  I find using "volatile" also useful when creating delay
loops.  But better yet, use the supplied libc functions (delay.h) - or
better yet, look at delay.h and see how the compiler guru's did it.  Many
useful lessons there!

Cheers!

-----Original Message-----
From: AVR-Chat@yahoogroups.com [mailto:AVR-Chat@yahoogroups.com] On Behalf
Of luthjej
Sent: Monday, January 29, 2007 4:52 PM
To: AVR-Chat@yahoogroups.com
Subject: [AVR-Chat] Re: C Code weird behaviour help?

Hi All,

Thanks for all your advice / help on this irritating problem.

Tim, I suspect you are probably correct - the code segment WAS working
fine, it was only when I went back to check the functionality of the
whole appliance that I discovered the problem - so it must be an
interaction between some other part of the code.

Although at the end of the day, all the code is doing is to
essentially compare var-a with var-b and return a result - even when
the dynamic updating is taken out (and manual value assignment is put
in it's place) it does not work.

This is not the 1st weird behaviour with loop checking I've seen with
this compilier, I had another problem also with the while loops that I
had to "fix" by putting if-then-"break" statements in the code to make
the while loops terminate.

The "fix" was to spend 1/2 a day porting the code into AVR-GCC (thanks
for the suggestion / quick start guide Larry!) - apart from a few
annoying things (e.g. itoa/ltoa's parameters in a different order),
about the only thing that avr-gcc picked up wrong with the code was a
couple of unused variables in main(). But the application now works
fine and all the while{} loops now work as they should.

Chalk one up for avr-gcc! I think avr-gcc will definately be the
compiler of choice for the next project!

Now I just have to figure out how to get gcc to stop optimizing out my
delay routines :)  But very minor in the scheme of things.



Thanks again for all the replies / help.


Cheers,


Jon



 
Yahoo! Groups Links

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.