Pages: [1]   Go Down
Author Topic: Arduino 16, Timer 2 PWM and Overflow ISR Crash  (Read 858 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 :'(

Logged

0
Offline Offline
Faraday Member
**
Karma: 16
Posts: 2855
ruggedcircuits.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17303
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: