Interrupts and optimization

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is my lucky day. After working my a$$ off for a few days I finally discovered that:

-the avrgcc-compiler isn't reliable
(it doesn't do what it claims to or is supposed to do)
-the atmel datasheets have way too many fact left out
(trial and error is the only way to go)

A warning to those using interrupts: The interruptbits (in TIMSK for example) are cleared by the sei() function (or rather the processor?). So

TIMSK=0x10;
sei();

won't work. It's gotta be the other way around.

Using
SREG |= 0x80;
works better than sei() at times, but not always.

Then the optimization must be set to 0 at all times or you won't get what you aim for. I had the code
i++;
in an interrupt-routine, and it was optimized away by the compiler. So set the optimization to 0 or you'll regret it.

PORTC=PORTB; will give you a flashing xmas-tree but not one that looks like you thought it would.

Any opinions about this? Am I wrong?
Now I'm off to work with the ADC. Yeeha! Way to spoil a good mood.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

You have encourated very some strange problems because I use avrgcc 3.2 with full optimisation (-Os) and all work fine with plenty of real time interrupts. when I test your little example (timsk and sei), all is ok, pre-incrementation inside interrupt is ok. Whait is your target ? version of compiler ? Have you a little example of your code where you find an error (post that "a peace of .lst")). In waiting,

Good luck

Frantz

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I use the 3.0.2 since I could get the interrupts to run with the 3.2 version, and since the latter is an experimental release.

I use the AT90S8535, which suits me very well.

Changing from -O1 to -O0 made a whole difference. I read different registers and they didn't contain what they should (or the reading was bad) if I used optimization.

More info later (if I still have a version that won't compile).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I use the AT90S8535 with the avrgcc 3.2 (experimental) and it works just fine.
I use the following interrupts: 16-bit timer (~15 Hz), 16-bit timer compare (~100 Hz)
and ADC in free running mode (~20 kHz). Ussually I ask the compiler for -O2 optimization.

However I only use outb(), inb(), outw(), inw(), cbi(), sbi() to manipulatr the I/O.

Pawel

ps. To move from avrgcc 3.0 to 3.2 I had only to replace the I/O calls:

outp() -> outb() (swap arguments !)
inp() -> inb()
__outw() -> outw() (swap arguments!)
__inw() -> inw()

after that change, the code was back in order.

admin's test signature