Skip to content

Interrupts setuped with attachInterrupt are very slow. #21

@sweetpi

Description

@sweetpi

Something seems to be wrong with the way how interrupts are handled.

I'm trying to record pulses of length 250-2000 micros. Example sketch:

volatile int lastTime = 0;

void setup()
{                
  Serial.begin(115200);
  attachInterrupt(2, pinChanged, CHANGE);
}

void loop()                     
{
}

void pinChanged()
{
  int time = micros();
  int duration = time - lastTime;
  Serial.print(duration);
  Serial.print("\r\n");
  lastTime = time;
}

But this outputs something like:

76131
3683
76143
3752
76146
3667
76128
3768
76141
3741
76148
3661
76114
3785
76130
3683
...

I exprected numbers around 250-2000. It's stange that its almost all time a longer dealy and then a shorter. I double checked the wiring and the interrupts only occure with connected sensor.

I did the same using nodemcu (using gpio.trig) and got ver accurate timings.

Any ideas what is going wrong here?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions