Pages: [1]   Go Down
Author Topic: attachInterrupt  (Read 697 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 9
Posts: 79
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a 2.8v pulse (1us width) every second on pin 7 (I can see it on scope) and Maple and Uno version work, but
I get no hits in the interrupt handler on the DUE with the following sketch.  What am I missing?

Code:
// gpspps

volatile unsigned long us;
volatile int tick=0;

void handler() {
us = micros();
tick=1;
}

void setup() {
Serial.begin(9600);
attachInterrupt(7,handler,RISING);
}

void loop() {
    static unsigned long prev = 0;
    unsigned long t;
    char str[32];
if (tick)  {
            t= us-prev;
            sprintf(str,"%ld us  %ld ppm",t,t-1000000);
Serial.println(str);
tick=0;
            prev=us;
}
}
Logged

Offline Offline
Jr. Member
**
Karma: 9
Posts: 79
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Never mind, problem was with IDE 1.5, works with IDE 1.5.1 (though it didn't like my hardware/ folder).
So sketch is working now, and I can use EM-406A GPS pps to measure frequency of DUE clock/crystal and get measurements consistent with using an NTP host as frequency reference. The Sparkfun EM-406A operates at 5v, but specs and scope show TX and pps are at 2.8v so no level conversion needed.  Frequency results and various sketches at
  https://github.com/manitou48/crystals
Logged

St. Petersburg, FL
Offline Offline
Jr. Member
**
Karma: 1
Posts: 61
Retired physicist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Pin 7 is not an interrupt pin. The first item in the attachInterrupt() call is an interrupt number and not a pin number. See the linked image for details. You may also need to set the interrupt pin as an input.

http://arduino.cc/forum/index.php?topic=128464.0
Logged

St. Petersburg, FL
Offline Offline
Jr. Member
**
Karma: 1
Posts: 61
Retired physicist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Oops, I see that the Due has different options for the first argument and any pin can be an interrupt.

Logged

Pages: [1]   Go Up
Jump to: