1

I have a precision pulse flow meter connected onto pin D4 of my ESP32 and am programming in the Arduino IDE environment. The following libraries are used:

/* Libraries */
// Include WiFi Library
#include <WiFi.h>
#include <HTTPClient.h>
// Include Serial Peripheral Interface library
#include <SPI.h>
// Include WiFi UDP Protocol
#include <WiFiUdp.h>
// Include ESP32 Time Library
#include <ESP32Time.h>
// Include Firebase ESP32 library (this library)
#include <FirebaseESP32.h>
// Provide the token generation process info.
#include <addons/TokenHelper.h>
// Provide the RTDB payload printing info and other helper functions.
#include <addons/RTDBHelper.h>

#include <pwmWrite.h>

I also have 2 Pulse Dosing Pumps connected to pins D2 and D15 respectively.

Currently, I am recording the intervals between pulses or every 10L of "Flow". This is happening through an ISR I have created which involves millis().

For some reason, when I output to (only dosing pump 2, be it a PWM signal or a simple on and off) the output of the dosing pump will trigger the ISR.

This causes the flow meter intervals to change unexpectedly.

I have tried connecting 10k Ohm resistors to the GPIO's of the dosing pumps and ground but to no avail. I am using just the NodeMCU-ESP32 to work this problem and separating my cloud processing on core 1 and operational processing on core 0.

This is due to me trying to remove latency of the system by separating operational processing and cloud processing.

My ISR is as follow:

void IRAM_ATTR inPulse(){
  button_time = millis();
  intervalPulse = button_time - last_button_time;
  if(button_time - last_button_time > 250){
    state = !state;
    prevTrail = HIGH;
    pulseDetect = 1;
    last_button_time = button_time;
    dailyFlow = dailyFlow + fMLPP;
  }
}

The system is designed using a state machine approach, where core 1 is constantly receiving information from Google RTFB and is populating global variables which core 0 will then use.

All dosing pumps and the flow meter share a common ground. It works with just 1 dosing pump alone but as soon as I connect the second pump (only the second pump) it will start triggering the ISR. Could it be that there is reflections when the output signal from the ESP gets sent to the one dosing pump causing some sort of EMI ?

Any advice or knowledge as to why this may be happening will help so much. Thanks a lot in advance!

Gamme40
  • 33
  • 6
  • 4
    Since your software seems to be quite complex, I would ignore it as a first step to make sure that the hardware and interrupts work as expected. For this I would write a little experimental program that simply toggles some pin, one for each interrupt. With an oscilloscope I would check the input and output signals. Only if this part works, I would proceed and debug the software, if it still shows erroneous behavior. – the busybee Aug 23 '22 at 07:14
  • @thebusybee I have solutioned a temporary workaround that doesn't involve using ISR's. This method is doing a digitalRead on the pin which the flow meter is connected to and is working with millis() to give me a similar result. I've figured that it is definitely something to do with the Interrupt Method due to the error only being present when using the Interrupts. The solution i have currently runs in the loop continuously however and it is not viable going forward for the long term, which is why I really would like to ask the community if there is any advice regarding the problem i have... – Gamme40 Aug 23 '22 at 11:53
  • 1
    OK. Since it is advisable to check things from start to finish, I would make sure that the hardware is OK, that my interrupts are OK, and only then to proceed. -- Anyway, do you share variables between interrupt functions and other "threads"? If so, did you mark them `volatile`, as it is necessary? Additionally, did you check that you have no race conditions? -- Multithreading, which includes interrupts in my view, is a difficult thing, and it is often done wrong. – the busybee Aug 23 '22 at 11:57
  • The solution not using ISRs is bound to be less sensitive. If you are polling instead of using interrupts then in all likely hood the the interference generated that might be getting to your input pin will not be present when you are polling the pin since the processor is doing only one thing at a time. So perhaps one instruction turns on the pump causing a spike of a few nanoseconds then a few microseconds you poll the input but by then the spike is no longer there. If you use an interrupt the spike will be captured any time it is generated. – Christian Aug 23 '22 at 19:22

0 Answers0