Multi timer interrupt question


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2007
    Posts
    59

    Default Multi timer interrupt question

    I'm going to use Darrel Taylor's interrupt program and want to run 2 separate timers. So when input 1 is on the timer starts and runs and can be reset. While it's timing I want to turn different lights on/off depending on how long the input has been on.

    I then want to do the same with a second input.

    I'm looking through all the paperwork (trying to RTFM) and I see the Gosub ResetTime and Gosub StartTimer commands. This is from the "Timers, Clocks, RTC's: Elapsed Timer Demo"

    And I also see from Darrel's page that there are up to 4 timers in the Elapsed.bas.

    What are the commands to start and reset the individual timers?

    I've been searching the forum and Darrel's site and haven't seen or have overlooked this information.

    Thank you,
    Hylan

  2. #2
    Join Date
    Sep 2007
    Posts
    59


    Did you find this post helpful? Yes | No

    Default Re: Multi timer interrupt question

    I'm trying to start with just getting one timer to work and do the usual "Flash an LED", or actually toggle between 2 LED's so I can tell where in the timing sequence it is. With what I have below, LED2 is on at startup and then it switches to LED1 and never toggles again. I think I have something wrong in my setup but don't know what. Once I get this working I would like to add the TMR1 (TimerB).

    Any help is appreciated.
    Thank you,
    Hylan
    Here's the code:
    Code:
    '****************************************************************
    '*  Name    : TimerTest.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2012 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 12/9/2012                                         *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    #config
     __CONFIG _CONFIG1H, _OSCS_OFF_1H & _OSC_XT_1H
     __CONFIG _CONFIG2L, _BOR_ON_2L & _BORV_27_2L & _PWRT_ON_2L
     __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H
     __CONFIG _CONFIG3H, _CCP2MUX_OFF_3H
     __CONFIG _CONFIG4L, _LVP_OFF_4L 
    #endconfig
    '**************************************************************
    'Interrupt code added 12-9-12
    INCLUDE "DT_INTS-18.bas"     ; Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas"     ; Include if using PBP interrupts
    INCLUDE "Elapsed_INT-18.bas"  ; Elapsed Timer Routines
    
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            ;INT_Handler    RX_INT,    _serialin,   PBP,  no        
            ;INT_Handler    INT_INT,  _ToggleLED1,   PBP,  yes
            INT_Handler   TMR0_INT,  _TimerA,   PBP,  yes
            ;INT_Handler   TMR1_INT,  _TimerB,   PBP,  yes
        endm
        INT_CREATE                ; Creates the interrupt processor
    ENDASM
    
    T0CON  = %10010010             ; T0 = 16-bit, Prescaler 8
    ;@   INT_ENABLE   RX_INT     ; enable external (INT) interrupts  
    ;@    INT_ENABLE   INT_INT     ; enable external (INT) interrupts
    @    INT_ENABLE  TMR0_INT     ; enable Timer 0 interrupts
    ;@    INT_ENABLE  TMR1_INT     ; Enable Timer 1 Interrupts  
    
    CLEAR   ' Clear all variables to 0
    
    LED1        VAR PortC.5     ' Output 1 
    LED2        VAR PortC.4      
    IN1         VAR PortE.0     ' Input 1 
    Counter     var byte        ' Keeps count of seconds 
                      
    PortA   =   %00100000       ' PortA All Off 
    PortB   =   %00000000       ' PortB All Off
    PortC   =   %00000000       ' PortC All Off
    PortD   =   %00000000       ' PortD All Off
    PortE   =   %00000000       ' PortE All Off
    PortF   =   %00000000       ' PortF All Off
    PortG   =   %00000000       ' PortG All Off
    TRISA   =   %00011001       ' Inputs = 1, Outputs = 0 RA(7-6) NA
    TRISB   =   %11111111       ' Inputs = 1, Outputs = 0
    TRISC   =   %10000010       ' Inputs = 1, Outputs = 0
    TRISD   =   %11111111       ' Inputs = 1, Outputs = 0
    TRISE   =   %11111111       ' Inputs = 1, Outputs = 0
    TRISF   =   %11111111       ' Inputs = 1, Outputs = 0
    TRISG   =   %00000000       ' Inputs = 1, Outputs = 0 RG(7-5) NA
    ADCON0  =   %00000001       ' A/D Enabled, Channel 0 (AN0)
    ADCON1  =   %00001110       ' AN0 Analog Input (Rest Digital I/O)
    ADCON2.7 = 1                ' Right Justify 10 Bit Word
    CMCON   =   %00000111       ' Both Comparators Disabled
    INTCON2.7 = 0               ' Turn ON PortB Pull-Ups
    T1CON   =   %00110100       ' 1:8 Prescale, T1OSCEN Off (524.288mS)
    
    GOSUB ResetTime               ; Reset Time to  0d-00:00:00.00    
    GOSUB StartTimer              ; Start the Elapsed Timer
    
    Main:
    pause 200
    if (Counter > 0) and (Counter < 10) then
    LED1 = 1
    LED2 = 0
    else 
    LED1 = 0
    LED2 = 1
    endif
    
    goto Main
    
    TimerA:
    if SecondsChanged = 1 then
        SecondsChanged = 0
        Counter = Counter + 1
            If Counter = 20 then
            Counter = 0
            endif
    endif                            
    @ INT_RETURN
    Last edited by Hylan; - 9th December 2012 at 19:42. Reason: changed code post

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Multi timer interrupt question

    Hylan,

    The Elapsed Timer only works with Timer1.
    And there is only one Elapsed Timer.
    That's not to say you couldn't write a program to do multiple Elapsed Timers.

    The INT_HANDLER for TMR1_INT has to point to the _ClockCount routine in the include file.

    Code:
            INT_Handler   TMR1_INT,  _ClockCount,   PBP,  yes
    DT

Similar Threads

  1. interrupt timer???
    By reik6149 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th September 2010, 11:32
  2. Timer interrupt 16F1827
    By Macgman2000 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 23rd July 2010, 20:19
  3. How to set interrupt for Timer 0
    By chai98a in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 18th November 2006, 00:14
  4. Multi Interrupt How To ?
    By capitano in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd February 2005, 14:48
  5. Timer 1 Interrupt
    By tjstevens in forum General
    Replies: 4
    Last Post: - 29th November 2004, 09:14

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts