This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

P89C66x PCA Watchdog Timer

I'm using Philips P89C664 which includes watchdog timer on the PCA Module 4.
P89C664 is running with 10.000MHz oscillator in 6 clock mode.
I use µVision V2.40 with C51 V7.09.

In Power-Up Initialization PCA is configured as follows:

CMOD    = 0x02;  //PCA Input Internal clock, fOSC/2 in 6 clock mode.
CCAP2H  = 0x80;  //PWM mit 50%/50% Duty cycle.
CCAPM2  = 0x42;  //Activate PCA Module 2 with PWM-Output on CEX2 (P1.5) -> PWM with approx. 19.5 kHz.
CCON    = 0x40;  //PCA Counter Run.
CCAPM4  = 0x08;  //Activate PCA Module 4 with Watchdog Timer, period approx. 13.2ms.
CCAP4L  = 0xFF;  //With clearing the bit ECOM4 (Disabling comparator in PCA Module 4).
CCAP4H  = 0xFF;  //With setting the bit ECOM4 (Enabling comparator in PCA Module 4).
CMOD   |= 0x40;  //Setting bit Watchdog Timer Enable.
Bios_delay_250ms();

Following shows the compiler output of subroutines in BIOS.LST:
             ; FUNCTION Bios_delay_5ms (BEGIN)
;---- Variable 'uc_ticks1' assigned to Register 'R7' ----
0000 7F33              MOV     R7,#033H
;---- Variable 'uc_ticks2' assigned to Register 'R6' ----
0002 7E11              MOV     R6,#011H
0004         ?C0004:
0004 DFFE              DJNZ    R7,?C0004
0006 DEFC              DJNZ    R6,?C0004
0008 22                RET
             ; FUNCTION Bios_delay_5ms (END)

             ; FUNCTION Bios_delay_250ms (BEGIN)
;---- Variable 'uc_hilfsvar' assigned to Register 'R5' ----
0000 7D32              MOV     R5,#032H
0002         ?C0010:
0002 120000      R     LCALL   Bios_delay_5ms
0005 E4                CLR     A
0006 F5EE              MOV     CCAP4L,A
0008 85F9FE            MOV     CCAP4H,CH         <--- Simulator Breakpoint here
000B DDF5              DJNZ    R5,?C0010
000D 22                RET
             ; FUNCTION Bios_delay_250ms (END)

Why does the watchdog kick off and reset occurs while processing the function Bios_delay_250ms()?

After stopping at breakpoint in simulator with value of R5=0x1C (therefore being executed 191817 cycles or 115.09ms), i watch following details:
PCA Timer CH/CL: 0xC802
CCAP4: 0x6600

After executing the next instruction MOV CCAP4H,CH i expect the value of CCAP4 should be 0xC800.
So, if i press Button F11 (single step), watchdog timer reset occurs... WHY?

I have no interrupts ever initialized or activated, e.g. bit EA is always still cleared!
I expect, that watchdog timer reset only occurs when matching CH/CL with CCAP4.
I know, writing in CCAP4L clears also the bit ECOM4 (Disabling comparator in PCA Module 4).
I know, writing in CCAP4H sets also the bit ECOM4 (Enabling comparator in PCA Module 4).

Am I missing something? Any other tricks to getting a safely hold off the watchdog reset?

