Hello,
I have tested :
- Marshall interrupt
- Event based interrupt "V1", like this
https://github.com/davetcc/TaskManagerIO/blob/master/examples/eventHandling/eventHandling.ino
- Event based interrupt "V2", like this
https://www.thecoderscorner.com/products/arduino-libraries/taskmanager-io/using-interrupt-threaded-events-taskmanager/ (-> please modify "overrride" to "override")
-> ยง Simple example of event triggering from interrupt
The two methods brings me to miss count. (for information count frequency is about 70 hz, wired with a pull up resistance on a ESP32 pin 5)
The factor of missed count depends on some tasks periods:
I have 2 periodics task, one task of 1s, an other of 200ms. 2/3 counts are missed by the event interrupt task with this settings.
If i put my sencond task 200ms-> 1s, 1/2 counts are missed.
Counter is declared like this : volatile int PulsecountTot = 0;
This counter is incremented by the the class.
extract of my code :
class InterruptEvent : public BaseEvent {
public:
InterruptEvent(pintype_t pin) {
pinMode(pin, INPUT);
::attachInterrupt(digitalPinToInterrupt(pin), interruptHandler, RISING);
}
~InterruptEvent() override = default;
uint32_t timeOfNextCheck() override {
return secondsToMicros(300);
}
void exec() override {
// do the work here when triggered.
#ifdef DEBUG_DEBIT
Serial.print("Interrupt triggered : ");
#endif
PulsecountInst++; //Every time this function is called, increment "count" by 1
PulsecountTot++; //Every time this function is called, increment "count" by 1
#ifdef DEBUG_DEBIT
Serial.println(PulsecountTot);
#endif
}
};
InterruptEvent interruptEvent(FLOW_PIN_DEBIT);
ISR_ATTR void interruptHandler() {
// here we now mark the event as triggered.
interruptEvent.markTriggeredAndNotify();
}
An other question, when you say : " Attach a raw interrupt handler that was of type CHANGE:", in my case my need is to count RISING EDGE of the pulse, not RISING EDGE + FALLING EDGE. With CHANGE, that double the counter.
I'm searching a solution for this problem for about 12 hours...
Problem confirmed with an oscilloscope.
Thanks