How to set Tmr1 to interrupt every 5 seconds


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2008
    Posts
    21

    Default How to set Tmr1 to interrupt every 5 seconds

    Hi,
    So I'm playing with DT's instant interrupts and even started to modify the T1CON register to adjust the prescaler. I'm using the 16F628A running at 4Mhz so it looks like the maximum time I can get from timer1 is about 0.5s

    4Mhz/4 = 1us * 65535 = 0.0655ms * 8 (max prescaler) = 0.524s and that seems to work as my led blinks around 0.5s ON, 0.5s OFF

    I'm very new to the interrupts and would like to trigger my interrupt if my switch on PortB.0 hasn't been pressed for at least 10 seconds.

    How can I do that?

    Thanks,
    Tom

    Code:
    @ __config _HS_OSC & _WDT_OFF & _MCLRE_ON & _LVP_OFF & _CP_OFF
    SWITCH  VAR PORTB.0
    LED1     VAR  PORTB.1
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  _ToggleLED1,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    T1CON = %00110001            ; Prescaler = 8, TMR1ON
    @ INT_ENABLE  TMR1_INT       ; enable Timer 1 interrupts
    
    Main:
      PAUSE 1
    GOTO Main
    
    '---[TMR1 - interrupt handler]--------------------------------------------------
    ToggleLED1:
         TOGGLE LED1
    @ INT_RETURN

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    One way would be to increase your interrupt rate to once every 50 milliseconds. In your ISR, check for PORTB.0 to be low and increment a counter. If the counter reaches 200, before PORTB.0 goes low, then the button hasn't been pushed for 10 seconds.
    Charles Linquist

Similar Threads

  1. PICs can do more if use others than delays instructions
    By hardcore in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 24th February 2010, 20:52
  2. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 10:00
  3. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 03:35
  4. Interruptus Frustratus
    By Byte_Butcher in forum General
    Replies: 16
    Last Post: - 17th April 2009, 21:36
  5. error on compiling
    By parker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th June 2005, 15:31

Members who have read this thread : 1

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