WDT, postscaler, Bully Bootloader

Find out how to setup your programmer's software and how to solve many common problems.

Moderator: phalanx

Post Reply
Posts: 4
Joined: Wed Jun 25, 2014 1:28 pm

WDT, postscaler, Bully Bootloader

Post by Siddartha » Wed Jun 25, 2014 1:33 pm

I am using a PIC24HJ64GP502 (FCY = 40MHz) to monitor heart rate derived from a finger tip mounted heart pulse detector (like pulse oximeter without oximeter part) so as to possibly detect REM sleep of human subject. I am using the MPLAB IDE v8.7 in conjunction with the Bully Bootloader to program my PIC24. I want the PIC24 to enter SLEEP mode for the first 45 minutes after the subject goes to bed since the first 45 minutes of heart rate and body movement data is irrelevant for detecting REM sleep.

I used the WDT to awaken the PIC24H from SLEEP mode by using a FOR loop to repeatedly place the PIC24H into SLEEP mode with the following code:

for (j=1; j<6; j++) // I chose j<6 just as an arbitrary test run
RCONbits.SWDTEN = 1; // activate WDT
asm("pwrsav #0"); // enter SLEEP mode
RCONbits.SWDTEN = 0; // deactivate WDT
// main body of code here where I begin to monitor heart rate and body movement

According to the macros in the pic24_configbits.c source file, the WDTPRE is set at 128 and the WDTPOST was set at 512 in the following code:
_FWDT (FWDTEN_OFF & WINDIS_OFF & WDTPRE_PR128 & WDTPOST_PS512); // found in pic24_configbits.c source code
I changed the WDTPOST in the above code to: WDTPOST_PS32768
but for each iteration of my FOR loop, the SLEEP mode is lasting about 2 seconds, which is consistent with WDTPRE equal to 128 and WDTPOST equal to 512, since (TLPRC)x(WDTPRE)x(WDTPOST) = (1/32768)x(128)x(512) = 2 However, since I changed the WDT postscaler to 32768, the SLEEP mode for each iteration of my FOR loop should last for 128 seconds since (1/32768)x(128)x(32768) = 128 ; but this is not happening.

I have searched all of my source and header files as listed in the Project Window of the MPLAB.IDE for any references to the WDT and its prescaler and postscaler values, but the pic24_configbits.c source file is the only file that contains parameters for the WDT which I have changed accordingly, but it is not having the desired effect. Any advice that anyone could offer would be greatly appreciated.

Interestingly enough, when I used the PWRSAV assembly syntax for SLEEP mode from the PIC24H FRM (Section 9):
my code failed to build successfully. So I used the code that I found in a PIC24 textbook ("Microcontrollers: From Assembly Language to C Using the PIC24 Family") which is:
asm("pwrsav #0");
which evidently worked well.


Post Reply