16f688 going to sleep issue


+ Reply to Thread
Results 1 to 9 of 9

Thread: 16f688 going to sleep issue21 days old

  1. #1
    Junior Member Tony's Avatar
    Join Date
    Oct 2019
    Posts
    3
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    0

    0 Not allowed!

    Default 16f688 going to sleep issue

    Hi,

    I have been playing with a 16f688 and sleep to reduce power consumption as this will be a device run from a tiny battery.
    Basically, the 16f688 needs to be asleep, then wake up when it see's an incoming 4kbit PWM data stream, it then reads the data, which can be between 2 to 4 bytes long, then depending on the actual data, it will either go back to sleep again, or reply with two or three bytes of data, again at 4kbit pwm.

    I have got it mostly working all the actual code is written and working fine, once asleep, I have used interrupt on change to wake the 16f688 the incoming PWM data provides the interrupt on change, which is again fine, the problem I have is that I need to wake up, deal with the data, then go to sleep.
    The sleep part is the difficult bit, because there may be 2,3 or 4 bytes of incoming pwm data, it is not always the same number of bytes.

    Ideally, I need it to wake from sleep, run my code, for say 200ms then go back to sleep again.
    What I cannot figure is how I get this to happen, I am guessing I need to use a timer somewhere, start the timer when the device wakes from sleep, then when the timer expires go to sleep again, but how would I go about this?

    Any suggestions, I am quite a novice at PIC's and Proton.

    Tony

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
    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: 16f688 going to sleep issue

    Well if you are using Timer 0 you need to configure it by writing to the Option_Reg (see page 47 of the data sheet) as determined by your choice of clock source (Xtal/4 or external) as its speed will determine if you need to use the prescaller or not to slow it down.
    You will also need to need to write to the INTCON register to enable the TMR0 interrupt (T0IE)and the Global Interrupt enable

    Being an 8 bit timer Timer 0 will over flow back to 0 after 255 clock pulse, consequently if your clock source was 1KHz (1mS clock) would would need to write a value of 5 to the TMR0 register (i.e. TMR0 = 5) so that 200mS later it would over flow creating an interrupt.

    See the Proton Manual Instruction for On_Hardware_Interrupt on how to create an interrupt handler.
    Within the interrupt handler you need to clear the Interrupt on change flag (RAIF, i.e. INTCON.0 = 0) and write the required value to the TRM0 register. Unless you have other interrupts running in which case you need to check the INTCON register to see which interrupt has occurred and take the appropriate actions.

    You should then have approximately 200mS for your code to read and process the incoming serial data before the timer interrupt is triggered.

    You could place the code for a Timer 0 interrupt either in you interrupt handler or external at the end of your main loop. If at the end of the main lop something like

    If INCON.3 = 1 then 'check for timer interrupt
    INTOCN.3 = 0 'Clear Interrupt
    SLEEP
    End IF

    If handling the Timer interrupt in your interrupt handler then you would need something like...
    If INTCON.0 = 1 then 'Interrupt On change has occurred
    INCTCON.0 = 0 'clear interrupt
    Else if INTCON.3 = 1 then 'Timer Interrupt has occurred
    Set a variable to 1 that is then checked at the end of your main loop (as above but change "If INTCON.3 = 1" to "If variable = 1" and clear both the variable and INTCON.3) - not good to put the PIC to sleep insider the interrupt handler.
    End IF

    If you want to use the Register Bit names instead of the bit numbers as I have click on the register names in the Code Explorer on the left side of the IDE and then on "Generate and insert code" at the bottom of the pop bit name viewer.
    If you are unable to slow the clock source down enough to use an 8 bit timer then use the 16 bit Timer 1 instead, the setup register and INCTON bits are different but the method is the same.

  • 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
    Junior Member Tony's Avatar
    Join Date
    Oct 2019
    Posts
    3
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    0

    0 Not allowed!

    Default Re: 16f688 going to sleep issue

    Hi Stephen
    Thank you, I will take a good look at what you have suggested, I do not have an interrupt routine at the moment, as the GIE bit isn't set, I just use the PortA.2 inetrrupt on change feature to wake the PIC from sleep.
    What I do want though, is after the device has gone to sleep, that it wakes up and runs the code I have written from the start, i.e. as if it has been reset, is this something that could be achieved in the way you have suggested?

  • 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
    Junior Member keytapper's Avatar
    Join Date
    Jun 2019
    Posts
    81
    Thumbs Up
    Received: 3
    Given: 3
    Total Downloaded
    230.41 MB

    0 Not allowed!

    Default Re: 16f688 going to sleep issue

    If you want to reset after it wakes up you might use the MCLR pin :P
    Otherwise I wrote a discussion.
    So you might try to set a assembly command like GoTo proton#code#start. Just after the sleep command.

  • 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
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,347
    Thumbs Up
    Received: 42
    Given: 39
    Total Downloaded
    3.36 GB

    0 Not allowed!

    Default Re: 16f688 going to sleep issue

    Just enter the Proton command "Reset". This will effectively do a power-up-start.

    If xyz = abc then
    reset
    endif

    Charlie

  • 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 Tony's Avatar
    Join Date
    Oct 2019
    Posts
    3
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    0

    0 Not allowed!

    Default Re: 16f688 going to sleep issue

    Just to thank everyone who replied to my original post, I have now got this all working, I had to use timer 1 as timer 0 didn't give me enough time to process the incoming PWM data.

    Reset didn't work as the 16f688 wasn't compatible with that instruction apparently, so I did the wakeup from sleep like keytapper suggested, by making the next instruction following the sleep instruction pull a port pin low, which I then connected back to the MCLR pin.
    It works perfectly :-)

  • 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
    Junior Member keytapper's Avatar
    Join Date
    Jun 2019
    Posts
    81
    Thumbs Up
    Received: 3
    Given: 3
    Total Downloaded
    230.41 MB

    0 Not allowed!

    Default Re: 16f688 going to sleep issue

    Well, you should not need to use a hardware reset. There's the option to go for the software one.

  • 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
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,215
    Thumbs Up
    Received: 74
    Given: 180
    Total Downloaded
    5.15 GB

    0 Not allowed!

    Default Re: 16f688 going to sleep issue

    I'm pretty sure Reset is an assembler mnemonic not a command and not available on older 16F devices.
    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.

  • #9
    Junior Member keytapper's Avatar
    Join Date
    Jun 2019
    Posts
    81
    Thumbs Up
    Received: 3
    Given: 3
    Total Downloaded
    230.41 MB

    0 Not allowed!

    Default Re: 16f688 going to sleep issue

    Hello George,
    The methods are already cited. But it may take a couple of minutes to add it to the language. Just like to write a procedure
    Code:
    proc Reset()
         asm-
                GoTo proton#code#start
          EndAsm
    EndProc
    
    This is not absolutely certain. I saw the name of beginning program changed some time.
    There might be an option to jump to a specific memory location, but it seems non allowed by the compiler.

  • 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. Time to wake up! (SLEEP issue)
      By davroski in forum Proton Plus Compiler v3
      Replies: 10
      Last Post: 22nd October 2019, 14:14
    2. Sleep and Sleep X[s] not working on 10F200
      By SebaG in forum Proton Plus Compiler v3
      Replies: 19
      Last Post: 29th October 2015, 09:19
    3. frustrations with a 16f688
      By Miles in forum Proton Plus Compiler v3
      Replies: 12
      Last Post: 8th December 2008, 12:30
    4. Sleep and Sleep (time) on 16F877A
      By fgcity in forum Proton Plus Compiler v3
      Replies: 1
      Last Post: 17th September 2008, 20:26
    5. 16F688 bank problem..
      By gpadamsuk in forum Proton Plus Compiler v3
      Replies: 11
      Last Post: 8th May 2007, 22:49

    Members who have read this thread since 17th November 2019, 21:24 : 0

    Actions :  (Set Date)  (Clear 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