Tmr0


Closed Thread
Results 1 to 7 of 7

Thread: Tmr0

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    You need to enable the interrupt.
    Code:
    TRISA = %00010000    ' Set PORTA.4 (TOCKI) to input for timer0
    
       OPTION_REG = %00111000 
       'Transition on TOCKI (RA4), 
       'Increment on falling edge
       'Prescalar assigned to WDT for a 1:1 TMR0 ratio.
       INTCON.2 = 0 ' Clear Timer0 int flag
       INTCON.5 = 1 ' Enable Timer0 int
       TMR0 = $FF   ' Set TMR0 to 255.  So one more tick and TMROIF will be set.
    
       ON INTERRUPT GOTO LapCount
    Main:
       ' Do something here
       goto Main
    
       disable
    LapCount:
       If INTCON.2 = 1 then
       i = i + 1
       endif
       toggle PORTB.3
       TMR0 = $FF      ' Indicate we're in interrupt handler
       INTCON.2 = 0    ' Clear TMR0 Interrupt Flag (Bit 2)
       
       Resume 
       Enable
    Place a 10K pull-up resistor on RA4. Have your input switch ground RA4 when pressed to toggle RB3 (or any available port pin).
    Regards,

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

  2. #2
    laughing-gravy's Avatar
    laughing-gravy Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks for the help Bruce.

    It's working fine now.

  3. #3
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    You need to enable the interrupt.
    Code:
    TRISA = %00010000    ' Set PORTA.4 (TOCKI) to input for timer0
    
       OPTION_REG = %00111000 
       'Transition on TOCKI (RA4), 
       'Increment on falling edge
       'Prescalar assigned to WDT for a 1:1 TMR0 ratio.
       INTCON.2 = 0 ' Clear Timer0 int flag
       INTCON.5 = 1 ' Enable Timer0 int
       TMR0 = $FF   ' Set TMR0 to 255.  So one more tick and TMROIF will be set.
    
       ON INTERRUPT GOTO LapCount
    Main:
       ' Do something here
       goto Main
    
       disable
    LapCount:
       If INTCON.2 = 1 then
       i = i + 1
       endif
       toggle PORTB.3
       TMR0 = $FF      ' Indicate we're in interrupt handler
       INTCON.2 = 0    ' Clear TMR0 Interrupt Flag (Bit 2)
       
       Resume 
       Enable
    Place a 10K pull-up resistor on RA4. Have your input switch ground RA4 when pressed to toggle RB3 (or any available port pin).
    I test and work fine , but i see a problem(
    I connect a button to RA4.When push the button one time the i increment +1 and after release the button the i increment one +1 again.Why;

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


    Did you find this post helpful? Yes | No

    Default

    My guess would be switch bounce. Wait on entry into your interrupt handler for RA4 to return high, or insert a short delay in the beginning of your interrupt handler, and see if that clears up your problem.
    Regards,

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

Similar Threads

  1. 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
  2. TMR0 interrupt and HSERIN
    By boban in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd September 2008, 11:48
  3. help: TMR0 interrupts disabling PORTAchange interrupts???
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th August 2008, 15:10
  4. using TMR0 as a counter..
    By sirvo in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 28th July 2007, 02:56
  5. Strange behaviour from PIC16F877 on TMR0
    By mikebar in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 19th August 2006, 01:31

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