Pulse Counter stops working until reboot

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
boarder87
New user
Posts: 8
Joined: 28 Sep 2021, 14:47

Pulse Counter stops working until reboot

#1 Post by boarder87 » 28 Sep 2021, 15:23

Hi,

I had a ESP8266 running for 2 months with the pulse counter without any issues to measure the energy usage via TCRT5000 on a ferraris meter. (GPIO13, pulse low, 100ms debounce, MQTT each 60sek, total and time)
Now I've extented the ESP with a reed contakt to measure gas usage on GPIO14 (input_pullup, pulse high, debounce 100ms, MQTT 60s, total), which work also fine. But after a few hours properly working, one of the counters stops working and do not count any pulses. After warm rebooting, again both counters work again a few hours.
  • I've already changed the GPIOs without any sucess.
  • I've flashed the latest ESP_Easy_mega_20210802_normal_ESP8266_4M1M clean without importing any "old" config
  • I've rebooted and unpluged the power supply a hundred times
  • I've checked and tried to understand the logs and here I noticed a really strange behaviour.
When the counter stops working I also do not receive any stats, even if i unplug the sensor and connect alternating 3.3V and GND with the GPIO which should definetivly trigger the counter.
Also I add a new task with a "input switch" on the same GPIO to read the status directly in ESP Easy. The logging is showing the change in high and low signal but the counter doesn't count or write something in the log.
After reboot and starting the log, all is working as expected but I've found out what caused this counter interruption.

Any help even just for a detailed debugging is much appreciated.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Pulse Counter stops working until reboot

#2 Post by TD-er » 28 Sep 2021, 15:30

How is the reed sensor electrically connected?
Only the internal pull-up? Or is there an external pull-up resistor present too?

Does the ESP still respond to network activity when it gets stuck?

How long is the cable from the reed sensor to the ESP?
If this happens, can you measure the voltage on the ESP side? What if the reed sensor gets stuck somehow?

boarder87
New user
Posts: 8
Joined: 28 Sep 2021, 14:47

Re: Pulse Counter stops working until reboot

#3 Post by boarder87 » 28 Sep 2021, 15:54

At the moment I just use the internal pullup resistance. The Reed sensor is connected between GND and the GPIO14 with a 6m long shielded telefon cable (JY(ST)Y 2x2x0,6 mm²). The cable runs approximately 1m parallel to many power lines, because the ESP8266 is located in the main electrical distribution board.The ESP still reponds to network activity as usual and I have access to it via web browser to see the updating log entries.
Voltage between GND and GPIO14 is 4.1V, which is obviously higher than the 3.3V, but as i already wrote, the ESP still reads the Input signal correctly, even after the counter has interrupted. Therefore I thought it's more a software than a wiring issue.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Pulse Counter stops working until reboot

#4 Post by TD-er » 28 Sep 2021, 16:54

How can the voltage be higher than the 3v3 you supply to it?
Also running such a long wire may pick up a lot of noise and maybe it even acts as a capacitor.
So I suggest to use a lower resistance pull-up resistor, as the internal pull-up is quite weak.
For example use a 10k or 4k7 resistor to start with.
That's already a factor 50 - 100 lower resistance.

boarder87
New user
Posts: 8
Joined: 28 Sep 2021, 14:47

Re: Pulse Counter stops working until reboot

#5 Post by boarder87 » 28 Sep 2021, 18:38

I will try using a 4,7k pullup resistor. But I can't really understand why and how this could affect the counter issues. At the moment mostly this channel is still working while the input from the tcrt5000 stops working.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Pulse Counter stops working until reboot

#6 Post by TD-er » 28 Sep 2021, 22:15

If the wires start acting as a capacitor, then the combination of the capacitor and resistor determine the time needed to change the voltage.
This is proportional to R times C (RC).
So a lower R does take less time to charge the capacitor.

Also the voltage you measure is above the 3V3, which is rather strange.
By lowering the pull-up resistor, you may be able to keep this voltage a bit more in line of the 3v3 you'd expect.

boarder87
New user
Posts: 8
Joined: 28 Sep 2021, 14:47

Re: Pulse Counter stops working until reboot

#7 Post by boarder87 » 30 Sep 2021, 09:02

Now I added a 4,7k resistor between 3V3 and the Input. Now i can measure 3,3V as expected.
But this night after 6 hours the counter 1 has stopped, while counter 2 is still running (counter 2 is the input with the new pullup resistor)
On both inputs i can see a regular signal switching between 0 and 1, but just the counter 2 also show the pulse stats in the log.

