bug: WDT prescaler value passed to init_wdt produces reserved WDTPS #33
Labels
No labels
bug
duplicate
enhancement
help wanted
invalid
question
wait-to-fix
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
daru/PICsense#33
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.
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 = prescalerwithout shifting, or (b) passprescaler >> 1to 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.