Take the 2-minute tour ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

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
share|improve this question
    
What value capacitor do you have the pin attached to? –  Oli Glaser Jan 14 '13 at 1:04
    
@Oli Glaser I have tried 100uF, 10uF, and somewhere in the pF range. –  Michael Jan 14 '13 at 4:23
    
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. –  apalopohapa Jan 14 '13 at 6:46
    
You probably are clearing, instead of setting the least significant bit of TRISA. It should be "BSF TRISA, 0" instead of "BCF TRISA, 0" –  gmagno Jan 17 '13 at 0:36
    
@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. –  Michael Jan 17 '13 at 1:56
show 3 more comments

2 Answers

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.

share|improve this answer
    
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. –  Michael Jan 17 '13 at 21:23
    
@Michael You should post your code for more help. Just posting the example code doesn't help us assist you very much. –  justing Jan 17 '13 at 23:06
    
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 –  Michael Jan 18 '13 at 22:16
    
I have added my program to the question as requested. –  Michael Jan 26 '13 at 8:25
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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