Asm sleep - pbp sleep


Closed Thread
Results 1 to 32 of 32

Hybrid View

  1. #1
    Join Date
    Jan 2009
    Location
    Alabama,USA
    Posts
    219

    Default Asm sleep - pbp sleep

    My project uses a 16F1936 on both a Master and a Slave board. Durring the program the Master sends a code for the Slave to run a subroutine to SLEEP. I am trying to use ASM SLEEP as to NOT designate a time to wake. twenty two hours after the slave enters sleep it recieves a USART comm which should WAKE the slave from SLEEP. Problem is the slave is not going to sleep, or it wakes right away after the command. So, how to trouble shoot SLEEP? I can't monitor the STATUS, PD bit while in sleep, I can only use an indicator LED when going into the SLEEP instruction and toggle it off when exit the sleep instruction, and it is toggling right away.
    One observation is that PBP asks for a period whenever I type SLEEP in the ASM module. Can PBP tell the difference between ASM SLEEP and PBP SLEEP or are they both seen as a PBP command? Comments please.
    Code:
      ;Slave Board
        PortA.1=1	Indicator LED
    
    RXceiveINT:
        INTbit=1             'Set Cvar to break out of Start loop                                                                                           
        Com_Enable=0       ' Con_enable not needed to RX
        hserin [Bvar] 
    @ INT_RETURN    ;goes back to INTerrupt locaion. which is Start loop.
    
    ;-----------------------
    CaseAction:
        busy=1
        Select Case Bvar
                Case 0 ;No action taken if Not in Sleep Mode, Return only
    @   nop            ;If in Sleep Mode, Wake up, goto Start          
    @   nop
    @   nop
                Case 1
                    gosub Ran_num
                Case 2
                    gosub RappidFireRight
                case 3
                    gosub RappidFireLeft
                case 4
                    gosub Desolve
                case 5
                    gosub FlashFlies
                CASE 6
                    gosub  SleepMode	;subroutine to place Slave in Sleep mode
        end select
        busy=0             
        return
    
    ;------------------Case6
    SleepMode:
        PortA.1=0     ;Indicator LED out on entering SLEEP
    ASM
        BTFSS   BAUDCON,RCIDL  ;Check for High, no receive in progress
        GOTO $-1                
        BSF BAUDCON,WUE        ;Wake on Rx from Master 
        SLEEP
        nop
        nop
        nop
    ENDASM
        PortA.1=1                   ;Indicator LED ON  at exit SLEEP
        return
        end
    The Master does not use the comm line for the next 22 hours.

    Wayne

  2. #2
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: Asm sleep - pbp sleep

    Code:
    @ SLEEP
    @ NOP
    It often makes a difference adding the NOP right after SLEEP.

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


    Did you find this post helpful? Yes | No

    Default Re: Asm sleep - pbp sleep

    at a guess is it possible there is still activity on the serial input ie a cr/lf after the command.
    your code might see a RCIDL condition between these chrs and pop into and straight out of sleep
    try a small delay before calling sleepmode a 2chr time delay can't hurt here

    It often makes a difference adding the NOP right after SLEEP.
    which you have already is necessary, the extra two in use may not be adding much value but won't hurt
    Warning I'm not a teacher

  4. #4
    Join Date
    Jan 2009
    Location
    Alabama,USA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default Re: Asm sleep - pbp sleep

    PIC16F1936, PBP PRO 2.60, MPASM,
    My Slave Board receives com from the Master Board and runs Subroutines.
    Slave operates in tight loop at Start.
    On EUSART INT Slave receives one command Byte from Master and advances to CaseAction (Multi-IF THENs) which will branch to Sub to take action.
    When Slave receives a code for Sleep Mode (CASE 7) is run.

    Here’s where my problems start!
    It seams that the RCIDL bit is never being set after Rx.
    Will not go into SLEEP mode with or without -
    BTFSS BAUDCON,RCIDL ;Check for High, no receive in progress
    GOTO $-1
    Before WUE bit is set.
    What would prevent RCIDL from being set? Even after a hundred cycles after Comm is complete? Data Sheet says this bit should be set on EUSART Stop bit. At this time no Rx is coming from the Master. Can’t get any SLEEP!

    Wayne

    Code:
    Start:                                                                                                                            
    @   nop
    @   BTFSS _INTbit             ;if set - gosub   CaseAction
    @   goto $-1
        INTbit=0                      ‘My INT flag bit
        gosub CaseAction         
        goto Start
    ;----------------------------------------------------------------------------------
    RXceiveINT:          ‘ISR
        INTbit=1             'Set INTbit to break out of Start loop                                                                                                              
        hserin [Bvar] 
    @ INT_RETURN    ;goes back to INTerrupt locaion. which is Start loop.
    ;----------------------------------------------------------------------------------
    CaseAction:   ‘PBP multi IF THEN’s
        busy=1
    @    MOVF BAUDCON,0     ;What is in the RCIDL bit?                            ;TESTING                         
    @    MOVWF _Avar                                                                        ;TESTING    
            serout2 USB_Tx,84, ["    BAUDCON=",bin8 Avar,13,10]                 ;TESTING
        Bvar=Bvar+1   'On wakeup Slave receives %00000000 from Master,
        Select Case Bvar
                Case 1 ;No action taken if Not in Sleep Mode   
                    gosub Dummy
    ;------------
               CASE  7
                    gosub  SleepMode
        end select
        busy=0             
        return
    ;----------------------------------------------------------------------------------
    ;------------------Case7
    SleepMode:
    @  INT_DISABLE RX_INT      ‘ASM- disable EUSART interrupt                              
        PortA.1=1            ‘Flash LED when entering Sleep Mode routine
        pause 100                                              
        PortA.1=0                                              
    @    MOVF BAUDCON,0      ‘Is RCIDL idel?  Set for Idel    	‘For testing               
    @    MOVWF _Avar     	‘For testing                   				
        Avar=Avar dig 6  		‘For testing               
       serout2 USB_Tx,84, ["    RCIDL=",dec Avar,13,10]  ‘display contents of RCIDL  ‘For testing               
            
    ASM
        BSF BAUDCON, ABDEN      ;enable Auto Detect in sleep mode - tried with and without
        BTFSS   BAUDCON,RCIDL  ;Check for High, no receive in progress - tried with and without
        GOTO $-1                	     ;return to previous line
        BSF BAUDCON,WUE           ;Set to Wake on Rx from Master 
        SLEEP 
        nop		‘WAKE from EUSART Rx should occur here
        nop
        nop                    ;
    ENDASM
    
        for Avar = 1 to 10         ‘flash LED on wakeup for TESTNG              
        PortA.3=1
        pause 50
        PortA.3=0
        pause 50   
        next Avar
    @ INT_ENABLE   RX_INT     ‘ASM- reenter EUSART interrupt
        Return
    
       END

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


    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

  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

    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

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default Re: Asm sleep - pbp sleep

    I read somewhere in microchip datasheets there might be a @NOP just past the @SLEEP ...

    INT1 is the wakeup event.

    here it has been working fine for me ... for about 15 years ! ( Lawn tractor computer ... )

    Code:
    Sommeil:
    
    	LCDOUT $FE,2, "BYE-BYE "
    
    	For I = 8 to 0	Step -1					'Animation arret
    	
    		LCDOUT 	$FE,$C0,REP "*"\I," "			'	...  4s 			
    		PAUSE 500
    		
    	NEXT I
    	
    	PORTB.4 	= 0					'Ports LCD à 0
    	PORTB.5 	= 0
    
    	PORTC.7 	= 0					' PortC à 0
    	PORTC.6 	= 0
    	PORTC.5 	= 0
    	PORTC.4 	= 0	
    	
    	
    	AlLCD 		= 1					' Coupure LCD
    	AlRef 		= 0					' Coupure Vref	
    	ADCON0.0	= 0					' Désactivation ADC
    
    	
    	T3CON.0		= 0				' arret TMR3
    	T1CON.0		= 0				' arret TMR1
    	T0CON.7 	= 0				' arret TMR0
    	
    	INTCON.7 	= 0			' Wakeup sans interruptions
    	
    	INTCON3.0 	= 0						' reset flag INT1
    	INTCON3.3 	= 1			' validation INT1 pour réveil
    
    	Alim		= 0			'Coupure alimentation
    	Signal 		= 0			'Extinction voyant régime
    				
    @ SLEEP
    @ Nop						' Redémarrage par mise du contact sans coupure générale
    							' Arret par décharge capa alim. 
    
    	
    	INTCON3.3 	= 0			'Neutralisation INT1
    	INTCON3.0 	= 0			'Reset Flag INT1
    	Alim		= 1			'Remise alimentation si remise contact rapide.
    	
    '*****************************************************************************
    Wakeup: 'Début du Programme - reveil du PIC / Affichage Memoire
    '*****************************************************************************
    '
    FLAGS 	= 0					' Validation Reset LCD
    
    	PORTB.4 = 0					'Ports LCD à 0
    	PORTB.5 = 0
    
    	PORTC.7 = 0					' PortC.4-7 à 0
    	PORTC.6 = 0
    	PORTC.5 = 0
    	PORTC.4 = 0
    	
    Reveil 	= 1
    LSelect	= 0
    Alain
    Last edited by Acetronics2; - 12th May 2020 at 16:12.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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