Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By rudy
#71331
philbowles wrote:Guys - Look at the exception, Look at the actual error. I have already identified a problem:


I'm glad that you identified the problem. But after the change I noted, it never failed. I spent two hours on this. Actually running the sketch and giving it harder tasks. And it worked. What more can I say. The code worked. I could not get it to fail.

EDIT

I forgot to mention. I did delete all the flush crap.
User avatar
By McChubby007
#71332 On the subject of hwCount : I'm not going to say I have a definitive answer, but from my own experience, hwCount access from ISR and non-ISR should be fine in your case (it may not necessarily be 'best practice' but I have no real opinion on that for this reply).
The reason *I think* it's OK, is because your data type (of hwCount) happens to be a natural processor word (I.e. An int) AND there is only one writer - the read or write will be atomic as it will be a single uninterruptible load or store. If the data type were something like a 64-bit integer (long long), or an array/struct etc etc, then a possibility exists for partial loads/stores to be intermixed between what are in essence two threads. The assembler output should confirm this. I would not expect any kind of exception to occur even if the data got corrupted, because in your case it's just a plain old number, not an address calculation etc - you would just see an odd looking value when you printed it.
In addition lastHwCount does not have to be volatile, since it is only used by the non-ISR code (unless I missed it being used elsewhere). But otherwise, yes volatile is a bit of a red-herring as far as the exception is concerned.
Care should also be taken when using "non-int sized architectures" (like an Arduino Uno which has a 8-bits as its natural machine word) as using an int in this case would be in error, and you must use an 8-bit data type (char, or unsigned char) for hwCount. I am fairly certain of what I say here, as I have done a lot of testing with high resolution interrupts writing to shared queues with code common to Uno and esp8266, and I have seen the effects and ensured my code is compliant with what I just wrote above.
User avatar
By rudy
#71333 The way I saw it was (as McChubby007 noted) there was only one writer. So it shouldn't get corrupted. I was less concerned about it being read correctly. (which it seems to be) My main concern was about the program crashing. And after moving the interrupt routine to iram I have not had an occurrence of a crash.

I send it 500 transitions at approximately 4800 Hz (close enough) and I still have working WiFi using udp. It hasn't missed a count. I was surprised about it not missing counts. But the interrupt routine is as it should be, short.

EDIT

I kept bumping up the baud rate for the serial feed I amusing as a signal generator for the pulse count input. Now at 115200 baud and still no lost counts. Its been running for two hours now.
User avatar
By McChubby007
#71336 I had a funny feeling that I had read about issues with isr functions not loaded into ram (I.e. Resident on flash), but it was from a very long time ago. Anyhow, I have now found some of the posts on espressif's forum, which confirms problems can arise...

http://bbs.espressif.com/viewtopic.php?t=150

http://bbs.espressif.com/viewtopic.php? ... t=10#p3975

As a matter of 'process' I always ensure my isr functions are resident in RAM. I hate somewhat arbitrary guidelines but some of this information has only drip fed out of espressif, and there's only so many hours in a day.