PDA

View Full Version : Why use Interrupts



lerameur
- 11th May 2007, 22:59
Hi,

I have not work with interrupts yet, But I heard different stories on them. Some say they are useful, other say they don't use them and rather trouble shoot in real time.
I would just like to have your opinion on this

thanks
ken

skimask
- 11th May 2007, 23:09
Hi,
I have not work with interrupts yet, But I heard different stories on them. Some say they are useful, other say they don't use them and rather trouble shoot in real time. I would just like to have your opinion on this
thanks
ken

In my case, real programming example...(as opposed to a fake one? :) )
Multiple channel software based PWM for lighting along with serial port control. Almost impossible to do with just a loop and keep all the light intensities the same, nevermind trying to read the serial port while you're controlling all the lights.

So, enter the lowly 'interrupt'...

The timer fires an interrupt and I update the outputs according to the PWM counter and duty cycle registers...

The serial port fires an interrupt telling me that I've received a byte across the serial port. If I didn't use an interrupt and had been processing a few lines for controlling the lights, I might've missed that byte. With the interrupt, I can save it in a buffer and act on it when I'm ready.

And the whole time, my main loop is executing (except when I'm in the interrupt routine, which is 'in and out' as fast as possible), I'm updating duty cycle registers according to the latest data received over the serial port, I'm checking push buttons, keeping tabs on power, sending a few bytes back out the serial port, whatever.

Another simple example...If you didn't have interrupts on your PC, the clock wouldn't get updated along with a million other things.
For example, you might be playing a flight simulator and the CPU was busy doing some calculations for the aircraft in flight, you hit the button for flaps, but the program was busy crunching numbers and missed the button push...because it doesn't have interrupts. But, since a PC does have interrupts, the program was able to jump away from the main loop for a split second, save the keypress in a buffer somewhere, and go back to the main loop (but you don't notice because the interrupt subroutine is just long enough to do what it has to do). Then when the program got finished crunching a few numbers, it checked the buffer that holds keypresses, and found the keypress for the flaps...now your flaps are down (or up...whatever).

mister_e
- 11th May 2007, 23:11
i think the problem is back of the keyboard or a total misunderstanding of them rather than else.

Yes they are usefull, but every project are different. Hard to say, when you need, and when you don't.

TIMER interrupt is soooo useful to me. PushButton scan, Debounce, TRIS refresh, USBSERVICE, etc etc

therian
- 13th May 2007, 20:49
How can I learn about interrupts ?

mister_e
- 13th May 2007, 22:12
well, i don't want to sounds like a broken record, but Doing a Forum search with interrupt as keyword will lead you to several thread.

Datasheet will show you all interrupt source for your PIC (timer, USART, MSSP, interrupt on PORTB change, INT0, INT1 etc etc )