<div dir="ltr">John,<div><br></div><div>I've been down this road.  Watch for the potholes.  Ticker Tasks are interrupt like (no matter what you might read). Tasks are not guaranteed to be re-entrant safe and you must feed the dogs if you dwell in the routine.  Use single bit flags to avoid code collisions.</div><div><br></div><div>Get the job done quickly and return.  If a second instance fires off, then chances are good stack space will be exhausted.  (Because if the first call didn't finish and the second call is just starting, chances requests are firing too frequently to ensure a timely completion.)  There are some tactics depending on use case.  When you enter your service code, disable Tickers and Interrupts to prevent re-entry, then enable them on exit.  In this state you can hang out until the Software or Hardware Watchdog timeout.  When a watchdog fires, the exception report will have something like <b>rst cause:4</b> or <b>rst cause:2</b> to indicate the Hardware or Software watchdog caused reset.  You can work around that by disabling Tickers, Interrupts and feeding the dogs.  You could also disable to dogs, but I really don't recommend it.  That can cause a lock with no way out.  Use care when feeding the dogs by hand.</div><div><br></div><div>Because we have no idea where we are in code when one of these fires, modifying variables and allocating memory are frowned upon.  You could be processing a variable character by character in your main code and write over the whole thing from the Ticker Task creating an unknown state.  They reason bits flags are recommends is they compile to a single offensive instruction.  Worst case your Task sets the flag while the main code is still processing the previous request.  That can be detected and handled if it becomes an issue.  I use something like this:</div><div><br></div><div><font face="monospace" size="1">Main loop {</font></div><div><font face="monospace" size="1">  if flag_double_dip {<br></font></div><div><font face="monospace" size="1">    // log an error so we know we are calling mainline service code too quickly</font></div><div><font face="monospace" size="1">  }</font></div><div><font face="monospace" size="1">  if flag_doet {</font></div><div><font face="monospace" size="1">    // reset the flag FIRST so the Ticker Task can set it again if needed</font></div><div><font face="monospace" size="1">    clear flag_doet</font></div><div><font face="monospace" size="1">    do some stuff</font></div><div><font face="monospace" size="1">  }</font></div><div><font face="monospace" size="1">}</font></div><div><font face="monospace" size="1"><br></font></div><div><font face="monospace" size="1">Task_callback {</font></div><div><font face="monospace" size="1">  if flag_doet {</font></div><div><font face="monospace" size="1">    // Houston we have a problem, set an error flag</font></div><div><font face="monospace" size="1">    set flag_double_dip</font></div><div><font face="monospace" size="1">  }</font></div><div><font face="monospace" size="1">  set flag_doet</font></div><div><font face="monospace" size="1">}</font></div><div><font face="monospace" size="1"><br></font></div><div><font face="monospace" size="1">Alternate_task_callback{</font></div><div><font face="monospace" size="1">  //disable Ticker and IRQ</font></div><div><font face="monospace" size="1">  //do the things</font></div><div><font face="monospace" size="1">  //feed the dogs</font></div><div><font face="monospace" size="1">  //do more things</font></div><div><font face="monospace" size="1">  //feed the dogs</font></div><div><font face="monospace" size="1">  //enableTicker and IRQ</font></div><div><font face="monospace" size="1">}</font></div><div><br></div><div><div>Another way you can handle this is to run up to your delay but instead of a delay, schedule another Ticker Task and carry on code from there.  Best of luck!</div><div><br></div><div>Mike</div><div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jan 26, 2021 at 12:23 PM John Vaughters via TriEmbed <<a href="mailto:triembed@triembed.org">triembed@triembed.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
You see that, now you guys are making me dig and I was happy with my solution. `,~)<br>
<br>
ticker lib uses millis() and micro() and not interrupt, but with your obsessed curiosities, now I may have found the real problem. You are not supposed to use delay() in the task. And I did use delay(), so I probably need to change the long task to do a task with set number of ticks at my delay time instead of using the delay. Which is much more responsible programming anyway. This will solve it for sure, now that I know how Ticker works.<br>
<br>
Back to the testing with me. Oh well, in the end you guys are making me better.<br>
<br>
Thanks,<br>
<br>
John Vaughters<br>
<br>
<br>
<br>
<br>
<br>
On Tuesday, January 26, 2021, 11:49:44 AM EST, Carl Nobile <<a href="mailto:carl.nobile@gmail.com" target="_blank">carl.nobile@gmail.com</a>> wrote: <br>
<br>
<br>
<br>
<br>
<br>
I wonder if your code used an interrupt that couldn't handle the 25 ms time period.<br>
~Carl<br>
<br>
On Tue, Jan 26, 2021 at 11:10 AM John Vaughters via TriEmbed <<a href="mailto:triembed@triembed.org" target="_blank">triembed@triembed.org</a>> wrote:<br>
> Pete,<br>
> <br>
> There is a debug port on the board for sure, not sure if it qualifies as JTAG. I've never actually used a debugger on a micro-processor, only on regular desktop/server programming. I never invested the time or money to get that up to speed. I will say it dumps a bunch of hex code to the serial port when it crashes and I did not really look at that either. The reason being that I never ran into a limitation that prevented my pragmatic application results and I'm more interested in the end result than the finer details. I just hack until I get it to work. Same goes for oscilloscopes and electronics, I just use basic concepts and practices and usually get it to work. However, I definitely want to gear up with oscilloscopes and logic analyzers one day. But until I have the time to play, no need in putting out the dough for it to sit on the shelf. This attitude is from experience of too many things sitting on the shelf.<br>
> <br>
> There are two timers on the board, but one is used for wifi. The other one is available, and I might be able to use that with better results, but the Ticker library does magic in the background and appears to act like a simple task scheduler. So in the code it appears you are setting tasks, but behind the scenes I have not investigated what it is actually doing. For sure if you use the single timer you are limited to one task or a tight management of tasks on that timer. I'm not quite sure because I did not go that route, I am just parroting my perception of what I read. So I opted for the code appearance of tasking through the Ticker library to make my code more readable. It seems to work great so far and I am close to being done with my wifi modbus device. The next application will be a very simple wifi serial to tcp converter to be able to use with micro-processors that have no network connections. This will allow modbus over TCP via serial conversion. You get the sense I like modbus? `,~) What I found so far is that the serial to tcp application is already solved and out there in multiple forms, so I just need to pick one and give it a go. <br>
> <br>
> I never really exposed my end applications; it is for my home SCADA system that monitors energy use for the goal of reducing energy while remaining comfortable. Basically, I am trying to use technology to "Stick it to the Man" `,~) Oh and have fun learning along the way. I'm pretty sure on just the electric controls implemented on the hot water heater alone I have saved enough to pay for my electronics. So anything above that is pay dirt. <br>
> <br>
> For Robotics, I am really liking the ESP32 combined with some nano arduinos as specialized processors. Top priority being a weed eater head remote controlled lawnmower to minimize allergen exposure. And for the record that has been on the task list for years and I wouldn't be surprised if it waits years longer, but hey the technology keeps making the idea easier as time flies by.<br>
> <br>
> Dreams are good, jobs are better! `,~)<br>
> <br>
> Bottom line is I am loving the ESP line of products.<br>
> <br>
> John Vaughters<br>
> <br>
> <br>
> <br>
> <br>
> <br>
> <br>
> On Tuesday, January 26, 2021, 10:20:04 AM EST, Pete Soper via TriEmbed <<a href="mailto:triembed@triembed.org" target="_blank">triembed@triembed.org</a>> wrote: <br>
> <br>
> <br>
> <br>
> <br>
> <br>
> Does ESP-12E support JTAG debugging? It might be interesting to figure <br>
> out what the crash is about (maybe there isn't actually a task scheduler <br>
> present and if you don't "yield" back you've violated the API <br>
> contract?). But you've stuck with the pragmatic approach, John. Thanks <br>
> for the tip.<br>
> <br>
> Getting  SparkFun "Micromod" boards with ESP32 and ESP8266 (no idea what <br>
> flavors) and the "All the Pins" carrier board today. But these go on the <br>
> shelf as I wait for the RP2040 Micromod board, and my stack is pushed <br>
> anyway. Particle Land, here I come. :-)<br>
> <br>
> -Pete<br>
> <br>
> On 1/26/21 10:03 AM, John Vaughters via TriEmbed wrote:<br>
>> In my playing around with the ESP-12e's that I have, I found something that may save someone some time. Using the Ticker library to schedule a task, I quickly found out that the task better be quick or it will crash the program. To define quick, my task was maybe 25ms, which was enough to crash the program. To get around this I found on the web a quick tip that made alot of sense. Just use the Ticker task to flip a bool and then have an if statement run the task and reset the bool.<br>
>><br>
>> It's not what I consider a great programming technique, but I consider it a valid workaround on the limitation. And it still beats running the task on every loop cycle.<br>
>><br>
>> I am certainly open to other suggestions, but it works quite well and I will be sticking with it for now.<br>
>><br>
>> John Vaughters<br>
> <br>
>><br>
>> _______________________________________________<br>
>> Triangle, NC Embedded Computing mailing list<br>
>><br>
>> To post message: <a href="mailto:TriEmbed@triembed.org" target="_blank">TriEmbed@triembed.org</a><br>
>> List info: <a href="http://mail.triembed.org/mailman/listinfo/triembed_triembed.org" rel="noreferrer" target="_blank">http://mail.triembed.org/mailman/listinfo/triembed_triembed.org</a><br>
>> TriEmbed web site: <a href="http://TriEmbed.org" rel="noreferrer" target="_blank">http://TriEmbed.org</a><br>
>> To unsubscribe, click link and send a blank message: mailto:<a href="mailto:unsubscribe-TriEmbed@bitser.net" target="_blank">unsubscribe-TriEmbed@bitser.net</a>?subject=unsubscribe<br>
>><br>
> <br>
> _______________________________________________<br>
> Triangle, NC Embedded Computing mailing list<br>
> <br>
> To post message: <a href="mailto:TriEmbed@triembed.org" target="_blank">TriEmbed@triembed.org</a><br>
> List info: <a href="http://mail.triembed.org/mailman/listinfo/triembed_triembed.org" rel="noreferrer" target="_blank">http://mail.triembed.org/mailman/listinfo/triembed_triembed.org</a><br>
> TriEmbed web site: <a href="http://TriEmbed.org" rel="noreferrer" target="_blank">http://TriEmbed.org</a><br>
> To unsubscribe, click link and send a blank message: mailto:<a href="mailto:unsubscribe-TriEmbed@bitser.net" target="_blank">unsubscribe-TriEmbed@bitser.net</a>?subject=unsubscribe<br>
> <br>
> <br>
> <br>
> _______________________________________________<br>
> Triangle, NC Embedded Computing mailing list<br>
> <br>
> To post message: <a href="mailto:TriEmbed@triembed.org" target="_blank">TriEmbed@triembed.org</a><br>
> List info: <a href="http://mail.triembed.org/mailman/listinfo/triembed_triembed.org" rel="noreferrer" target="_blank">http://mail.triembed.org/mailman/listinfo/triembed_triembed.org</a><br>
> TriEmbed web site: <a href="http://TriEmbed.org" rel="noreferrer" target="_blank">http://TriEmbed.org</a><br>
> To unsubscribe, click link and send a blank message: mailto:<a href="mailto:unsubscribe-TriEmbed@bitser.net" target="_blank">unsubscribe-TriEmbed@bitser.net</a>?subject=unsubscribe<br>
> <br>
> <br>
<br>
<br>
-- <br>
-------------------------------------------------------------------------------<br>
Carl J. Nobile (Software Engineer)<br>
<a href="mailto:carl.nobile@gmail.com" target="_blank">carl.nobile@gmail.com</a><br>
-------------------------------------------------------------------------------<br>
<br>
<br>
_______________________________________________<br>
Triangle, NC Embedded Computing mailing list<br>
<br>
To post message: <a href="mailto:TriEmbed@triembed.org" target="_blank">TriEmbed@triembed.org</a><br>
List info: <a href="http://mail.triembed.org/mailman/listinfo/triembed_triembed.org" rel="noreferrer" target="_blank">http://mail.triembed.org/mailman/listinfo/triembed_triembed.org</a><br>
TriEmbed web site: <a href="http://TriEmbed.org" rel="noreferrer" target="_blank">http://TriEmbed.org</a><br>
To unsubscribe, click link and send a blank message: mailto:<a href="mailto:unsubscribe-TriEmbed@bitser.net" target="_blank">unsubscribe-TriEmbed@bitser.net</a>?subject=unsubscribe<br>
<br>
</blockquote></div>