0
\$\begingroup\$

I have a PIC16 (datasheet here) for which I use the watchdog timer. I configure the watchdog timer as follows:

WDTCONbits.WDTPS = 0b01110;

According to page 105 of the datasheet, this should configure the watchdog timer for 16 seconds. However, the timer interrupt is called after only 4 seconds. (I have tested the timer with other values and the 4x discrepancy always persists.)

My first thought was that it was due to the 4xPLL being enabled. But as far as I understand, the watchdog timer is based upon the LFINTOSC clock, which is invariant under the 4xPLL.

Why is my watchdog timer running at four times the speed it should be?

\$\endgroup\$
1
\$\begingroup\$

According to the datasheet you provided, at page 105, the value you should program is: 01110. Thus the whole register should be 0b00011101 -> 0x1D.

It seam that you already did so. But are you sure that the definition of WDTCONbits.WDTPS doen't contains a bug ? Try to assign to the whole register directly.

The watchdog is powered by the internal low frequency oscillator. It has nothing to do with the PLL.

\$\endgroup\$
0
\$\begingroup\$

The timing bits are bits 5 to 1, which means for 16 seconds the register should be written with 0b00011100 (or the LSB can be 1 if you are controlling the WDT in software).
Not sure why it would be 4 times off rather than 2, but try writing the above value directly to the full register (i.e. WDTCON) and see if it works correctly.

Also, check the errata for the part, to see if any bugs are mentioned regarding the WDT.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.