Go Down

Topic: Interrupts. (Read 659 times) previous topic - next topic

Hi. I'm wonder if I can attach function on Serial external interrupts. I mean, can I receive data from serial on external interrupt? i don't want to use loops to check data.

Graynomad

#1
Apr 24, 2011, 01:42 pm Last Edit: Apr 24, 2011, 05:10 pm by Graynomad Reason: 1
The serial funcs are already interrupt-driven.

Quote
i don't want to use loops to check data.

Maybe you should tell us why, because otherwise you'll have to write a custom buffering function which is almost certainly more trouble than it's worth.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Ok, i'll try to explain. In my opinion loops is that thing which loads our chip and it always works. In this case, when I push a lot of code in VOID LOOP(), it will decrease perfomance. And I thought, that interrupts is the best way to receive data from COM, because it will be easily to watch and catch needed data and no need to check data cyclically. I just listen to interrupts and perform needed functions.

It intereseted me, because the syntax of code in Arduino is different, for example, from CodeVision AVR. And this language writting hides from us more importnat things.

Graynomad

#3
Apr 24, 2011, 02:43 pm Last Edit: Apr 24, 2011, 02:51 pm by Graynomad Reason: 1
Quote
In this case, when I push a lot of code in VOID LOOP(), it will decrease perfomance.

But what else will the processor be doing if not looping? If it's not sleeping or crashed it's looping somewhere.

Quote
And I thought, that interrupts is the best way to receive data from COM,

In the Arduino environment serial characters are already received using interrupts. The fact that you can write

if (Serial.available() > 3)

means that characters have been received in the background. And while it is possible to write code specific to an application that is more efficient that would require a reasonable amount of programming skill.

Interrupts can make code easier but for novice programmer they are also a source of much trouble, also technically interrupts are LESS efficient than polling as the overhead for an interrupt is quite high.

So in general I would say that interrupts are not worth it, but if you have a specific example maybe.


______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

PaulS

Quote
also technically interrupts are LESS efficient than polling as the overhead for an interrupt is quite high.

Don't forget that interrupt handlers must be very fast, since the interrupt handler might itself by interrupted. It's best to be done before that can happen.

AWOL

Quote
technically interrupts are LESS efficient than polling as the overhead for an interrupt is quite high.

That's an...interesting point of view.

I suppose it depends on your personal definition of "efficient".
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Graynomad

#6
Apr 25, 2011, 02:28 am Last Edit: Apr 25, 2011, 03:08 am by Graynomad Reason: 1
Quote
I suppose it depends on your personal definition of "efficient".

That's true.

I should qualify by saying I'm referring to response time and "wasted" time in general. An interrupt will consume maybe up to 100-odd clock cycles to save and restore the processor context, a poll can respond in a couple of cycles.

So maybe "efficient" isn't the correct term, but depending on the program flow 2-3 cycles used every loop may be less wasteful than 100 used every interrupt, for example when receiving characters at high speed you can spend most of you time in the ISR pre and post ambles.

Having said that I use interrupts of one kind or another for just about everything, they can certainly clean up the program logic and solve many spaghetti code issues.

______
Rob


Rob Gray aka the GRAYnomad www.robgray.com

Go Up