Asm sleep - pbp sleep


Closed Thread
Results 1 to 32 of 32

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: Asm sleep - pbp sleep

    if you are going to do this sort of thing in asm then you need to understand how banked memory access is
    used for this chip. hint [ baudcon is not in access bank ]
    Warning I'm not a teacher

  2. #2
    Join Date
    Jan 2009
    Location
    Alabama,USA
    Posts
    232


    Did you find this post helpful? Yes | No

    Default Re: Asm sleep - pbp sleep

    Quote Originally Posted by richard View Post
    if you are going to do this sort of thing in asm then you need to understand how banked memory access is
    used for this chip. hint [ baudcon is not in access bank ]

    Thanks guys for all your replies. I really do appreciate the time you've
    taken.
    So Richard, I should have understood what you were saying the first time. I converted all code to PBP and it looks like RCIDL is set after all. However it didn't change the results.
    I then went to battery power, no change. Still a reset every 2.14sec. I also changed several of the configs with no change in results. I may mark this one up as part of the magical mystery tour as I have a work around for the problem. This is one of a couple problems that I could never solve. The other was the inability to make RA.7 a digital I/O. I wonder if my software has some corruption. Yea, when all else fails blame it on the software. Wayne

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default Re: Asm sleep - pbp sleep

    Did you set WDT to OFF?

    Ioannis

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default Re: Asm sleep - pbp sleep

    OK, here is the explanation about the NOP:

    When the SLEEP instruction is being executed, the next
    instruction (PC + 1) is prefetched. For the device to
    wake-up through an interrupt event, the corresponding
    interrupt enable bit must be set (enabled). Wake-up
    occurs 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
    after the SLEEP instruction, then branches to the interrupt
    address (0004h). In cases where the execution of
    the instruction following SLEEP is not desirable, the
    user should have a NOP after the SLEEP instruction.
    The WDT is cleared when the device wakes up from
    Sleep, regardless of the source of wake-up.


    The key is that before SLEEP the next command is prefetched and might not be what one wants right after a wake, especially after wake from interrupt.

    Ioannis

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: Asm sleep - pbp sleep

    a 2 sec reset looks very likely to be wdt



    after disabling wdt i would try something like this

    Code:
    SleepMode:
        PortA.1=0     ;Indicator LED out on entering SLEEP
    ASM
        BANKSEL BAUDCON  ;bank 3
        BTFSS   BAUDCON,RCIDL  ;Check for High, no receive in progress
        GOTO $-1                
        BSF BAUDCON,WUE        ;Wake on Rx from Master 
        BANKSEL 0  ;bank 0
        BSF  PORTC,1   ;LED 
        BCF INTCON ,7
        SLEEP
        nop
        BSF INTCON ,7
    ENDASM
        PortA.1=1                   ;Indicator LED ON  at exit SLEEP
        return
        end
    Warning I'm not a teacher

  6. #6
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Re: Asm sleep - pbp sleep

    Quote Originally Posted by richard View Post
    .....

    Code:
      SLEEP
        nop
        BSF INTCON ,7
    

    Wayne,
    Pay attention to Rihard's code there. The first ting after SLEEP must be NOP.
    You did not have NOP as the first thing atfer SLEEP in your code.

    and WDT is OFF in config; how can it be an issue?
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  7. #7
    Join Date
    Jan 2009
    Location
    Alabama,USA
    Posts
    232


    Did you find this post helpful? Yes | No

    Default Re: Asm sleep - pbp sleep

    Success at last, well kind of. New questions are raised as the problem is solved.
    Alain's code dimnstrates the purpose of the sleep state, low power, all ports off. This is not required but is good practice.

    I followed richards ASM modifications of my poor attempt (years since I wrote ASM. I was trying to brush up)

    WDT was always off in Configs so it was never WDT event. Will later read Config addresses to confirm I got what I wanted in memory.

    As I enter the ASM code blockk, no LED can be executed after the test for RCIDL and before SLEEP.
    Place BSF Portx.x before RCIDL test and SLEEP works.
    Place BSF Portx.x after RCIDL test and SLEEP dies not works.
    Place BSF Portx.x after BSF BAUDCON, WUE and SLEEP dies not works.
    Place BSF Portx.x after BSF INTCON.7 t and SLEEP dies not works.

    Before entering the ASM block i can turn on as many LED's as I like and Sleep works as it should.

    OK so this is a strange behavure that does not fit any RESET format I can find in the data sheet.

    Regarding the data sheet section memtioned by Ioannis.
    Wake up will occure regardless of state of GIE bit.
    PC SLEEP +1 is prefeched durring SLEEP.

    SLEEP with GIE set: NOP may be needed in this case!
    Test RCIDL
    Set WUE
    SLEEP
    Wake and exicute next instruction
    Call ISR
    return to Sleep +2
    continue program

    SLEEP with GIE clear: no NOP needed but it can't hurt!
    Test RCIDL
    Set WUE
    SLEEP
    Wake and exicute next instruction
    No ISR called
    continue program

    In my case I will WAKE on EUSART single byte %00000000. I need the ISR to read RCREG and clear RCIF, then discard Break character. Single NOP will be needed.

    So now the adventure of the WAKEUP routine. Thank you for alll your help.
    Wayne

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default Re: Asm sleep - pbp sleep

    Glad you did it! Similar cases we faced I guess too.

    But that makes me wonder, if we try so hard to solve such things on a PIC, what would happen on a more complex MCU? Would then take years to find what is wrong???

    Ioannis

Similar Threads

  1. Can't @sleep
    By MOUNTAIN747 in forum General
    Replies: 3
    Last Post: - 30th December 2010, 17:29
  2. Trying to add a sleep function or pretend to sleep
    By lilimike in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 9th May 2010, 19:10
  3. Help with PBP 'SLEEP' command
    By dreadmaul in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 18th November 2006, 07:40
  4. How to go to sleep
    By savnik in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 22nd September 2006, 18:38
  5. Sleep Mode in PBP
    By Keith in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th March 2005, 20:58

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