Pages: [1]   Go Down
Author Topic: Performance  (Read 828 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

While working on a disciplined clock, I decided to check the interrupt response times. I was amazed. With the following code, which does not do a lot of work in either the loop or the interrupt service routine, I was  able to send interrupts at a 10Khz input rate and see the loop run fine. Much superior performance to what I expected. I enjoy this environment.


//works to 20khz interrupt rate and still services the loop

#include <avr/interrupt.h>  
int state = LOW;

void setup()
{
  pinMode(7,OUTPUT);
  pinMode(13,OUTPUT);
  attachInterrupt(0, intin, FALLING);
  Serial.begin(9600);
}

void loop()
{
  delay(200);
  state=!state;
  digitalWrite(13,state);
  Serial.println("through the loop");
}

void intin()
{
  state=!state;      
  digitalWrite(7,state);    //pin 7 toggles at half input frequency

}  
Logged

Australia
Offline Offline
Jr. Member
**
Karma: 0
Posts: 63
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

heh, well the datasheet says it takes 4 clocks to get into the ISR and 4 clocks to get out again. The chip runs at 16MHz. your loop has a delay and a serial.write, both of which take *aaages* compared to a measly couple dozen clocks or so.

In theory, you'd be able to generate frequencies up to almost a megahertz if you hand-tweaked the assembly.

In fact, I've seen projects that directly generated radio frequencies using a PWM output and modulated it from code, then did some gating on the rx side to receive.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

True, but what is so nice, at least to my eyes,  is to be able to achieve this performance with just the Arduino programming environment as it is offered.
Logged

Pages: [1]   Go Up
Jump to: