help: countdown with timer0 interrupt


Closed Thread
Results 1 to 13 of 13

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    While the PIC is sleeping Timer0 will be off since on-chip clocks are shut down. You could
    use Timer1, but you would need an extermal clock during sleep.

    If it will be awake during your 5 minute time period, you could use the compare module set
    to reset Timer1 on each match. Load CCPR1L and CCPR1H with 62,500, set a prescaler of
    1:16, and it will interrupt every 500mS + automatically reset Timer1 to 0.

    Then you can just increment a variable in your int handler until your delay period is reached.
    This is a lot easier than reloading a timer in an int handler - or fiddling with adjustments to
    reload values compensating for code overhead.
    Regards,

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

  2. #2
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by Bruce View Post
    While the PIC is sleeping Timer0 will be off since on-chip clocks are shut down. You could
    use Timer1, but you would need an extermal clock during sleep.

    If it will be awake during your 5 minute time period, you could use the compare module set
    to reset Timer1 on each match. Load CCPR1L and CCPR1H with 62,500, set a prescaler of
    1:16, and it will interrupt every 500mS + automatically reset Timer1 to 0.

    Then you can just increment a variable in your int handler until your delay period is reached.
    This is a lot easier than reloading a timer in an int handler - or fiddling with adjustments to
    reload values compensating for code overhead.
    You pointed out something I just read this afternoon: timer0 is frozen, which is a problem as I use "@ SLEEP" !!
    Well, my idea is to use the folowing parameters:
    With a TMR0 preset to 176 and a prescaler of 256 it will interrupt every 10ms.
    When in my lasergame program player health points drop below 0, it sets a variable (BIT) called CRITICAL to 1 and enable TMR0 interrupts.
    The routine handling the TMR0 interrupt would increment a counter variable and then it would go back to my main loop and... uh... go to sleep, disabling the timer...
    But, if I write (preseting CRITICAL to 0):

    (program starts here)
    loop:
    if (countdown == 1) THEN
    PAUSEus 15 'shortest pause I can use with a 8MHz clock
    ELSE
    @ SLEEP
    ENDIF
    Goto loop


    Then when my countdown in the INT handler reaches the desired value, I disable the INT for TMR0 and set CRITICAL to 0 so the main loop will behave as it should: have a sleep when the INT handler has been processed.
    My question is: when sleeping, the interrupt will be handled then MCU will go back to "goto loop" or will it continue the "@ sleep"?????

Similar Threads

  1. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 09:00
  2. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 02:35
  3. Sleep Mode
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th March 2008, 10:31
  4. Ping Darrel Taylor - Timer0 Instant Interrupt
    By JEC in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 9th January 2007, 11:20
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

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