Using the new Arduino IDE for ESP8266 and found bugs, report them here

Moderator: igrr

User avatar
By Mickbaer
#46242 Thanks Martin,
for your hint: :idea:
void ICACHE_RAM_ATTR pulseCounter()
{
G_pulseCount++; // Increment the pulse Counter
}
This works, to get no more Exceptions,
at the Advanced-ESP_WebServer example,
to count the 240 pulse per second.


This depends on that, at the Loop is only an delay(2), for to shorten the example.

At my original build Programm, there is much more traffic at the LOOP.
( Blinking some leds at some timer, Calculations, Website refresh, reportings to my Homeautomation FHEM...)
So I have now, no exception any more, but the fast pulses, will not be counted.
Only slow pulse < 50 will be counted correctly.

( The pulse at the the Interrupt Pin came to fast, so it is recordniced an impuls Count of ZERO)
Some times when I distorb the System, by to refreshing the Website, it works counting some periodes of counting and than it stops like this:
------------------------ The Pulse from Generator are constant here, 78 pulse / sec ---------------------
WaterSensor pulseCount:24 Milis:280375
MakeHtmlPage duration = 28108, FreeHeap = 28400
MakeHtmlPage duration = 40765, FreeHeap = 28216
WaterSensor pulseCount:39 Milis:281378
MakeHtmlPage duration = 31773, FreeHeap = 28176
WaterSensor pulseCount:79 Milis:282381
MakeHtmlPage duration = 42619, FreeHeap = 28400
MakeHtmlPage duration = 27493, FreeHeap = 28400
WaterSensor pulseCount:98 Milis:283384
WaterSensor pulseCount:73 Milis:284387
WaterSensor pulseCount:73 Milis:285390
WaterSensor pulseCount:67 Milis:286394
Sending SensorUptime
AtwebHandleSensorUptime Uptime=Up:0d0h4m38s
WaterSensor pulseCount:75 Milis:287398
WaterSensor pulseCount:84 Milis:288401
WaterSensor pulseCount:24 Milis:289404
WaterSensor pulseCount:9 Milis:290408
WaterSensor pulseCount:1 Milis:291459
WaterSensor pulseCount:0 Milis:292462
WaterSensor pulseCount:0 Milis:293490
WaterSensor pulseCount:0 Milis:294493
-------------------------
I think this is the same Problem, an other user posted, about the SLOW GPIO, at this Forum.

@Martin, thanks for your quick and good help, :D
but at the end, it did not solve my Impuls Counter Problem at the ESP8266Webserver. :(

Who can help here? :?:

Thanks for any advise,
Mickbaer from Berlin Germany
User avatar
By penatenjoe
#46246 I do count pulses at a rate of about 100/sec and believe not to have your problem. Not sure why. One difference is that I framed every reference to the counter with cli() sei(), e.g.
Code: Select allvolatile unsigned long cnt; // volatile var is stored in RAM (not register) for interrupt handler
void ICACHE_RAM_ATTR rpm() {
  cnt++;
}
float measureflow() {
  cli();
  unsigned long cnt1 = cnt;
  sei();
  // count for 1000 msec
  delay(1000);
  cli();
  unsigned long cnt2 = cnt;
  sei();
  // calculate results
  volume = cnt2 * coeff;
  return (cnt2 - cnt1) * coeff * 60; // l/min
}
void resetflowcounter() {
  cli();
  cnt = 0;
  sei();
  volume = 0;
}

I would be interested to learn if this makes the difference. Otherwise I probably have to find out if I truly count all pulses or not and test high pulse rates.
BTW: I use an older version of the addon package.
User avatar
By martinayotte
#46249 I remember seeing a thread about missing interrupts if the handler was set using FALLING/RISING mode, but was properly working if it is in CHANGE mode. This issue is caused by the fact that FALLING/RISING detection is not done in hardware, but in software in the lower layer where it looks to GPIO input state to determine the edge, so with high frequency, it skip some edges. Maybe not fixed yet, we need to search in github.
But in the mean time, you can try with CHANGE mode and divide the counting number by 2, if it still fit for you application.