EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

ATTiny2313 Timer1 output compare broken in AVR Studio ?

Started by Unknown February 20, 2005
Hi,

I am attempting to use the AVR Studio IDE to implement a simple program
for ATtiny2313, utilizing both the 8-bit timer0 and the 16-bit timer1.
I am using the latest version of AVR Studio (4.11.401). Unfortunately,
I have discovered that the output compare interrupt for timer1 is not
handled correctly by the simulator.

Here is what I did:

* Create a new project under AVR Studio, and select "Simulator" as the
platform, and "ATtiny2313" as the device.
* Write a short program to intialize timer1.
  * Set the timer to CTC mode, and set the TOP value to OCR1A
(WGM13:10==0100)
  * Set OCR1A to 5
  * Enable the output compare A interrupt in TIMSK (OCIE1A==1)
  * Write an interrupt handler routine for it, with a simple NOP
inside, and place it at the correct address in the interrupt vector
table ($0004)
* My main program enables global interrupts, and loops in an infinite
loop.

Here is what I observe in the simulator:
* All the timer registers (TIMSK, OCR1A, TCCR1x) are set correctly
* The timer counter TCNT1H:TCNT1L counts from 0 to 5, then clears back
to 0, as expected (in CTC mode)
* The flag OCF1A in TIFR is set each time the timer loops around. The
OCF1A flag is cleared during the next CPU instruction.
* And yet, my interrupt routine is never called.

I have tried setting breakpoints in my routine, using the "run to
cursor" command, or stepping through execution manually with the "step
into" button. The result is the same: the output compare A interrupt
flag is set and cleared, yet my interrupt routine is never called.

Just out of curiosity, I decided to replace "attiny2313" with
"at90s2313" as the Device under the "Debug | Select platform and
device" menu in AVR studio. When I did that, my interrupt routine
started working as expected -- i.e., it was called each time the OCF1A
flag was set.

It would appear that there is a bug in the simulator for attiny2313,
which prevents it from simulating the OCF1A interrupt properly.

I should also point out that the 8-bit timer0 does not suffer from this
problem - - both its output compare interrupts (OCF0A and OCF0B) are
raised and simulated properly.

Is anyone else experiencing this problem ? Is there a workaround ?

Yes, I have run across the same problem and reported it to atmel who have
acknowledged that it is a bug in the simulator.  avrstudio 4.09 simulates
the timer 1 compare match properly, but timer0 does not seem to run
properly...


The 2024 Embedded Online Conference