bug: WDT prescaler value passed to init_wdt produces reserved WDTPS #33

Open
opened 2026-08-02 05:25:20 +00:00 by time · 1 comment
Contributor

init_wdt(0b01010) shifts left by 1, producing WDTPS=10101 which is reserved and results in minimum interval (~1ms). To get 256s (WDTPS=10010), need to pass 0b10010 directly to WDTCONbits.WDTPS without shifting. The init_wdt function's shift logic is wrong for the new bitfield accessor pattern.

init_wdt(0b01010) shifts left by 1, producing WDTPS=10101 which is reserved and results in minimum interval (~1ms). To get 256s (WDTPS=10010), need to pass 0b10010 directly to WDTCONbits.WDTPS without shifting. The init_wdt function's shift logic is wrong for the new bitfield accessor pattern.
Author
Contributor

Confirmed and critical. In PICKLE.c, init_wdt(0b10010) shifts left by 1: WDTCON = (prescaler << 1) | SWDTEN, producing WDTCON = 0b101001. That sets WDTPS = 0b01001 (4s interval), not 0b10010 (256s).

The shift-left-by-1 was likely intended to make room for SWDTEN at bit 0, but it corrupts the WDTPS value. Fix: either (a) use bitfield accessor WDTCONbits.WDTPS = prescaler without shifting, or (b) pass prescaler >> 1 to the current function. Option (a) is cleaner.

This means the WDT is currently resetting every ~4s instead of 256s. With MAX_COUNTER=3, the device wakes every 12s instead of the intended ~1280s (~21min). This significantly impacts battery life.

Confirmed and critical. In PICKLE.c, `init_wdt(0b10010)` shifts left by 1: `WDTCON = (prescaler << 1) | SWDTEN`, producing WDTCON = 0b101001. That sets WDTPS = 0b01001 (4s interval), not 0b10010 (256s). The shift-left-by-1 was likely intended to make room for SWDTEN at bit 0, but it corrupts the WDTPS value. Fix: either (a) use bitfield accessor `WDTCONbits.WDTPS = prescaler` without shifting, or (b) pass `prescaler >> 1` to the current function. Option (a) is cleaner. This means the WDT is currently resetting every ~4s instead of 256s. With MAX_COUNTER=3, the device wakes every 12s instead of the intended ~1280s (~21min). This significantly impacts battery life.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
daru/PICsense#33
No description provided.