Thanks,
Martin Macher

  • Here is an example of using the watch-dog and the pwm.

        CL = CH = 0;                // Set minimum on PCA counter
        CCAP1H = CCAP1L = 0x01;     // set up PWM for backlight, beeper
        CCAPM1 = 0x42;
    
        CCAP4H = CCAP4L = 0xff;     // Force maximum on Watch dog counter
        CCAPM4 = 0x48;              // Turn on watch dog
    
        CR = TRUE;                  // Start the watchdog
        CMOD = 0x40;                // WatchDog on, Osc/12
    

    To pat the watchdog I use the following macro:

    #define PatDog() { CCAP4H = CH-1; } /* Pat the watch dog */
    

  • I so detest the Intel PCA4 kludge.

    The 66x has a real whatchdog, use that. I am sure Philips included the Intel kludge for compatibility reasons only.

    Erik

  • Erik,
    first of all, I used the hardware watchdog timer. Due to the less bits (14 bit counter instead of 16 bits in PCA) there is a watchdog timer period of approx. 9.8ms (with crystal 10.0MHz mentioned in my first posting).

    I have the crucifix, that my mainloop in main() will be started every 10ms (by flag setting from ISR). In PCA solution, I get the desired watchdog timer period of approx. 13ms, so I decided to implement the second solution.


    You say PCA4 is a kludge. What confuses me, nevertheless:
    Following suggestion contents in all recent datasheets of 8051 derivates with PCA included, also in the Intel AppNote "AP-440 8XC51FA/FB/FC PCA Cookbook" (which is from Feb.1990!):

    WATCHDOG:
         CLR  EA         ;Hold off interrupts
         MOV  CCAP4L,#00 ;Next compare value is within
         MOV  CCAP4H,CH  ;255 counts of the current PCA
         SETB EA         ;timer value
         RET
    

    On account of the large and many years' spreading, it seems to be a safely solution, isn't it?
    In case of my detailed observation while debugging in simulator, the values were:
    PCA Timer CH/CL: 0xC802
    old CCAP4: 0x6600 (before executing MOV CCAP4H,CH)
    new CCAP4: 0xC800 (expected value after executing MOV CCAP4H,CH)
    Because the PCA timer counts upward, a matching (and therefore watchdog kick off) can never have occured!
    Have I misunderstood something?
    Is there a bug in the simulator?


    Bob,
    I will try your suggested method. If it runs perfectly, I will report here later!

    Martin

  • On account of the large and many years' spreading, it seems to be a safely solution, isn't it?
    It is not a "safely solution" because this so called watchdog can be turned off. All real watchdogs can not be turned off once turned on. Also, it can be restarted by ONE instruction where real watchdogs require 2 consequtive.

    as to "many years' spreading", in that light, you could recommend using an 8255 as well.

    Erik

  • Erik,
    I am in your opinion: A true safely Watchdog timer should never be disabled by any instruction!

    I have written a little misleading: I meant "a safely solution to hold off the watchdog reset".

    Martin

  • Meanwhile, I am debugging the PCA watchdog timer on a real target hardware (instead of the simulator): The same code runs on it correctly!

    It seems in such a way that the µVision V2.40 simulator has a bug!

    Erik, are you a member of the KEIL support team? I have this impression because you write here in the forum very often.

    Martin

  • Erik, are you a member of the KEIL support team
    my postings at
    http://www.keil.com/forum/docs/thread6246.asp (the IDE is stupid) should answer that.

    Erik

  • Hi devs,

    i get a new bugfixed version of Simulator-DLL (DP51.DLL Version 2.46b)!

    Now my Code works fine on it, thanks to KEIL support team!

    Martin

  • i have problems using the watchdog timer
    because of the very short delay befor reset
    could you helpe me to make the delay longer
    and please send me assembly software for
    philips p89c668 microcomputer to make the
    wd work thankyou
    m. kattan

  • Hi Mohamed,

    the hardware Watchdog-Timer (WDT) has only a 14-bit prescaler, so if you use 18.432 MHz crystal you get a WDT period of approx. 5.333 ms (Milliseconds).

    There is no way to extend the WDT delay. Except slowering the crystal clock itself of course ;-)

    You can use alternatively the Watchdog function of the PCA. But this isn't a true Watchdog function because in case of software malfunction the PCA can be stopped or cleared unintentionally, so the PCA-Watchdog is no more able to reset the µC! (see the topics above)

    So the only (relative) safe way you have is to retrigger the WDT by timer interrupt! BUT: Don't retrigger the WDT by timer interrupt ONLY! Because if a routine in mainloop hangs, Wtchdog will not reset the µC due to retriggering WDT permanently by timer interrupt!

    In this case, it's heavly recommended to extend your code by interprocess communication (e.g. semaphore or simply a bit flag), so the mainloop (which period is normally larger than timer interrupt interval) "can tell" to timer interrupt, "i'm okay"! If this flag fails, timer interrupt stopps retrigerring the WDT.

    Hope this helps you?
    Martin

  • please send me assembly software for
    philips p89c668 microcomputer to make the
    wd work

    Rephrase: please help me avoid the tedious task of reading the datasheet

    the hardware Watchdog-Timer (WDT) has only a 14-bit prescaler, so if you use 18.432 MHz crystal you get a WDT period of approx. 5.333 ms (Milliseconds). There is no way to extend the WDT delay. Except slowering the crystal clock itself
    slowing the clock gain you NOTHING. The number of instructons executed between WD ticks is a constant.

    So the only relative safe way you have is to retrigger the WDT by timer interrupt!
    This method has the same shortcoming as the PCA4 method, it can be beaten by runaway software.

    I never have understood the issue of this WD, you get 16000 instruction cycles per WD tick where is the problem? Retriggereing the WD once per 16000 instruction cycles is, if anything, too infrequent.

    Erik

  • you get 16000 instruction cycles per WD tick where is the problem?

    In my case, the mainloop (this is the endless loop in main() written in c language) will be computed every 20ms, in some other projects 100ms.

    Due to floating-point algorithms (with trigonometric functions) some unoptimized subroutines lasts up to 200ms, e.g. calculating solar state. With these outputs we can control the slat tracking on venetian blinds (sun protection) depending of the sun in geographical relation to the facade (azimuth and heigth).

    I have been optimized these number-cruncher subroutines down to 16ms (time-sliced). So its impossible to fit the whole mainloop into the WDT period of 5.33ms.

    This is a example where mainloop period is normally larger than timer interrupt interval.

    Martin

    BTW: In older projects e.g. with Infineon SABC515C there is a WDT with configurable periods of 1sec or longer at 10MHz, we have no problems with WDT intervals in mainloop with 100ms periods.

  • Sorry,

    This is a example where mainloop period is normally larger than timer interrupt interval.

    must be corrected as:

    This is a example where mainloop period is normally larger than WDT interval.

    Martin

  • This is a example where mainloop period is normally larger than timer interrupt interval.
    Who on earth has stated that you can only kick the puppy once in the main loop?

    floating-point algorithms (with trigonometric functions) .... (time-sliced).

    Martin,

    How often do you wipe the little '51s forehead, you are making it work really hard.

    It sounds as if you have coded "for the convenience of the programmer" not "for the convenience of the chip"

    Erik