Two Timer interrupts

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

Hi, 

 

I am using the latest version Atmel Studio Version 7.0.1006

Processor ATMEGA16

 

With the build in GCC compiler i try to use interrupts of  two timers, i used creation of Gcc C executable code has GCC C++ executable code, with the same results.

 

When timer0 is defined alone, it is ok, the port PB0 is toggled every 50ms.

 

But from the moment i start Timer2, by setting the prescallers, it appears that it influences the puls on PB0, every 50ms i see a 10Us puls.

Although i have not even written an interrupt routine to handel Timer2 compare match interrupt.

 

If i include a interrupt routine to toggle PB4 on Timer2 compare match. Then i can not start the program in debug mode. It always stops after a run command.

 

In disassembed listing, in interrupt jump table,  the two interrupts jump to the correct interrupt routines.

 

I am new with GCC.  Is it something i am missing in the setup of GCC ?

 

Thanks for your advice,

Best regards,

Fabrizio

Attachment(s): 

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

But that code only has an ISR for the TIMER0 compare. But you also set:

   TIMSK |= 1<<OCIE2;

You *MUST* provide an ISR for every interrupt source you enable (as soon as sei() is to be used) because what's happening right now is that when the second timer has the OCR match and there is a call to TIER2_COMP_vect (which has not been defined) the default action is given under "catch all interrupt" in the user manual here:

 

http://www.nongnu.org/avr-libc/u...

 

As it tells you there, all the interrupts that have no ISR() code will jump to "bad_interrupt" and it just does "JMP 0". So this has the effect of resetting the AVR every time the missing interrupt is called.

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

I left out the interrupt routine of timer2 for testing, that was not a good idee.

 

The problem is that in debug mode the code is not running.

The execution of the code stops always after the ISR of Timer2, Yellow arrow at end of ISR procedure.

 

The code works, when stopping debug mode, i can see the two pulses on the scoop.

 

I use Jtagice-MKII  has debugger.

JTAG clock is set on 200Khz, i tryed also on 750khz, with same behaviour, target is running on 3,6864Mhz

Use external reset check/uncheck is the same

 

Any help on this problem is appreciated .

 

Thanks in advance,

Fabrizio

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

So this is nothing about the code (which was wrong anyway!) but about whether timers/interrupts continue to run when you are debugging? There are options in Studio to modify the behaviour of the debugger in this regard.

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

The options for timers to keep running in stop mode is set.

 

It has to to with compiler code optimalisation.

 

When optimalisation is set to None, program execution in debug mode is executing with on stop on instruction  TIMSK |= 1<<OCIE2;   in Initialisation_Generic(void)  procedure.

After a continue, the debugger keeps running.

 

I found a tutorial "Optimization and the importance of volatile in GCC" actually written by U in 2005 about this subject.

 

I will read this tutorial first.

 

Thanks for advice,

Best regards,

Fabrizio