11 years, 4 months ago.

Why don't multiple InterruptIn's work?

Hi!

I'm counting rising edges from mbed pin 5, 11, 27, 28, 29 and 30. I'm using InterruptIn to trigger interrupts whenever there is a rising edge at any pin. However, it only works for pin 27 and 28, and not the rest (even though they are all initialized similarly). Could someone please explain to me why this is so?

2 Answers

11 years, 4 months ago.

Posting your code either by copying it and pasting it here between code tags, or publishing it, is really handy to get help so we can see what you are using, and also try it ourselves.

Anyway which version of the mbed library are you using? Few days ago a new version was published which should fix bugs regarding InterruptIn. When in doubt: If you made it today/yesterday, you got the latest version. If longer ago, click on the mbed library in your compiler, click the update button. Then try recompiling it and if it is fixed.

11 years, 4 months ago.

Hi Erik!

Here is my code. Essentially I'm counting rising edges of 4 different waveforms from 4 different input pins to calculate different frequencies. I'm using the latest mbed library. There is no problem with counting frequencies from pin 27 and 28 but not the rest of the pins, which I find it pretty strange when I'm declaring them similarly. Here, frequency input from pin 11 cannot be read.

  1. #include "mbed.h"
  2. #include "EAOLED.h"
  3. #include "TextDisplay.h"
  4. #define count_interval_sec 1

EAOLED oled(p5, p6, p7, p8, p25);

void incr_timer_count(void);

void incr_p27edge_count(void);

void incr_p28edge_count(void);

void incr_p11edge_count(void);

Timeout interval;

InterruptIn p27_edge(p27);

InterruptIn p28_edge(p28);

InterruptIn p11_edge(p11);

DigitalOut led1(LED1);

DigitalOut led4(LED4);

volatile int timer_count = 0;

volatile int running = 1;

volatile int p27_edge_count = 0;

volatile int p28_edge_count = 0;

volatile int p11_edge_count = 0;

volatile int freq = 0;

volatile int freq2 = 0;

volatile int freq3 = 0;

int main() {

led1 = 1;

led4 = 0;

oled.cls();

oled.locate(0,0);

oled.printf("Count cycles");

interval.attach(&incr_timer_count, 2);

while (1) { } }

void incr_timer_count(void) {

led4 = 1 - led4;

timer_count = timer_count + 1;

if(timer_count == count_interval_sec){

p27_edge.rise(NULL);

p28_edge.rise(NULL);

p11_edge.rise(NULL);

timer_count = 0;

freq = p27_edge_count/count_interval_sec;

freq2 = p28_edge_count/count_interval_sec;

freq3 = p11_edge_count/count_interval_sec;

oled.locate(0,0);

oled.printf("P27: %0.7i", p27_edge_count);

oled.locate(0,1);

oled.printf("Frq1:%0.7i", freq);

oled.locate(0,2);

oled.printf("P28: %0.7i", p28_edge_count);

oled.locate(0,3);

oled.printf("Frq2:%0.7i", freq2);

oled.locate(0,4);

oled.printf("P11: %0.7i", p11_edge_count);

oled.locate(0,5);

oled.printf("Frq3:%0.7i", freq3);

p27_edge_count = 0;

p28_edge_count = 0;

p11_edge_count = 0;

freq = 0;

freq2 = 0;

freq3 = 0;

p27_edge.rise(&incr_p27edge_count);

p28_edge.rise(&incr_p28edge_count);

p11_edge.rise(&incr_p11edge_count);

}

interval.attach(&incr_timer_count, 1);

}

void incr_p27edge_count(void){

p27_edge_count = p27_edge_count + 1;

}

void incr_p28edge_count(void){

p28_edge_count = p28_edge_count + 1;

}

void incr_p11edge_count(void){

p11_edge_count = p11_edge_count + 1;

}