devnull
Posts: 65
Joined: Sat Dec 24, 2011 7:46 am

Most reliable method for 500ms watchdog pulse

Mon Sep 23, 2013 1:16 am

I need to send a 500ms watchdog pulse to the GPIO, currently I am doing this from within a node app as it is already running a 500ms interval timer.

But this pulse is not reliable, as when node is busy doing other stuff, the pulses may not happen.

What would be the most reliable way of getting a 500ms pulse ? - should I use python with a loop timer, or bash with sleep or use something like watch to execute a command / script ??

Thanks
> /dev/null 2>&1

User avatar
joan
Posts: 13454
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Most reliable method for 500ms watchdog pulse

Mon Sep 23, 2013 8:23 am

Perhaps a bit of overkill for your needs.

http://abyz.co.uk/rpi/pigpio/cif.html#g ... AddGeneric

Code: Select all

#square.c
#cc -o square square.c -lpigpio -lrt -lpthread

#include <stdio.h>

#include <pigpio.h>

#define LED 4

gpioPulse_t pulse[2]; /* only need two pulses for a square wave */

int main(int argc, char *argv[])
{
   int secs=60, us = 1000000;

   if (argc>1) us   = atoi(argv[1]); /* square wave micros */
   if (argc>2) secs = atoi(argv[2]); /* program run seconds */

   if (us<2) us = 2; /* minimum of 2 micros per pulse */

   if ((secs<1) || (secs>3600)) secs = 3600;

   if (gpioInitialise()<0) return 1;

   gpioSetMode(LED, PI_OUTPUT);

   pulse[0].gpioOn = (1<<LED); /* high */
   pulse[0].gpioOff = 0;
   pulse[0].usDelay = us;

   pulse[1].gpioOn = 0;
   pulse[1].gpioOff = (1<<LED); /* low */
   pulse[1].usDelay = us;

   gpioWaveClear();

   gpioWaveAddGeneric(2, pulse);

   gpioWaveTxStart(PI_WAVE_MODE_REPEAT);

   sleep(secs);

   gpioWaveTxStop();

   gpioTerminate();
}

devnull
Posts: 65
Joined: Sat Dec 24, 2011 7:46 am

Re: Most reliable method for 500ms watchdog pulse

Mon Sep 23, 2013 11:47 am

Thanks so much, but I have zero experience with C, would not know where to start.

You library seems very comprehensive, but as you mention, probably a bit of an overkill for this.

Is there a second best method that would fit within the scope of my knowledge i.e. python, node/js, bash :-)

I don't need extreme accuracy, just a guarantee that no more than 1 or 2 pulses will ever be missed.

Thanks

PeterC
> /dev/null 2>&1

User avatar
joan
Posts: 13454
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Most reliable method for 500ms watchdog pulse

Mon Sep 23, 2013 12:25 pm

I'm sure there are solutions better suited to your needs. Could you clarify the format of the required pulses? e.g. 500,000 micros high, 500,000 micros low repeating, and what latitude there is in the timing.

devnull
Posts: 65
Joined: Sat Dec 24, 2011 7:46 am

Re: Most reliable method for 500ms watchdog pulse

Mon Sep 23, 2013 12:36 pm

Thanks, I have a microcontroller monitoring this watchdog, the pulse width is not so critical.

Each rising edge of the PI's GPIO resets an interrupt timer on the microcontroller, if the timer exceeds several seconds then the micro assumes that the PI is either down or is not responding.

So the pulse width is really not so critical, but what is important is the frequency which is currently set to 5 seconds which allows several missing pulses created by NODE when the CPU is busy doing other things, but I would really like to reduce this to a maximum of 1 or 2 seconds.
> /dev/null 2>&1

devnull
Posts: 65
Joined: Sat Dec 24, 2011 7:46 am

Re: Most reliable method for 500ms watchdog pulse

Tue Sep 24, 2013 9:33 am

Hi Joan;

Do you have any alternative solutions based on the criteria above ?

Thanks

PeterC
> /dev/null 2>&1

User avatar
joan
Posts: 13454
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Most reliable method for 500ms watchdog pulse

Tue Sep 24, 2013 10:04 am

I was wondering about your requirements again.

You want to implement a watchdog which triggers when your Pi software application, or the Pi itself fails.

So you need to pulse an external device at regular intervals.

A problem is that sometimes the software loop takes a long time. But the loop will also take a long time if the software has failed so I don't see how you can distinguish those cases.

Is the problem that the external device needs a pulse at regular intervals and you have no control over that time?

If so I'd use the serial link. Fill the buffer with the maximum number of characters transmittable in the "long" software loop in your software loop. That will continually send edges to the external hardware until 1) the Pi fails, or 2) the buffer is empty.

User avatar
AndrewS
Posts: 3625
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
Contact: Website

Re: Most reliable method for 500ms watchdog pulse

Tue Sep 24, 2013 11:07 am

I'm wondering if you're using this external microcontroller simply as a hardware watchdog, and using that to reset the Pi if it stops responding?

If that is all you're doing, a much simpler option would just be to use the Pi's internal hardware watchdog timer, e.g. https://duckduckgo.com/?q=raspberrry+pi+watchdog

EDIT: but if you want to keep using your external microcontroller, then I guess bash would be the simplest solution - see http://elinux.org/RPi_Low-level_periphe ... ing_system

devnull
Posts: 65
Joined: Sat Dec 24, 2011 7:46 am

Re: Most reliable method for 500ms watchdog pulse

Sun Sep 29, 2013 10:37 am

Thanks for all the suggestions.

I ended up using the Hardware PWM on GPIO18 in the end.
> /dev/null 2>&1

Return to “Arch”

Who is online

Users browsing this forum: No registered users and 2 guests