For use in my acoustic touchscreen project, found here: http://hackaday.io/project/1990-Low-Cost-Touchscreen-Anywhere

Dependencies:   mbed

Revision:
3:5d221e8f4012
Parent:
2:2ccbee38f4a8
Child:
4:99bd88e2b2e7
--- a/main.cpp	Sat Aug 09 15:04:11 2014 +0000
+++ b/main.cpp	Wed Aug 13 21:25:49 2014 +0000
@@ -15,6 +15,34 @@
 
 float timeArray[3];  //important. this stores the delays between vibration detections
                    //right now only indices 0 and 1 are used
+
+
+//Code from: http://mbed.org/users/ThatcherC/code/WatchDogTest/
+class Watchdog {
+public:
+// Load timeout value in watchdog timer and enable
+    void kick(float s) {
+        LPC_SYSCON->SYSAHBCLKCTRL = LPC_SYSCON->SYSAHBCLKCTRL|(1<<15);
+        LPC_SYSCON->WDTCLKSEL = 0x1;                // Set CLK src to Main Clock
+        LPC_SYSCON->WDTCLKUEN = 0x01;       /* Update clock */
+        LPC_SYSCON->WDTCLKUEN = 0x00;       /* Toggle update register once */
+        LPC_SYSCON->WDTCLKUEN = 0x01;
+        LPC_SYSCON->WDTCLKDIV = 0x10;
+        uint32_t clk = SystemCoreClock/16;    // WD has a fixed /4 prescaler, PCLK default is /4
+        LPC_WDT->TC = s * (float)clk;
+        LPC_WDT->MOD = 0x3;                   // Enabled and Reset
+        kick();
+    }
+// "kick" or "feed" the dog - reset the watchdog timer
+// by writing this required bit pattern
+    void kick() {
+        LPC_WDT->FEED = 0xAA;
+        LPC_WDT->FEED = 0x55;
+    }
+};
+
+Watchdog w;
+                   
 void flip1(){
     if(first){
         t.start();
@@ -64,6 +92,7 @@
 int main() {
     pc.baud(115200);
     pc.printf("Ready\n");
+    w.kick(.1);
     int1.fall(&flip1);
     int2.fall(&flip2);
     timeArray[0] = 0;
@@ -73,7 +102,7 @@
         if(timeAvailable){
             int tA0 = int(timeArray[0]*1000000);
             int tA1 = int(timeArray[1]*1000000);
-            pc.printf("[%i, %i]\n",tA0,tA1);
+            pc.printf("%i\t",tA0-tA1);
             t.reset();
             timeArray[0] = 0;
             timeArray[1] = 0;
@@ -83,5 +112,6 @@
             int1.fall(&flip1);
             int2.fall(&flip2);
         }
+        w.kick();
     }
 }