Menu

Help again please with Sleep function

Help
Keith
2026-03-29
2026-03-30
  • Keith

    Keith - 2026-03-29

    Many moons ago you helped with some code you wrote for me to send a PIC29F202 into sleep. The code you wrote was:

    SysBYTETempA = On_signal
    'Clear the port change reset flag
    Set GPWUF off

      movlw B'01001111'   'This is assembler.  :-)
      option
      'Return to sleep
      wait 3 S
      sleep
      nop
    

    The code has been recycled many times by simply changing the £On_signal " line.

    the PIC16F18346 I'm using in this latest project doesn't want to know this and spits it out as if it were a nasty taste.
    Having resolved all the project issues, i'm on the last hurdle and quite pleased with the outcome but I want the processor to go to sleep - any help would be really appreciated

     
  • Anobium

    Anobium - 2026-03-29

    Just enter the command sleep

     
  • Keith

    Keith - 2026-03-29

    So I don't use any of the code instructions as befpre with the 10F202 and 12F508 ?

    Thats magic - Thank you.

     

    Last edit: Keith 2026-03-29
  • Anobium

    Anobium - 2026-03-29

    What event will wake the chip? That may help answer.

     
  • Keith

    Keith - 2026-03-29

    Yes, that is a problem. it goesn't go to sleep. It becomes Comatosed!.

    I need it come back to life on pressing the encoder switch on PortB.6

    The code is below - Thank you

     
  • Anobium

    Anobium - 2026-03-30

    Try this following to wake.

    // Both edges (most common for buttons/encoders)
    IOCBP6 = 1
    IOCBN6 = 1
    
    ' =============================================
    ' Enable Interrupts
    ' =============================================
    On Interrupt PORTABChange Call Handle_IOC   ' Link IOC interrupt to subroutine
    
    
    // code, lots of it.
    
    
    ' =============================================
    ' Interrupt Service Routine (ISR)
    ' =============================================
    Handle_IOC:
    
        If IOCBF.6 = 1 Then             ' Check if RB6 caused the interrupt
            IOCBF.6 = 0                 ' Clear the flag for RB6
    
        End If
    
    Return
    
     
  • Keith

    Keith - 2026-03-30

    Thank you once again. It works a treat.
    I put the first part of the routine above my main program as:

    ' =============================================
    ' Enable Interrupts sor Sleep Function
    ' =============================================

    // Both edges (most common for buttons/encoders)

    IOCBP6 = 1 ;Required
    IOCBN6 = 1 ;Required

    On Interrupt PORTABChange Call Handle_IOC ' Link IOC interrupt to subroutine

    Main: ;----- start main*******

    and a Sub called Handle_IOC ....
    Calling up that Sub routine when the Main program times out and is inactive

    Sub Handle_IOC ' Link IOC interrupt to subroutine

    Sleep

    ' =============================================
    ' Interrupt Service Routine (ISR)
    ' =============================================
    Handle_IOC:

        If IOCBF.6 = 1 Then             ' Check if RB6 caused the interrupt
         IOCBF.6 = 0                 ' Clear the flag for RB6
    
        End If
    

    End Sub

    As I said it works really well downing the current to a couple of uA's

    Thank you

     

Log in to post a comment.

MongoDB Logo MongoDB