Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 8 months ago.
WatchDog LPC1347
Hello all;
More problems with LPC1347, This time it is the watchdog,
#include "mbed.h" // data sheet: http://www.nxp.com/documents/user_manual/UM10524.pdf //DigitalOut myled1 (P1_2); //DigitalOut myled2 (P1_5); DigitalOut myled3 (P1_28); DigitalOut myled4 (P0_7); class Watchdog { public: void kick(float s) { // 3.5.8 Watchdog oscillator control register LPC_SYSCON->WDTOSCCTRL = 0x0021; // // 0x0024;// 0.6 mhz/4 ?? // 0x003f; // 0.6 Mhz / 64 -> ?? 0.106667 mS // 15.8.5 Watchdog Clock Select register LPC_WWDT->CLKSEL = 0x01; // Set CLK src to Watcdog osc //uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4 //LPC_WDT->WDTC = s * (float)clk; LPC_WWDT->TC = 9375; // ?? 1 second LPC_WWDT->MOD = 0x3; // Enabled and Reset LPC_WWDT->FEED = 0xAA; LPC_WWDT->FEED = 0x55; } void feed() { // LPC_WWDT->FEED = 0xAA; // LPC_WWDT->FEED = 0x55; } }; Watchdog w; int main() { printf("Hello World!\r\n"); w.kick(2.5); int hang = 0; int ReadCountDown; while(1) { //printf("loop...%d\r\n",hang); float h = hang / 10.0; ReadCountDown = LPC_WWDT->TV; // printf("ok T:%4.3f %d\r\n",h,ReadCountDown); // logging program printf("%d %d\r\n",hang, ReadCountDown); wait(0.1); myled3 = !myled3; if (hang == 30) { // w.feed(); LPC_WWDT->FEED = 0xAA; LPC_WWDT->FEED = 0x33; // force reset by wrong food !! printf ("\r\n Cat Food !!\r\n"); } else { myled4 = !myled3; } if (hang > 150) hang = 10; hang++; } }
I copied the example from Simon's Watchdog code from - http://mbed.org/forum/mbed/topic/508/
Changed some of the defines to match (compile) those in LPC13Uxx.h
but It does not work,
If I read the TC value, which should be decremented, it is fixed at 255 (default)
if I feed WatchDog with Cat food, no RESET is generated :(
As you can see, in the code, I NEVER feed the dog !!!
Still no reset ??
I know I must be doing some thing wrong, but what ??
Pleas any one ??
Ceri
1 Answer
9 years, 8 months ago.
Try adding at the start:
LPC_SYSCON->SYSAHBCLKCTRL |= 0x8000;
That enables clock for the registers of the watchdog.
In general example code for LPC11u24 WDT for a different purpose (waking from deepsleep): https://developer.mbed.org/users/Sissors/code/WakeUp/file/f3adba7cf7c4/Device/WakeUp_LPC11u24.cpp
Thanks,
it does appear to work now with IRC clock,
#include "mbed.h" // data sheet: http://www.nxp.com/documents/user_manual/UM10524.pdf //DigitalOut myled1 (P1_2); //DigitalOut myled2 (P1_5); DigitalOut myled3 (P1_28); DigitalOut myled4 (P0_7); Timer t; class Watchdog { public: void kick(float s) { // Table 268. Register overview: Watchdog timer (base address 0x4000 4000) // 3.5.14 System clock control register (SYSAHBCLKCTRL) LPC_SYSCON->SYSAHBCLKCTRL |= 0x8000; // 3.5.8 Watchdog oscillator control register LPC_SYSCON->WDTOSCCTRL = 0x0021; // // 0x0024;// 0.6 mhz/4 ?? // 0x003f; // 0.6 Mhz / 64 -> ?? 0.106667 mS // 15.8.5 Watchdog Clock Select register LPC_WWDT->CLKSEL = 0x00; // Set CLK src to 12MHZ - Watcdog osc //uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4 //LPC_WDT->WDTC = s * (float)clk; LPC_WWDT->TC = 3000000; // 9375; // ?? 1 second LPC_WWDT->MOD = 0x3; // Enabled and Reset LPC_WWDT->FEED = 0xAA; LPC_WWDT->FEED = 0x55; } void feed() { // LPC_WWDT->FEED = 0xAA; // LPC_WWDT->FEED = 0x55; } }; Watchdog w; int main() { t.reset(); t.start(); printf("\r\n\r\nHello World!\r\n"); w.kick(2.5); int hang = 0; int ReadCountDown; while(1) { //printf("loop...%d\r\n",hang); float h = hang / 10.0; ReadCountDown = LPC_WWDT->TV; // printf("ok T:%4.3f %d\r\n",h,ReadCountDown); // logging program printf("%d %08x, %d mS .. \r\n",hang, ReadCountDown, t.read_ms()); wait(0.01); myled3 = !myled3; if (hang == 30) { // w.feed(); // LPC_WWDT->FEED = 0xAA; // LPC_WWDT->FEED = 0x33; // force reset by wrong food !! // printf ("\r\n Cat Food !!\r\n"); } else { myled4 = !myled3; } if (hang > 150) hang = 10; hang++; } }
this gives 990mS count @ 9600 Baud,
will try to get my oscilloscope on it later, and tweak to get a value - or possibly set to a time out !!!
Would also like to get watchdog timer to work, but this makes me happy :)
Cheers
Ceri
posted by 21 Apr 2015