Sample code for TPL5010

Does anybody has a test code for such watchdog ic? I am trying it with Arduino but it seems it’s not working well…

Any suggestion or link is appreciated :wink:

There really isn’t so much code. I use the TPL5000, but it’s similar. Connect a GPIO pin to the DONE line. Use pinMode(pin, OUTPUT) in setup. In loop, I usually just flip it to the opposite state each time through using digitalWrite(pin, value).

1 Like

@not103,

I agree with @rickkas7 in that the code can be mammal but I have taught mine a few tricks.

I use a TPL5010 in my outdoor projects. I have uploaded the project details and code here:
Electron for Outdoor Applications
Photon - Smart and Safe Outdoor Watering System - New for 2018

The long and short of it is this:

  • Pick a period that makes sense. Short enough that you reset within a reasonable time, long enough that you can get critical things done and take time to sleep if you are on a battery.
  • Use an interrupt service routine to “pet” the watchdog so it can be services no matter what your code is doing.
  • Don’t use blocking code like delay() unless it is very short
  • In the ISR, I add a petting enabled logic. That means that I can disable petting the watchdog if I am doing something important. For example, when I am watering using the AquaMaster, I disable petting to reduce the chance that the device will lock up with the water turned on. For this to work, the watchdog interval needs to be slightly longer than the longest watering period. I also need to make sure I pet the watchdog manually just before turning on the water to ensure the timing is right.

Hope this helps,

Chip

Basically my code take a measurement every 10 minutes at 0-10-20-30-40-50 during day and every hour during night.
I would like to set the watchdog at 1-1.5 hours and to keep all minimal I like also the idea to simply change the state of the done pin at every loop, Ignoring the wake pin.

The purpose is to reset the board if for some reason (it happens) the Electron stop works.

Does it make sense?

@not103,

Sure, if you are OK with the possibility of a 1-1.5 hour lockup, this is the simplest method. In fact, you might simply look at the Application Watchdog which is part of the ARM processor as adding a separate timer may be overkill for you.

Chip

It seems for some reason the application watchdog is not enough, it can handle most of connection problems but there is something wrong that put the device in sleep forever… (or it seems it’s in such state).

I’ve found a strange coincidence of this problem and thunderstorm.

Only a manual reset or cold start resolve this state, for this reason I would try the external watchdog.

Another question, what would be the best way to power the TPL5010?

  1. direct from battery
  2. from 3V3 pin on Electron
  3. from VIN pin on Electron
  4. fromVBAT pin on Electron

assuming I’m using SLEEP_MODE_DEEP

3V3 is fine. It’s powered all the time. 3V3 powered by VIN, USB, or battery. It’s usually the best choice.

Direct from battery (Li+) won’t work if not powered by battery. Also, it will drain the battery when charging from USB or VIN, which is different than 3V3 which bypass the battery when external power is used.

VIN is not great, as it is only powered when you’re powered by USB, not battery, unless you are powering by VIN from an external source.

VBAT is connected to 3V3 with a zero ohm resistor, but you should just use 3V3 instead.

Clear, thanks.

This is my test scheme, is it correct? Because it seems it’s not working.
It run well, publish and after it goes sleep till next hour, with the 22Kohm resistor it should wake it after 1 minute but nothing.

What’s wrong?

You don’t have to put a pull-up on RST, there’s an internal one (but won’t hurt to add both).

However, you should put an external pull down on DONE. If you let it float, I’ve found that the random floating can prevent the watchdog from triggering.

Ok, I was suspecting the resistor on DONE what value? 10Kohm?

10K is what I use.

Do you find that the TPL5000/10 always trigger the watchdog reset on the first tick of the timer?

With mine it always triggers the reset after 64seconds (my time interval), the first time, despite me putting DONE high, after that it performs as expected???

No, I haven’t had any trouble with the TPL5000. I have the DONE pin connected to GPIO D6. There is an external pull-down resistor, 10K.

If I don’t do anything, the TPL5000 resets the Photon after about a minute.

Normally, my firmware pets the watchdog with code like this at the bottom of loop:

watchdogState = !watchdogState;
digitalWrite(watchdogPin, watchdogState);
1 Like

ok thanks. Weird. Oh well it doesn’t matter too much, i just get a reboot first off ,but then all fine.