Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

18F2420 Sleep / low power options

Status
Not open for further replies.
HI,

I have built a circuit around an 18F2420. The PIC reads data from a RTCC chip. If the main +5V circuit power fails, a MAX 690 switches in a 3.6v cell to power the RTCC. I want to monitor the backup cell voltage via the PIC. But if the main +5V is lost there will be +3.6V (assuming new cell) on the PIC analogue input wrt the PICs Vdd. So I figure the best thing to do is also power the PIC from the 3.6V cell when power fails but put the PIC into sleep mode.

How do I go about this? Can I use the PBOR to trigger an interupt that will put the PIC to sleep or is it better to use the HLVD function? Never used any of these low power options or interupts before. Reading the data sheet has made my mind go a bit funny.

Be grateful for any advice. Thanks.
 
Hi,

Finally got the HLVD working, but my PIC won't go to sleep when the sleep instruction is in the ISR. It will sleep if the sleep instruction is in the main program. Any ideas, please.

Code:
list      p=18F2420            
    #include <p18F2420.inc>
    errorlevel  -302            ; suppress message 302 from list file
    errorlevel  -305
    
    CONFIG  OSC = INTIO7, FCMEN = OFF, IESO = OFF, PWRT = OFF, BOREN = OFF, WDT = OFF, MCLRE = OFF, LPT1OSC = OFF,            PBADEN = OFF, STVREN = OFF, LVP = OFF, XINST = OFF, DEBUG = OFF
        

    org  0
    
    goto    Start
    nop
    nop
      
ISR:
    bcf     PORTA,0  
    sleep    
    nop
    nop
       
Start
    clrf    LATA    
    clrf    PORTA
    clrf    TRISA
       
    movlw   b'01100010'     ;4mhz
    movwf   OSCCON
    
    movlw   b'00011110'     ;<3:0> set trip level (1110 = 4.6V)
    movwf   HLVDCON
    
    bcf     PIR2,2          ;(HLVDIF)
    bsf     PIE2,2          ;(HLVDIE)
    bsf     INTCON,7        ;(GIE)
    bsf     RCON,7          ;(IPEN - enable priority interupts)  
    bsf     IPR2,2          ;HLVD is high priority interupt
    
Main
    bsf     PORTA,0         ;turn led on
    nop
    goto    $-2             ;wait for interupt
    
    end
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top