Pages: [1]   Go Down
Author Topic: Interrupts.  (Read 617 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 129
Posts: 8606
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: April 24, 2011, 10:10:28 am by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 129
Posts: 8606
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: April 24, 2011, 07:51:59 am by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 644
Posts: 50524
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26538
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 129
Posts: 8606
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


« Last Edit: April 24, 2011, 08:08:28 pm by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

Pages: [1]   Go Up
Jump to: