Re: bug with timer0 interrupt?
Georg-Johann Lay <[email protected]>
| Newsgroups | gmane.comp.hardware.avr.gcc |
|---|---|
| Message-ID | <[email protected]> |
Jonathan Geisler schrieb: > I'm encountering a strange error with avr-gcc 4.6.3 and 4.7.2 using > the timer interrupt. The code I'm using is attached. As you can see, > I was trying to tie in to the Arduino environment (with Eclipse) so > that I could help my students wean off that set of functions to being > able to use the hardware directly. > > When I set up the library, I encountered a strange error and was able > to trace it back to this simple program that sets up the timer with a > prescalar of 1024 and then increments an unsigned long counter when > that timer overflows. When the counter reaches a specific value, I > toggle the built-in LED on the Arduino board connected to PORTB. > > The strange behavior is that if I initialize the counter to 0, the > code doesn't work--appearing to hang. If I initialize the counter to > 1, everything works perfectly. I have verified that if I make a > similar change to the Arduino libraries that the original code begins > to work properly. > > I'm not sure what the exact error is since I can use the Arduino > environment on my machine without a problem, but when I try to compile > it through Eclipse it gives me this error. I'll include the build log > as an attachment in case particular compiler/linker flags are triggering > the error. When you change count in the ISR and read it in main, the read must be atomic. Otherwise, you may see glitches and phantom values. It atomic access does not help, you can compare the code generated with your Eclipse setup and with your Arduino setup. You cal also check the generated assembly whether or not it is as you expect. If so, your problem is somewhere else. You could also supply a test case that can be compiled and reproduced. To get a test case, add -v -save-temps to the compiler options and recompile. Then post the console output of the compiler and the .ii file. Johann