SLEEP mode 16F628A


Closed Thread
Results 1 to 8 of 8
  1. #1

    Default SLEEP mode 16F628A

    I have a 16F628A as an infrared rcvr/xmtr pair and the data is transferred fine but having some intermitent problems. (It may be my receiver breadboard, if my code looks alright....it may well be the breadboard.....it works off and on).

    I'll junk the breadboard if the code looks ok.

    Neverthe less, I'd like to check some things and also want to make sure that the code is letting the pic sleep.

    (1) If you're using the PORTB.0 interrupt, do you have to enable the PORTB pullups? If so, does it set the whole port or can you assign the pullups individually? (I'll have to use an external 10k...if I need to)

    (2) When you come out of sleep and you see a high pulse on PORTB.0 and go to a routine.....at some point you need to reset the B.0 flag, right?
    INTCON.1 = 0

    My code for the Xmtr is basically as follows....I'm using 1n4148 steering diodes at every switch to take PORTB.0 high... (and wake up chip?).

    WDT is off.

    START:

    SWITCH.1 = PORTA.0 '10K PULLDOWNS ON ALL
    SWITCH.2 = PORTA.1
    ETC

    SEROUT PORTB.7,T1200,[QUAL,SWITCH]

    INTCON.1 = 0
    IF SWITCH = 0 THEN LOWPWR
    IF SWITCH >= 1 THEN START

    LOWPWR:
    INTCON.4 = 1 'ENABLE INTERRUPT
    OPTION_REG.6 = 1 'LOW TO HIGH TRIGGER
    @SLEEP
    PAUSE 100
    INTCON.4 = 0 'DISABLE INTERRUPT (Ok here?)
    GOTO START

    END


    Thanks for any help on this.

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Either I'm asking really stupid questions or (?) but I'm not having much luck with this forum.

    Anyway....just wondering if my code is letting the PIC sleep....everything else seems to be working fine but I'm seeing some battery drain after just a few days.

    Thanks.

    --Mike
    (picbasic novice)

  3. #3
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    Hi Mike,
    Well, at a glance your code looks like it should let the Pic go to sleep, but I'm certainly not a pro!

    On your two questions...
    (1) If you're using the PORTB.0 interrupt, do you have to enable the PORTB pullups? If so, does it set the whole port or can you assign the pullups individually? (I'll have to use an external 10k...if I need to)

    (2) When you come out of sleep and you see a high pulse on PORTB.0 and go to a routine.....at some point you need to reset the B.0 flag, right?
    INTCON.1 = 0
    1) You don't have to use the built-in pullups if you don't want to - but be sure to use an external pullup / pulldown as needed otherwise. The entire port has its pullups enabled as a group (other Pic models allow setting individual pin pullups). When a pin is switched to output mode, the individual port pin pullup is automatically disabled.

    2) The interrupt flag(s) should be cleared before exiting your interrupt service routine and resuming the 'normal' program.


    You might consider putting some 'debugging' blinky LED outputs throughout your code for a visual indication of where the code is.

    Arch
    Last edited by Archilochus; - 24th April 2006 at 14:51.

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Well one thing's for sure, I'll add the 10k pullup on PORTB.0, there isn't one now.

    I just didn't know....I mean obviously it's an input when acting as an interrupt but who's to say that as part of the INTCON.4 statement it doesn't automatically configure the internal pullup?....so there is always some question to ask when you're a beginning pic person.

    Something isn't acting right....I have the xmtr on a PCB but the rcvr on breadboard so I'll just wait till I get it all on PCB's and everything stable.

    2 fresh aaa cells in the xmtr and had close to 3 volts....but today about 2.6.....yet I understand in sleep mode, battery life should be close to shelf life?

  5. #5
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    Yup - the power consumption sounds high. It should be below ~10uA in sleep if everything is set up for low power operation.

    The pullups will not be set automatically - you have to enable them. Same goes for the input/output states - enabling the interrupt does not set the pin to an input.

    Arch

  6. #6
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    966


    Did you find this post helpful? Yes | No

    Default caution

    Hi Michael

    I'm not sure if this will help. The sleep statement needs to be followed by at least a nop. Read the datasheet carefully - it has a mention of this. Anyway, I am too lazy to read it and point it out at this time. I use the 16F628A in sleep and successfully.

    The statement sequence should be

    @sleep
    @nop
    @nop

    Also, make sure that the pending interrupt is cleared before you put the PIC to sleep.

    Jerson

  7. #7


    Did you find this post helpful? Yes | No

    Default

    Ok....that's a new one. A NOP?

    Everything I think is fine...as always a stupid mistake on my part by not taking PORTB.0 low with a pulldown and letting it float....(a great way to get "unpredictable" behavior).

    It was probably sensing a false high and interfering with the sleep routine.

    I had put a pause following sleep as I had read in the archives (Melanie?) suggested it's use, to let the PIC wake up and get some coffee.

    Maybe what your saying is the NOP would do the same thing?

    Sort of a safety buffer before it gets back to work?

  8. #8
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    966


    Did you find this post helpful? Yes | No

    Default Ok, Here it is

    See section 14.8.1 of the datasheet on page 110/168. This is the excerpt

    When the SLEEP instruction is being executed, the
    next instruction (PC + 1) is pre-fetched. For the device
    to wake-up through an interrupt event, the correspond
    ing interrupt enable bit must be set (enabled). Wake-up
    is regardless of the state of the GIE bit. If the GIE bit is
    clear (disabled), the device continues execution at the
    instruction after the SLEEP instruction. If the GIE bit is
    set (enabled), the device executes the instruction afte
    the SLEEP instruction and then branches to the inter
    rupt address (0004h). In cases where the execution of
    the instruction following SLEEP is not desirable, the
    user should have an NOP after the SLEEP instruction.

    Jerson

Similar Threads

  1. High Power Consumption in Sleep Mode
    By ngeronikolos in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 18th September 2014, 13:29
  2. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 09:00
  3. Need help with SLEEP mode
    By aggie007 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 28th November 2007, 09:56
  4. Replies: 3
    Last Post: - 27th November 2007, 08:56
  5. 16F628A current high during sleep
    By Rubicon in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 9th October 2006, 10:21

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts