7
\$\begingroup\$

I am trying to implement the "Ultra Low Power Wake Up" feature on a small PIC project. The idea is the chip will go to sleep, and then be woken up in the future by the ULPWU interrupt.

The idea behind the ULPWU is that you connect a capacitor to this pin, charge it and put the chip to sleep. When configured, the ULPWU pin will slowly discharge the capacitor. Once the voltage on the cap falls to some value, the chip wakes up and possibly generates an interrupt.

This application note (PDF) from Microchip explains how the ULPWU is programmed and implemented. See Example 2 and Figure 2 (below).

Example 2:

BANKSEL PORTA           ;
BSF PORTA, 0            ;Set RA0 data latch
BANKSEL ANSEL           ;
BCF ANSEL, 0            ;RA0 to digital I/O
BANKSEL TRISA           ;
BCF TRISA, 0            ;Output high to
CALL CapDelay           ;charge capacitor 
BANKSEL PIR2            ;
BCF PIR2, ULPWUIF       ;Clear flag
BANKSEL PCON            ;
BSF PCON, ULPWUE        ;Enable ULP Wake-up
BSF TRISA,  0           ;RAO to input
BSF PIE2, ULPWUIE       ;Enable interrupt
MOVLW B’11000000’       ;Enable peripheral
                        ;interrupt
MOVWF   INTCON          ;
SLEEP                   ;Wait for interrupt
NOP                     ;


enter image description here

I have carried this out but am stuck with a strange problem.

When the chip goes to sleep, there is 5V being supplied by the ULWU pin (RA0). If I connect this pin to ground, the chip wakes up and does what it is supposed to do.

My question is, why is there 5V on this pin when it is supposed to be an input? If I have this pin connected to a charged capacitor, the capacitor never discharges (the 5V on the pin is keeping it charged).

EDIT
Here is my test code. I am not using a capacitor in this case. I am simply switching the RA0 pin from high to low. The question remains, why is RA0 High when it is supposed to be discharging a capacitor in order to trigger the wake up feature?

INCLUDE registers.asm
__CONFIG 0x2EFF20E5
     ORG    0x00
    GOTO    MAIN
;***********************************************
;Interrupt Service Routine
;turn on an led and return
;*********************************************
    ORG 0X04
ISR
    BANKSEL PORTD
    BSF PORTD,7
RETFIE

MAIN
    CALL    SETUP
    CALL    SETUP_WU
    SLEEP
TRAP
    GOTO    TRAP

SETUP
    BANKSEL ANSELH
    CLRF    ANSELH      ;CONFIGURE ALL PINS FOR DIGITAL IO
    CLRF    ANSEL
    BANKSEL TRISD   ;PORTD IS OUTPUT
    CLRF    TRISD
    BANKSEL PORTD
    CLRF    PORTD
    RETURN

SETUP_WU
    BANKSEL PORTA
    BSF PORTA,0
    BANKSEL ANSEL
    CLRF    ANSEL
    BANKSEL TRISA
    BCF TRISA,0
    BANKSEL PIR2
    BCF PIR2,2
    BANKSEL PCON
    BSF PCON,5
    BSF TRISA,0
    BSF PIE2,2
    MOVLW   B'11000000'
    MOVWF   INTCON
    RETURN

END
\$\endgroup\$
8
  • \$\begingroup\$ What value capacitor do you have the pin attached to? \$\endgroup\$
    – Oli Glaser
    Commented Jan 14, 2013 at 1:04
  • \$\begingroup\$ @Oli Glaser I have tried 100uF, 10uF, and somewhere in the pF range. \$\endgroup\$
    – Michael
    Commented Jan 14, 2013 at 4:23
  • \$\begingroup\$ You've posted the sample code, but it may help if you post the actual code you are using. There might be something wrong there. \$\endgroup\$ Commented Jan 14, 2013 at 6:46
  • \$\begingroup\$ You probably are clearing, instead of setting the least significant bit of TRISA. It should be "BSF TRISA, 0" instead of "BCF TRISA, 0" \$\endgroup\$
    – gmagno
    Commented Jan 17, 2013 at 0:36
  • \$\begingroup\$ @gmagno That cant be right. When the pin is manually connected to ground, the processor wakes and an interrupt is generated. That would indicate the ULWU feature is working and the PORTA is set for input. \$\endgroup\$
    – Michael
    Commented Jan 17, 2013 at 1:56

2 Answers 2

2
\$\begingroup\$

Are you sure you have waited for appropriately long times for the capacitor to discharge? Using Equation 2 in the application note:

equation 2

and your capacitor values you have supplied in your comments (x pF, 10uF, 100uF), the discharge times would be:

(5V - 0.6V)*10pF / 140nA = 314 useconds

(5V - 0.6V)*10uF / 140nA = 314 seconds ~= 5 minutes

(5V - 0.6V)*100uF / 140nA = 3,143 seconds ~= 52.3 minutes

Perhaps you are not waiting long enough enough on your uF capacitors, and the pF one is too small and causing the micro to become stuck in you interrupt routine (or something, without supplying YOUR code it is impossible to guess any sort of coding error).

A good value to try may be in the 100 nF range, which would wake up every ~3 seconds, which would be easy to see with the naked eye whether it is working.

NOTE: I took the values I used in Equation 2 from the example values in the Application note.

\$\endgroup\$
4
  • \$\begingroup\$ Good suggestion. However I can verify with a scope that the cap is charging. And I dont believe that answers the question of why the pin is set high with 5v after it has been set as an input. \$\endgroup\$
    – Michael
    Commented Jan 17, 2013 at 21:23
  • \$\begingroup\$ @Michael You should post your code for more help. Just posting the example code doesn't help us assist you very much. \$\endgroup\$
    – justing
    Commented Jan 17, 2013 at 23:06
  • \$\begingroup\$ Yes you are correct and I apologize. This function is part of a larger program. I really should have tried getting this subsystem working on its own before incorporating into a larger program. I need to pause this question for a bit so I can do some more work \$\endgroup\$
    – Michael
    Commented Jan 18, 2013 at 22:16
  • \$\begingroup\$ I have added my program to the question as requested. \$\endgroup\$
    – Michael
    Commented Jan 26, 2013 at 8:25
0
\$\begingroup\$

It is possible there is an internal pull-up on this pin that is activated.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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