Go Down

Topic: Arduino 16, Timer 2 PWM and Overflow ISR Crash (Read 896 times) previous topic - next topic

aka47

Hi Guys,

This is probably going to be a very dumb question, Sorry I am new.

I have been experimenting with some code for an app where I wanted 6 PWM channels of custom waveforms.

I seem to have blundered into what may be a bug but because I am a touch new here i am not sure.

I have defined all six (168) PWM channels as output and am currently running a pair of for loops in loop() to give six channels of triangle waveform.

It works great. I realy want to be a able to rewrite the PWM values  for all six channels from pre calculated Look up tables.

LUT's are pretty straight forward so no problems there.

I set up a blank ISR using the overflow for timer 2, and the avr interrupt.h method.

If I call other subroutines or mess with variables from my ISR it works fine.

When I try and call digitalWrite() from the ISR to toggle a debug pin it crashes.

Is this usual ??

Thanks in advance

aka47 :'(


RuggedCircuits

Have you tried calling a subroutine from the ISR which itself calls more subroutines? You may be "on the edge" of available stack space, and with each subroutine call you use up a little stack. digitalWrite() does call a sub-sub-routine so you may have a crashed stack that you don't see if you only call a "simple" subroutine that calls nothing else.

aka47

Thanks for the reply, much appreciated.

Yes I tried this it was OK. It seems to be whenever I try to work with IO for some reason. The analogue routines do the same.

I will try with a newer version of Arduino when the next is released and see if it helps.

Cheers

retrolefty

Well not enough of a code guy to help you dig down, but the 'rule of thump' when creating ISR routines is to keep them as short and simple as possible as all interrupts are disabled while a ISR is active. This can effect timing of other running I/O routines, etc.
Set/reset global flags while in the ISR that the main loop of the sketch can deal with. Calling functions within a ISR is just asking for problems.

Lefty

Go Up