interrupt question

Status
Not open for further replies.

clarkcbrawley

New member
Trying to test the attach interrupt function in the ArduinoIDE and on teensy3. This compiles and loads with the teensyduino beta6. I have a wire between 13 and 0 and I get no pulses counted in the ISR. The loop counts and runs, I see the pulse_train going 1 and 0 and the led is flashing. I assume I am doing something wrong. I use similar code in a breadboard with a Mega and count pulses from a pump and it works flawlessly. I am investigating moving this to a Teensy3 and wanted to investigate this function. I assume I am doing something wrong. Why do I get no ISR service?.
 
as forum rule at top states: Always post complete source code & details to reproduce any issue!
(use CODE tags (#) when posting code to retain indentation)

teensy3 pin interrupts are numbered by pin number like Arduino DUE
https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/

here is a simple example using PWM to pulse pin 10 which is jumpered to pin 0
Code:
volatile uint32_t ticks;

void isr() {
  ticks++;
}

void setup() {
  analogWrite(10, 127);   // PWM pulse pin 10 jumpered to pin 0
  attachInterrupt(0, isr, CHANGE); // interrupt on change
  Serial.begin(9600);
}

void loop() {
  Serial.println(ticks);
  delay(1000);
}
 
The Teensy 3.x's pins default to "disabled" instead of "input" unlike the AVR chips in the (Arduino UNO, Mega).
In SETUP() add: pinMode(0, INPUT);
 
my code (resumen)
Code:
const uint8_t pinHall = 23;   <---- pin 23 input external signal.
volatile bool hallState=false;

void setup() {
Serial.begin(921600);
hallState = 0;
pinMode(pinHall, INPUT_PULLDOWN);
attachInterrupt(digitalPinToInterrupt(pinHall), hallRising, FALLING);
}

void loop(){

while (!hallState)
     {
      Serial.print("Rising!!!\n");
      hallState = false;
      };
};


void hallRising() {
	hallState = true;
};

Good Luck!
 
Status
Not open for further replies.
Back
Top