PDA

View Full Version : Help with Interrupts



Aussie Barry
- 25th January 2011, 14:38
Can anyone recommend a good tutorial on interrupts - what they are, how they work, how they can be implemented etc?

I have been reading a whole host of old posts recently and the subject comes up time and time again. I am keen to try DT's Instant Interrputs but I need to find out what they can do (and why) before I start.

Any assistance would be greatly appreciated.

Cheers
Barry

mackrackit
- 25th January 2011, 18:50
Probably the best read right now would be in the back of the PBP manual.

In general, interrupts are a way to give the appearance of doing more than one thing at a time. Any CPU can only do one thing at a time, even the PC on your desk. But there are times when the cpu is idle, say between key strokes, that time can be used to do something else like send more data to a printer. We do not notice all this happening these days but if you go back 20 years or so you will know what I am getting at. If a process has a high priority it can actually stop, "INTERRUPT", other processes to do a task.

The same applies for micro cpus. A timer running to cause something to happen at a given interval or an event on a pin are a couple of cases where interrupts are commonly used here.

The are two types of interrupts we can use with PBP.

The first being ON INTERRUPT.
ON INTERRUPT is a pseudo interrupt. If an interrupt is triggered it will not be acted on until the next instruction in the code is finished. In many cases this type of interrupt is "OK".

The second type of interrupt is an ASM type.
ASM interrupts are true interrupts. They will be acted on no matter what. An example would be a pause of on second. ON INTERRUPT will wait for the PAUSE command to finish while the ASM type will be acted on immediately. The problem with the ASM type is in the setup. You have to save the current state of all registers before acting on the interrupt and restore the registers when finished. Sounds like a big task but it is not that bad.

There are examples for each of the above in the manual.

Now comes the Cadillac of interrupts.. DT's Instant Interrupts.
Easy to setup, ASM or PBP types and the interrupt created is a TRUE interrupt.

I recommend starting with ON INTERRUPT then the ASM type before using DT's Interrupts. I think this give one a better understanding of how they work and when one can be used over the other. Then when you do use DT's Interrupts you will be able to get the results you expect.

Start off by making an LED blink by using an interrupt for practice.