Question about interrupts

Hi, I plan to make a opto encoder and I want to know if an input signal in the io pins (rising edge or falling edge) internally trigger an interrupt? There are documantation about low level operation and other topics like this?
Thanks for this great app, it’s a bit like microflo but much more light.

Hello!

There is no functionality that lets to deal with interrupts yet. It is in plans but not yet implemented.

The idea is to have a low-level general purpose node that watches for a particular INT and provides outputs:

  • How many times the interrupt triggered because of rising/falling signal
  • What’s the timestamp of the last triggered interrupt

Then all other things like encoder driver node could be based on such node.

Thank you for the feedback.

Great! I think With this node and a loop suport, xod will be usable in the real world soon!

Off topic:
Please, It’s a great app, don’t turn it in another kid toy, the educative apps are very important but I think the FBP in general and xod in particular have a big professional potencial for speedup the embedded programming.

1 Like

We are trying. It’s quite hard to keep a balance, but we seek design decisions carefully so that they don’t restrict advanced applications and at the same time are accessible for a child (teenager).

1 Like

Any updates on implementing an interrupt node? It doesn’t sound that difficult.

I’m migrating a project from Arduino IDE… so far so good.
My Pro Mini is battery-powered and sleeps the whole time, except when PIR-input triggers interrupt wake:

#include <JeeLib.h>
ISR(WDT_vect) {
  Sleepy::watchdogEvent();
}

void setup() {
    attachInterrupt(digitalPinToInterrupt(PIR_PIN), Interrupt, CHANGE);
}

void loop() {
  if (not Motion and not MotionEnded)
    Sleepy::powerDown();
  else 
    ...
}

How can I currently hardcode the code above into XOD?

Hello!

No changes yet. It’s not on the top of the backlog, unfortunatelly. Meanwhile, I can think you can try to make a C++ node which has inputs:

  • PORT — awake the program when changed
  • SLP — pulse to sleep

The code would be roughly:

void evaluate(Context ctx) {
  if (isInputDirty<input_SLP>(ctx)) {
    // ... power down ...
  }

  auto port = getValue<input_PORT>(ctx);
  attachInterrupt(digitalPinToInterrupt(port), loop, CHANGE);
}

With some level of hacking I’m pretty sure you can make it work.

2 Likes

Just wondering if there are any nodes or examples of using interrupts? Thx

I don’t think many people have been working with interrupts in XOD. There is nothing in libraries or documentation pages. There have been several discussions in this forum, so searching the forum is probably your best bet. Unfortunately, I don’t know if that will give you any answers or just show who else was interested in using interrupts…

The only example I know of off hand is the delay node uses an alarm interrupt.

The following example code was posted in March 2019 regarding how an interrupt node could look like by nkrkv

quote…

There’s no interrupt management built in XOD C++ runtime (yet). A quick solution one could try is the following (very rough draft, unchecked):

volatile uint8_t interruptCount = 0;

void myISR() {
  // Record we have had an interrupt
  ++interruptCount;
}

void evaluate(Context ctx) {
    if (isSettingUp()) {
        // Register handler once
        auto pin = getValue<input_PORT>(ctx);
        attachInterrupt(digitalPinToInterrupt(pin), myISR, RISING);
    }

    if (interruptCount) {
        // Process a single interrupt
        --interruptCount;
        emitValue<output_OUT>(ctx, 1);
    }

    // Come back on next transaction
    setTimeout(ctx, 0);
}

I tried to make an node based on this but failed as I know little about code etc.

Can anyone help to make an interrupt node based on the above?
Thanks