Time to wake up! (SLEEP issue)


+ Reply to Thread
Results 1 to 11 of 11

Thread: Time to wake up! (SLEEP issue)35 days old

  1. #1
    Junior Member davroski's Avatar
    Join Date
    Mar 2019
    Posts
    18
    Thumbs Up
    Received: 0
    Given: 2
    Total Downloaded
    345.98 MB

    0 Not allowed!

    Default Time to wake up! (SLEEP issue)

    Hi,
    I'm using a 16F18344 PIC with comparator C1 in use.
    I want to put the PIC to sleep and be woken up by activity from C1.
    I don't need an ISR so I don't think I need to set GIE

    PIC very sleepy - he won't wake up!
    (how do I know? - a test port is set to toggle within loop. Port toggles ok when 'sleep' remmed out.)

    code used:

    Code:
    main:
    '   ------------ interrupts --------------
        PIR2.5 = 0      ' clear any C1 interrupt flag
        INTCON.6 = 1    ' enable PEIE peripheral interrupts
        'intcon.7 = 1    ' Global interrupt enable - may not be needed. Doesn't fix if set anyway.
        PIE2.5 = 1      ' enable C1 peripheral interrupt
        PIE0.0 = 1       'Enables the INT external interrupt (not sure if relevant)
         
         '--------MAIN LOOP------------------
        Sleep
        'etc
    Last edited by joesaliba; 19th October 2019 at 08:05.

Attention

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

The advertisements we display are relevant to this web site and your browsing history

Please consider supporting us by disabling your ad blocker.


Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues


