Asm sleep - pbp sleep


Closed Thread
Results 1 to 32 of 32

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: Asm sleep - pbp sleep

    your code is an uncompilable snippet so its hard to know whats going on


    there are issues here

    Code:
    @    MOVF BAUDCON,0      ‘Is RCIDL idel?  Set for Idel    	‘For testing               
    @    MOVWF _Avar     	‘For testing                   				
        Avar=Avar dig 6  		‘For testing
    what bank is baudcon in ?
    what bank is Avar in ?
    from the looks of it Avar must be byte , how can it ever have a Dig 6

    whats wrong with one of these ,one of them will produce efficient code i'm sure

    if baudcon & 64 then
    avar=1
    else
    avar=0
    endif

    or

    avar=baudcon.6

    or

    avar=(baudcon&64) >>6
    Warning I'm not a teacher

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


    Did you find this post helpful? Yes | No

    Default Re: Asm sleep - pbp sleep

    Here is something from me:

    1. Leave the RX pin unconnected for testing. Check the pin state. Does it stay low or high? If it is high and you get int at high already, then it never sleeps.
    2. IF all ok, then before sleep instructon, disable GIE and PEIE first. Disable eusart module. Then re-enable it. clear the flags. Then enable GIE, PEIE and lastly usart int bit. Make sure usart flag is cleared, and Usart int bit enabled at the last just before SLEEP command.
    3. There should be at least two NOP() immediately after SLEEP.
    4. If there are some other ints in your code not shown here, than they may be the cause of wake up. Remember, Most of the ext int sources wake the device up eventhough you do not care for them. Make sure you disable all other ext int sources (if you are using any) before SLEEP.
    Last edited by sayzer; - 11th May 2020 at 08:42.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: Asm sleep - pbp sleep

    3. There should be at least two NOP() immediately after SLEEP.
    not as i read the data sheet


    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 enabled. Wake-up will
    occur regardless of the state of the GIE bit. If the GIE
    bit is disabled, the device continues execution at the
    instruction after the SLEEP instruction. If the GIE bit is
    enabled, the device executes the instruction after the
    SLEEP instruction, the device will call the Interrupt Service
    Routine. In cases where the execution of the
    instruction following SLEEP is not desirable, the user
    should have a NOP after the SLEEP instruction.
    Warning I'm not a teacher

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


    Did you find this post helpful? Yes | No

    Default Re: Asm sleep - pbp sleep

    One NOP is enough and should be a good practice to have one in any case. After all a NOP delay is too small to create any short of problem.

    Ioannis

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


    Did you find this post helpful? Yes | No

    Default Re: Asm sleep - pbp sleep

    Yes, I checked it again. For some reason I remember to have two NOPs. Sorry for that. Have one or three. It is up to you.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default Re: Asm sleep - pbp sleep

    I rephrase: at least one NOP.

    You may have as many as you want of course. Will not argue that. Still, I do not know which case(s) will not need the NOP, so put it there in any case!

    Ioannis

  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

    Quote Originally Posted by sayzer View Post
    Yes, I checked it again. For some reason I remember to have two NOPs. Sorry for that. Have one or three. It is up to you.
    So I've run all the test Sayzer has suggested. No changes. I then strip code to a couple of lines. I have done this on multipal 1936 and different boards.


    Code:
    Asm
     __config _CONFIG1,_FOSC_INTOSC & _CLKOUTEN_OFF & _MCLRE_ON & _BOREN_OFF & _WDTE_OFF & _FCMEN_OFF & _CP_OFF & _CPD_OFF & _IESO_OFF
     __config _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_ON & _BORV_LO & _LVP_OFF
    endasm  
    define OSC 8
        OSCCON=%01110000   ;1110=8Mhz                                                 
        ANSELA=$0   
        ANSELB=$0    
        ADCON0=$0
        PortA=0
        PortB=0                                      
        PortC=0 
        TrisA=%00000001                                                                                
        TrisB=%00001001        
        TrisC=%00000000   
        Avar    var byte
        Bvar    var byte
        Cvar    var byte 
        
    SleepMode:
    ASM
    ;    BTFSS   BAUDCON,RCIDL  ;Check for High, no receive in progress 
    ;    GOTO $-1                     ;return to previous line
    ;    BSF BAUDCON,WUE        ;Wake on Rx from Master
    ;    BSF PORTA,1            ;LED
       
        SLEEP
        BSF  PORTC,1   ;LED 
        nop
        nop
        nop                   .
    ENDASM
    SLEEP is the first command after which my LED flashes apx. every 2.14seconds.
    I then expand the code.

    Code:
    SleepMode:
    ASM
    ;    BTFSS   BAUDCON,RCIDL  ;Check for High, no receive in progress 
    ;    GOTO $-1                     ;return to previous line
                   
        BSF BAUDCON,WUE        ;Wake on Rx from Master
        BSF PORTA,1    ;LED 
        SLEEP
        BSF  PORTC,1   ;LED 
        nop
        nop
        nop                   .
    ENDASM
           END
    I run the code and LED A.1 is on and LED C.1 is blinding every 2.14sec.
    I then expand the code.

    Code:
    SleepMode:
    ASM
        BTFSS   BAUDCON,RCIDL  ;Check for High, no receive in progress 
        GOTO $-1                     ;return to previous line
        BSF BAUDCON,WUE        ;Wake on Rx from Master
        BSF PORTA,1            ;LED  
        SLEEP
        BSF  PORTC,1   ;LED 
        nop
        nop
        nop                    ; Should be in sleep for 10sec.
    ENDASM
    I run the code and No LED comes on. The program is stuck in the loop BTFSS BAUDCON, RCIDL & GOTO $-1. This is a HARDWARE RESET not caused by any of my code unless something in the configs are at falt. Threre are no interrupts as I have tested all flag bits i can think of. Rx stays LOW. No com is connected to the board. RCIDL should be HIGH but it is not.
    CONFIGS !!! Next round of testing.

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: Asm sleep - pbp sleep

    its all the same problem
    what bank is baudcon in?
    what bank is porta or portc in ?


    ASM
    BTFSS BAUDCON,RCIDL ;Check for High, no receive in progress
    GOTO $-1 ;return to previous line
    BSF BAUDCON,WUE ;Wake on Rx from Master
    BSF PORTA,1 ;LED
    SLEEP
    BSF PORTC,1 ;LED
    nop
    nop
    nop ; Should be in sleep for 10sec.
    ENDASM
    Warning I'm not a teacher

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 : 1

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