WDT, postscaler, Bully Bootloader

31 views
Skip to first unread message

Bryan Bennett

unread,
Jun 25, 2014, 4:17:24 PM6/25/14
to pic24-assemb...@googlegroups.com
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):
PWRSAV #SLEEP_MODE;
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.

Bryan









Robert Reese

unread,
Jun 29, 2014, 12:12:47 PM6/29/14
to pic24-assemb...@googlegroups.com
Bryan,

You have made the correct changes. The problem is that the bootloader code, when loading an application, does not change the configuration bits by default.  Because a device can be 'bricked' by incorrect settings of configuration bits, we have not enabled programming configuration bits by default. There is an option in bully bootloader to enable configuration bit programming by an application (check the box labeled 'Enable Config Bits Prgming), but I have not checked on this in  a while, and it may not even work even more. 

The alternative would be to edit the configuration bits in the bootloader code and reprogram the bootloader.

Since waking up and incrementing a variable takes so little time and CPU energy, and you are already by default able to sleep for 2 seconds at time, just use your loop to wake up 64 times for a total delay of 128 seconds).   You will be wasting a little bit of energy, but it will not be much.

Bob R

Bryan Bennett

unread,
Jun 30, 2014, 11:14:10 AM6/30/14
to pic24-assemb...@googlegroups.com
Bob,  

since I will actually be placing the PIC24 into SLEEP mode for a total of 45 minutes, do you think that using my FOR loop with a total 1350 iterations (30 x 45 = 1350) will be expending much energy?

Thanks for your time and help,

Bryan Bennett


--
You received this message because you are subscribed to the Google Groups "PIC24 Assembly-to-C Book" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pic24-assembly-to-...@googlegroups.com.
To post to this group, send email to pic24-assemb...@googlegroups.com.
Visit this group at http://groups.google.com/group/pic24-assembly-to-c-book.
For more options, visit https://groups.google.com/d/optout.

Dave

unread,
Jun 30, 2014, 11:50:03 AM6/30/14
to pic24-assemb...@googlegroups.com
Bryan,
As Dr. Reese is not certain that the bootloader will handle the configuration bits as you desire, perhaps a PICkit type in-circuit programmer would work better for you. Ebay has these for about $30.00.
Dave

Bryan Bennett

unread,
Jun 30, 2014, 5:58:24 PM6/30/14
to pic24-assemb...@googlegroups.com
Bob and Dave,

the original advice to check the box labeled "Enable Config Bits Prgming" actually worked and placed the PIC24 into SLEEP mode for 128 seconds since the change to WDT postscaler produced the desired and expected effect. Thank you so much for the advice, and I apologize for my ignorance but I am an amateur to this and am still learning my way around the technology.

Thanks again,

Bryan Bennett


Robert Reese

unread,
Jun 30, 2014, 7:10:30 PM6/30/14
to pic24-assemb...@googlegroups.com
No problem, glad you got it figured out!

 Bob R

Reply all
Reply to author
Forward
0 new messages