Must be something to do with the wire, I've unplugged the long wire for counter 2 for 24h and all works again. Plugged the long wire again on the ESP, after a few hours same issue as before. Even that the reed has not closed the circuit oncxe in the meantime, because gas is just use 1 or two tomes a day.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Pulse Counter stops working until reboot

#8 Post by TD-er » 30 Sep 2021, 09:16

Sounds like the long wire is acting as a capacitor and getting charged over time.
If the reed switch then is closed only for a short period, this "capactor" cannot discharge far enough to get the voltage level (on the ESP side, not the Reed switch side) down far enough to be detected as a low level by the ESP.

boarder87
New user
Posts: 8
Joined: 28 Sep 2021, 14:47

Re: Pulse Counter stops working until reboot

#9 Post by boarder87 » 30 Sep 2021, 09:31

Would a resistor parallel to the reed prevents a "charge" of the wire? Must be of course higher than the pullup to have a high signal while reed is open.

I still struggling with my mind, why one channel could affect the behaviour of another one. I would understand if the signal level is not fast enough switching between high and low but how is this influencing another Input pin and cause there a "crash" with the counter?

Even If i unplug both sensors after a "crash" and use just a jumper cable, it won't work until a warm reboot. Somehow I can't get rid of the feeling that something is being triggered on the software side that causes the meter to be interrupted.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Pulse Counter stops working until reboot

#10 Post by TD-er » 30 Sep 2021, 09:37

That I also can't yet explain.
I know the ESP does have some diodes inside to protect the chip/GPIO against higher than 3v3 voltages.
However that should not affect other pins... I think

boarder87
New user
Posts: 8
Joined: 28 Sep 2021, 14:47

Re: Pulse Counter stops working until reboot

#11 Post by boarder87 » 30 Sep 2021, 13:06

Thank you very much, your help is much appreciated.
Is there any idea how to debug in more detail than LogPulseStatistic,i? might be too see if there is some timeout or whatever?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Pulse Counter stops working until reboot

#12 Post by TD-er » 30 Sep 2021, 19:52

You could try to use a short wire, with a reed sensor.
If that causes these issues too, then we can exclude the capacitance theory.

boarder87
New user
Posts: 8
Joined: 28 Sep 2021, 14:47

Re: Pulse Counter stops working until reboot

#13 Post by boarder87 » 01 Oct 2021, 11:04

I've spent yesterday the whole night to play around and tried to force this issue.
Therefore i've used just short jumper cables and after counting some pulses on counter1, then counter2, again on counter1 --> issue on counter 1
I've switched the GPIOs on the counter, still having issues with the counter 1
Also addding a dummy task 1, and put the counter on task 2 and 3. Same issue with the first counter.

After a while I went back to my couch, plugged the ESP with another USC cable on the usb port of my notebook and everything works fine at the beginning. After a while i had noticed the same issue. Tried to change cables and power supply, tried not to touch anything on the ESP, used the resistor as pull-up and pulldown, but at the end i could force it in any configuration that everytime the first counter crashes, but the input still showing a digital input reading of 1 and 0.
Must be something happen, that the counter loop is getting blocked.

I also had a look in the source on github to find any kind of "wait for" or interruption and i found something in the comments, but i haven't understood what could cause this flag.

Code: Select all

 
  // allow next pulse check call from interrupt
  ISRdata.processingFlags = false;
 
 ....
 
 
 // processing for new PULSE mode types
  {
    #ifdef PULSE_STATISTIC
    self->ISRdata.Step0counter++;
    #endif // PULSE_STATISTIC

    // check if processing is allowed (not blocked) for this task (taskID)
    if (!self->ISRdata.processingFlags)
    {
      // initiate processing
      self->ISRdata.processingFlags  = true; // block further initiations as long as async processing is taking place
      self->ISRdata.initStepsFlags   = true; // PLUGIN_FIFTY_PER_SECOND is polling for this flag set
      self->ISRdata.triggerTimestamp = getMicros64();
    }
Because always one pulse counter with mode pulse low is always running, now I try to set the second counter with the edge mode falling or rising. Both counters still counting since a half a day, but with some unexpected single counts every half hour, which is not caused by the reed switch.

boarder87
New user
Posts: 8
Joined: 28 Sep 2021, 14:47

Re: Pulse Counter stops working until reboot

#14 Post by boarder87 » 12 Oct 2021, 21:26

With one counter with pulse mode and one with edge mode, everything works fine and keeps counting, except that I noticed some ghostcounts. Switching back to two pulse mode counters, caused again a crash on on of those counters.

Really strange. Might be to much stress for the 8266 :lol:

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 32 guests