tracking call and return

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

Hello everybody,

Is there a way in AvrStudio to track the function call stack, including IT (I use V5.1, but I can change for other version).

I am using timer1 to generate waveform. For some I use CTC (Clear on Timer compare) for others PWM Pulse Width Modulation. In CTC mode I change to PWM and back in PWM I change to CTC. This is to avoid unwanted sequences in the waveform due to the double buffering of OCR.
I wish to analyse the address of call & return while changing from CTC to PWM and back from PWM to CTC.
I have observed something strange and I wish to confirm or not. I should say that nevertheless programme is still working fine!

Structure:

IT → ISR(TIMER1_COMPA_vect)
{
If .... return;
If .... return;
if
Point A: to send 23 pulses set PWM
....
Return;
}

IT → ISR(TIMER1_OVF_vect)
{
If ....return;
If ....return;
Set CTC mode
Return;
}
The last return in TIMER1_OVF_vect is apparently to point A in ISR(TIMER1_COMPA_vect) not to the function which was interrupted by overflow. Other return works has expected, return to the function which was interrupted.

Hope my explanation on what I want to analyse are clear enough. (I don't know why the indentation does not appear in my message!)

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

There is no need to go interfering with the stack.

In your ISR(TIM_COMP) you disable OCIE and enable TOIE.
Likewise in ISR(TIM_OVF)

You can clear any pending xxIF bits before you leave the ISR().

Of course you can fiddle with the stack if you really want. OTOH, you know that it was TOIF that got you there if you are in ISR(TIM_OVF).

Also note that there are immediate OCRA and buffered OCRA modes.

David.

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

david.prentice wrote:
There is no need to go interfering with the stack.
Of course you can fiddle with the stack David.

Sorry I can see that my question was not clear enough. I don't want to interfere or fiddle with the stack in any way.
I want to track the call and return address while simulating in AvrStudio, as you will watch a variable in a watch window.

Is there a way to know where a programme was interrupted and if the return occurs at that point, even after many other function calls and may be other interrupt.

Pierre

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

You just inspect the stack. Read the return address.

Now you know what you were doing when you were interrupted.

Does it really matter?
As long as your ISR() preserve registers and flags properly, you do not crash your foreground code.

Yes. The return is always at the 'next' instruction.
Unless you want to crash the code intentionally.

David.