Well, the ISR is still being called with a frequency of 16kHz. It's just the extra stuff inside the ISR is artificially being run every 1kHz, because of the ISRCounter variable I'm using. So, I think about 1 time out of 16 calls, it may take too much time inside the ISR. But the ISR is the only thing that's happening in the whole program, except for a watchdog timer reset, which is ever 2 seconds. Is a rare (every 16 times) periodic overflow acceptable?
My understanding is that if I change the timer1 ISR frequency to 1 or 2 or 4 kHz, that it will mean that the pwm waveform will lengthen, and I'll hear an annoying buzz, since the interrupt is triggered each time the pwm waveform completes a single cycle (which takes 1024 clock counts. up to 512 and back down to 0, at which point the interrupt is called).
I could use a different timer (say timer2) with a different prescaler so that its interrupt would be called with a frequency of let's say 2kHz, but I would perhaps lose the measurement of the current at the exact same point on the pwm waveform. However, since 16kHz is a multiple of 2kHz, maybe it would be at about the same point on every 8th pwm waveform??? I'm not sure though. That would be really really nice later if I needed to do other stuff that took longer too, like sending data through the usart while driving. The nice thing is, if I try it out, go take a drive, and everything feels perfect, then it doesn't really matter too much I guess.
Last edited by MPaulHolmes; 05-25-2009 at 01:14 PM..
|