Thank you for your attention.

  • #2
    Prolific Poster RGV250's Avatar
    Join Date
    Aug 2005
    Posts
    2,326
    Thumbs Up
    Received: 29
    Given: 7
    Total Downloaded
    802.58 MB

    0 Not allowed!

    Default Re: Time to wake up! (SLEEP issue)

    Hi,
    I have never used sleep but looking at the compiler manual it appears straightforward. Have a look at the example in the manual and try that first, once you have that working it should be a simple task to modify it for the comparator.

    Regards,
    Bob

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #3
    Senior Member Stephen Moss's Avatar
    Join Date
    Jan 2006
    Posts
    505
    Thumbs Up
    Received: 30
    Given: 7
    Total Downloaded
    3.72 GB

    0 Not allowed!

    Default Re: Time to wake up! (SLEEP issue)

    It would help if you posted your entire code (including Configuration fuses) as sometimes the issue may not lie where you think it does and so without the entire code it may prove difficult to resolve the problem.
    For example your CMxCON0 settings may not be correct but as you have not included them we cannot tell, it is also unclear as to whether you are using the comparator interrupt to wakes from sleep or are trying to read the comparator output in another pin, although as you don't say you need and ISR I suspect the latter in which case how would the input be read if the PIC is asleep?

    I think I only ever put a device to sleep one so am no expert on it however try looking at this as a possible source of the problem...
    The note in section 18.2.2 states "The internal output of the comparator is latched with each instruction cycle."
    Section 18.4.1 states that "The output from a comparator can be synchronized with Timer1 by setting the CxSYNC bit of the CMxCON0 register. Once enabled, the comparator output is latched on the falling edge of the Timer1 source clock."
    Section 18.11 states "The comparator module can operate during Sleep. The comparator clock source is based on the Timer1 clock source. If the Timer1 clock source is either the system clock (FOSC) or the instruction clock (FOSC/4), Timer1
    will not operate during Sleep, and synchronized comparator outputs will not operate.

    Therefore, if you are not using the comparator interrupt to wake the PIC and have not already done so I suggest setting the CxSYNC bit of the CMxCON0 register to 0 for asynchronous output and see if that has any effect.
    If you are using the comparator interrupt to wake from sleep then ensure you have set the relevant register bits listed in section 18.5 correctly, whenever you interrupts you should have an IRS as at the very least you use it to clear the interrupt bit so that the next interrupt can be detected.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #4
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,214
    Thumbs Up
    Received: 74
    Given: 180
    Total Downloaded
    5.15 GB

    0 Not allowed!

    Default Re: Time to wake up! (SLEEP issue)

    What are you comparing? I've had sleeping PIC devices working by

    Code:
        ' Note! don't mess with weak pull ups - or the exit sleep condition will never happen
        '
        IOCA = %00110101                ' A5, A4, A2 and A0
        IOCB = %10100000                ' B7 and B5
        SBOREN = 0
        RBIF = 0                        ' jic
        RABIE = 1                       ' enable ioc interupt
        Sleep
        '
        ' we will stick here till a switch is pressed
        '
        RABIE = 0                       ' disable ioc interupt
        SBOREN = 1
        RBIF = 0                        ' jic
        IOCA = %00000000                ' A5, A4, A2 And A0
        IOCB = %00000000                ' B7 and B5
    Keys where attached to A5, A4, A2, A0, B7 and B5 running on 16F690
    George.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #5
    Junior Member davroski's Avatar
    Join Date
    Mar 2019
    Posts
    18
    Thumbs Up
    Received: 0
    Given: 2
    Total Downloaded
    345.98 MB

    0 Not allowed!

    Default Re: Time to wake up! (SLEEP issue)

    Hi
    Comparator settings:

    Code:
      '---------comparator----------------    'comparator  C1
         CM1CON0.7 = 1  ' comparator enabled
         CM1CON0.6 = 1  ' inverted polarity
         CM1CON0.4 = 1  ' output inverted
         
         CM1CON1 = %00110000  ' Allocate FVR to COMP1 positive input
         FVRCON = %10001000   ' FVR enabled and gain set to X2 (2.048V)
         
         
         'Direct RA4 to handle the output of the C1 comparator 10110
         RA4PPS.4 = 1
         RA4PPS.3 = 0
         RA4PPS.2 = 1
         RA4PPS.1 = 1
         RA4PPS.0 = 0
    Last edited by joesaliba; 19th October 2019 at 08:06.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #6
    Junior Member davroski's Avatar
    Join Date
    Mar 2019
    Posts
    18
    Thumbs Up
    Received: 0
    Given: 2
    Total Downloaded
    345.98 MB

    0 Not allowed!

    Default Re: Time to wake up! (SLEEP issue)

    Hi
    Thanks for the detailed reply.

    COMP1 is set to FVR at 2.048V with output PPS'd to RA4 (this works as expected when awake)
    see settings below

    Figure 18.2 in data sheet DS40001800D-page 183 suggests the interrupt flag is port independent. I don't think there's any chicken and egg clock dependency but obviously i'm wrong somewhere!

    settings as below:

    Code:
    '   ------------ interrupts --------------
        PIR2.5 = 0      ' clear any C1 interrupt flag
        INTCON.6 = 1    ' enable PEIE peripheral interrupts
        'intcon.7 = 1   ' Global interrupt enable - may not be needed. Doesn't fix if set anyway.
        PIE2.5 = 1      ' enable C1 peripheral interrupt
        PIE0.0 = 1      ' Enables the INT external interrupt (not sure if relevant)
     
    ;-------------------------------------------------------------------------------
    ;**** Added by Fuse Configurator ****
    ; Use the Fuse Configurator plug-in to change these settings
    
    
    Device = 16F18344
    
    
    Config1 FEXTOSC_OFF, RSTOSC_HFINT32, CLKOUTEN_OFF, CSWEN_OFF, FCMEN_OFF
    Config2 MCLRE_OFF, PWRTE_OFF, WDTE_OFF, LPBOREN_OFF, BOREN_OFF, BORV_HIGH, PPS1WAY_OFF, STVREN_ON, DEBUG_OFF
    Config3 WRT_OFF, LVP_OFF
    Config4 CP_OFF, CPD_OFF
    
    
    ;**** End of Fuse Configurator Settings ****
    ;-------------------------------------------------------------------------------
    
    Comparator settings:
        '---------comparator----------------
        'comparator  C1
         CM1CON0.7 = 1  ' comparator enabled
         CM1CON0.6 = 1  ' inverted polarity
         CM1CON0.4 = 1  ' output inverted
         
         CM1CON1 = %00110000  ' Allocate FVR to COMP1 positive input
         FVRCON = %10001000   ' FVR enabled and gain set to X2 (2.048V)
         
         '(default CM1CON1.5-3 = 000  C1VP to C1IN0+ pin 19 RA0)
         '(default CM1CON1.2-0 = 000  C1VN To C1IN0- pin 18 RA1)
    
    
         
         'Direct RA4 to handle the output of the C1 comparator 10110
         RA4PPS.4 = 1
         RA4PPS.3 = 0
         RA4PPS.2 = 1
         RA4PPS.1 = 1
         RA4PPS.0 = 0
    Last edited by joesaliba; 19th October 2019 at 08:04.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #7
    Senior Member tumbleweed's Avatar
    Join Date
    May 2011
    Posts
    485
    Thumbs Up
    Received: 59
    Given: 0
    Total Downloaded
    330.54 MB

    0 Not allowed!

    Default Re: Time to wake up! (SLEEP issue)

    There are a few things missing, such as selecting either rising or falling edge for the comparator intr

    Here are some suggestions...
    Code:
    ;-------------------------------------------------------------------------------
    ;**** Added by Fuse Configurator ****
    ; Use the Fuse Configurator plug-in to change these settings
    
    Device = 16F18344
    
    Config1 FEXTOSC_OFF, RSTOSC_HFINT32, CLKOUTEN_OFF, CSWEN_OFF, FCMEN_OFF
    Config2 MCLRE_OFF, PWRTE_OFF, WDTE_OFF, LPBOREN_OFF, BOREN_OFF, BORV_HIGH, PPS1WAY_OFF, STVREN_ON, DEBUG_OFF
    Config3 WRT_OFF, LVP_OFF
    Config4 CP_OFF, CPD_OFF
    
    
    ;**** End of Fuse Configurator Settings ****
    ;-------------------------------------------------------------------------------
    
    ' added for DelayUs
    Declare Xtal = 32
    
    '---------comparator----------------
    'comparator C1
    CM1CON0.6 = 1 ' inverted polarity
    CM1CON0.4 = 1 ' output inverted
    
    'CM1CON1.5-3 = 110 C1VP to FVR buffer 2
    'CM1CON1.2-0 = 000 C1VN To C1IN0- pin 18 RA1
    'select either CxINTP OR CxINTN:
    'CM1CON1.6 = 1 C1INTN negative going edge
    'CM1CON1.7 = 1 C1INTP positive going edge
    CM1CON1 = %00110000 ' <<< ADD C1INTx EDGE
    FVRCON = %10001000 ' FVR enabled and gain set to X2 (2.048V)
    
    'set RA1 input to analog mode
    ANSELA.1 = 1
    
    'Direct RA4 to handle the output of the C1 comparator 10110
    RA4PPS.4 = 1
    RA4PPS.3 = 0
    RA4PPS.2 = 1
    RA4PPS.1 = 1
    RA4PPS.0 = 0 
    
    ' allow time for FVR startup (datasheet param Tfvrst = 35us typ)
    DelayUs 50
    
    ' always enable the peripheral last after setup
    CM1CON0.7 = 1 ' comparator enabled
    
    ' now that comparator C1 is setup...
    ' ------------ interrupts --------------
    PIR2.5 = 0 ' clear any C1 interrupt flag
    INTCON.6 = 1 ' enable PEIE peripheral interrupts
    PIE2.5 = 1 ' enable C1 peripheral interrupt
    
    ' do not enable either of these... look at Figure 8-1 Interrupt Logic
    ' INTE doesn't have anything to do with C1INT
    'PIE0.0 = 1 ' Enables the INT external interrupt (not sure if relevant)
    ' only enable GIE if you actually have an ISR and want to get an interrupt
    ' not required for wake from sleep
    'intcon.7 = 1 ' Global interrupt enable - may not be needed. Doesn't fix if set anyway.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #8
    Junior Member davroski's Avatar
    Join Date
    Mar 2019
    Posts
    18
    Thumbs Up
    Received: 0
    Given: 2
    Total Downloaded
    345.98 MB

    0 Not allowed!

    Default Re: Time to wake up! (SLEEP issue)

    Hi tumbleweed,
    I'd missed the positive or negative edge trigger. ANSELA was set - it just missed the code clip.
    Still not working it seems
    (this is supposed to be a port from working code on the 16F628A which is much simpler to configure)
    My current settings and test code is:

    Code:
    '--------PORT SETUP-----------
     
         TRISA = %00001010
         TRISB = %00000000
         TRISC = %00000000          
         
        '---------comparator----------------
        'comparator  C1    
         CM1CON0.6 = 1  ' inverted polarity
         CM1CON0.4 = 1  ' output inverted
         CM1CON1.6 = 1  ' C1INTP negative going edge
         CM1CON1 = %00110000  ' Allocate FVR to COMP1 positive input
         FVRCON = %10001000   ' FVR enabled and gain set to X2 (2.048V)
         ANSELA.1 = 1 'DIGITAL I/O EXCEPT RA1
         
         'Direct RA4 to handle the output of the C1 comparator 10110
         RA4PPS.4 = 1
         RA4PPS.3 = 0
         RA4PPS.2 = 1
         RA4PPS.1 = 1
         RA4PPS.0 = 0
         
         CM1CON0.7 = 1  ' comparator enabled
    
    main:     
        
    '   ------------ interrupts --------------
        PIR2.5 = 0      ' clear any C1 interrupt flag
        INTCON.6 = 1    ' enable PEIE peripheral interrupts
        PIE2.5 = 1      ' enable C1 peripheral interrupt
         
         '--------MAIN LOOP------------------
        Sleep             
        Toggle PORTA.2
        GoTo main
        
        '-------------------------------------------------------------------------------------------
    Last edited by joesaliba; 19th October 2019 at 08:03.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #9
    Senior Member tumbleweed's Avatar
    Join Date
    May 2011
    Posts
    485
    Thumbs Up
    Received: 59
    Given: 0
    Total Downloaded
    330.54 MB

    0 Not allowed!

    Default Re: Time to wake up! (SLEEP issue)

    The order of setting CM1CON1 needs to change... the edge setting is getting over-written
    Code:
    CM1CON1 = 110000 ' Allocate FVR to COMP1 positive input
    CM1CON1.6 = 1 ' C1INTP negative going edge
    or just
    Code:
    CM1CON1 = 110000 ' Allocate FVR to COMP1 positive input, negative edge
    Also, you took out the delayus call from my example. It takes a bit before the FVR stabilizes when you first turn it on.
    Last edited by tumbleweed; 18th October 2019 at 15:31.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #10
    Junior Member davroski's Avatar
    Join Date
    Mar 2019
    Posts
    18
    Thumbs Up
    Received: 0
    Given: 2
    Total Downloaded
    345.98 MB

    0 Not allowed!

    Default Re: Time to wake up! (SLEEP issue)

    Sorry for delay - yes I see my error!
    I'll try it later and report back.

    I omitted the settle time as there is a system-wide settle time that is much longer.

    Many thanks

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #11
    Junior Member davroski's Avatar
    Join Date
    Mar 2019
    Posts
    18
    Thumbs Up
    Received: 0
    Given: 2
    Total Downloaded
    345.98 MB

    0 Not allowed!

    Default Re: Time to wake up! (SLEEP issue)

    Success!

    Sleep is working fine.

    Note to self - do not mix bit and byte directives

    A big thank you to Tumbleweed for your invaluable assistance.

    Dave

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

    Thread Information

    Users Browsing this Thread

    There are currently 1 users browsing this thread. (0 members and 1 guests)

       

    Similar Threads

    1. [SOLVED !] wake from sleep
      By dmTulsa in forum Proton Plus Compiler v3
      Replies: 4
      Last Post: 9th July 2010, 16:57
    2. EUSART asynchronous wake from sleep
      By keystoneclimber in forum Proton Plus Compiler v3
      Replies: 1
      Last Post: 24th June 2009, 09:13
    3. [SOLVED !] SD GPS DATA LOGGER - Sleep but does not Wake
      By ohararp in forum Proton Plus Compiler v3
      Replies: 10
      Last Post: 14th March 2007, 21:45
    4. SD GPS DATA LOGGER - Sleep but does not Wake
      By ohararp in forum Proton Plus Compiler v3
      Replies: 0
      Last Post: 18th November 2006, 01:39

    Members who have read this thread : 39

    Actions :  (Set Date)

    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