Trying to add a sleep function or pretend to sleep


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Which PIC are you using?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  2. #2
    Join Date
    May 2009
    Location
    Montreal, QC, Canada
    Posts
    118


    Did you find this post helpful? Yes | No

    Default

    Sorry about that,

    Using 16F628A

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    One easy way would be to increment a counter variable in your Timer1 int handler, and turn off all LEDs & enter sleep mode once it reaches a certain value.

    During normal operation, reset the counter var in the INT_INT handler.

    Timer1 increments counter on each interrupt, external interrupt clears it. Just monitor the count value in your main loop.

    Just remember that if you enter sleep mode, Timer1 stops unless you have an external crystal for your Timer1 clock source.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  4. #4
    Join Date
    May 2009
    Location
    Montreal, QC, Canada
    Posts
    118


    Did you find this post helpful? Yes | No

    Default

    The problem I have is I can not stop Timer1 because that is where the PWM burst happens.

    If I stop this timer I have no way to wake it up so I can not go in sleep mode.

    I can only get the LEDs off based on a counter and I guess compare it with its own value from the previous loop.

    What I can't figure out is, how many loops I get in one minute? and how much can I count with a word variable?

    Perhaps I need to use nested counters? or is there a better way?

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    A word var can count up to 65,535. If your Timer1 interrupts happen every 20mS, then count up to 3000.

    It won't be right on the money for 1 second with your delays, HPWM, etc, in your Timer1 interrupt handler, but you can adjust for overhead if you need it closer to 1 second exactly.

    You could also use a Timer0 interrupt to increment your counter.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Members who have read this thread : 0

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