interrupt timer???


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2010
    Posts
    8

    Default interrupt timer???

    hi all, i am a newbie for picbasic, have a question regarding to my final year project, hope the pros can help me =)

    the question is : is it posible to run 2 routine at the same time ?

    basically i want a routine to measure the time between my sensor interrupt, and another routine running a series of LED, the process are as below:


    interupt : sensor pass thru <--- when sensor pass thru then interrupt jump to here
    off all led
    timer1 stop and save the value
    timer1 start count the time between the sensor pass thru

    led1 on
    pause 1000
    led2 on
    pause 1000
    led3 on
    pause 1000
    led4 on
    pause 1000

    from the process above, the timer1 is counting the value, and the leds is still on at the same time.

    is the process above posible? can anyone give me the clue or code related? =)

    thank you very much =)
    Last edited by reik6149; - 11th September 2010 at 07:31.

  2. #2
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Welcome to the forum reik6149. You can run multiple interrupts at the same time, making it appear as the chip is doing multiple things at once.

    The easiest way to get started in interrupts, is to use DT_INTS or instant interrupts. This is an include file that simplifies the use of interrupts. It can be found here: http://darreltaylor.com/DT_INTS-14/intro.html
    You will notice a hello world, a blinky, and an elapsed timer. And also a combine all three. This is similar to what you are doing. Get comfortable setting all three of these, then see if you can figure out what you want your project to do.
    http://www.scalerobotics.com

  3. #3
    Join Date
    Sep 2010
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    thx for scalerobotics's kindly reply =)

    by the way,after i read thru the website,i still cant get the point. Perhaps i do not have the basic knowledge about something like option_reg or t1con. i think i have to read the basic 1st.
    =(

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    ASM interrupts are good, Darrel's instantaneous ones are best...

    But for starters look at ON INTERRUPT in the PBP manual and INTCON in the chips data sheet.

    BTW, what chip are you playing with?
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Sep 2010
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    sorry guys, im really cant understand what darrel did, from this page http://darreltaylor.com/DT_INTS-14/elapsed.html

    how the program know when start button is interrupted??

    in wat condition the program will

    gosub starttime and gosub resettime??

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Default

    Hi, reik

    Your scenario reminds me a "Thunderstrike distance measurer" ... ( sorry for the Tool name ... I am French ... )

    so, if I understand it right ... the time between two interrupts could be many seconds ... ( 4 in your example ).

    Consider a Pic Timer itself ( Timer1 ...i.e.) can count up to 0.52s @ 4Mhz clock ... so, you have to use an extra counter that will count Timer 1 Overflows.

    your time will be ( 0.52s x nb of overflows ) + ( Timer1 x 8µs )
    distance will be ... 330 ( or SQR ( 1.3*287*(Temp+273.15)) ... x count (s)

    see Here for Timer calculations help :
    http://pictimer.picbingo.com/index.php

    BUT, you first have to open your pic datasheet to learn about the Timer modules and CCP module ( capture mode ) use.

    Darrel's Interrupts just are the easy tool to drive the interrupts ... but it is you to configure what happens during the interrupts ...

    The process is the same for pulse duration measuring, Rpm meters, shotshells speed measuring ...

    Just need to know the maximum time between interrupts ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7
    Join Date
    Sep 2010
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    HI everyone, although im nt understand the code, but im trying to modify the code to my desire code. Hope to pros 1 can help me to debug =)
    '* Name : Elapsed_INT.bas
    ; syntax = Handler IntSource, Label, Type, ResetFlag?
    DEFINE Elapsed_Handler TMR1_INT, _ClockCount, PBP, yes

    Ticks var word ' 1/100th of a second (10ms) <--- how to change to 1ms ?

    BitSave VAR BIT

    '''''Goto OverElapsed <---- ????
    ' ------------------------------------------------------------------------------
    Asm
    IF OSC == 4 ; Constants for 100hz interrupt from Timer1
    TimerConst = 0D8F7h ; Executed at compile time only
    EndIF
    If OSC == 8
    TimerConst = 0B1E7h
    EndIF
    If OSC == 10
    TimerConst = 09E5Fh
    EndIF
    If OSC == 16
    TimerConst = 063C7h
    EndIF
    If OSC == 20
    TimerConst = 03CB7h
    EndIF

    ; ----------------- ADD TimerConst to TMR1H:TMR1L
    ADD2_TIMER macro
    CHK?RP T1CON
    BCF T1CON,TMR1ON ; Turn off timer
    MOVLW LOW(TimerConst) ; 1
    ADDWF TMR1L,F ; 1 ; reload timer with correct value
    BTFSC STATUS,C ; 1/2
    INCF TMR1H,F ; 1
    MOVLW HIGH(TimerConst) ; 1
    ADDWF TMR1H,F ; 1
    endm

    ; ----------------- ADD TimerConst to TMR1H:TMR1L and restart TIMER1 ----------
    RELOAD_TIMER macro
    ADD2_TIMER
    BSF T1CON,TMR1ON ; 1 ; Turn TIMER1 back on
    endm

    ; ----------------- Load TimerConst into TMR1H:TMR1L --------------------------
    LOAD_TIMER macro
    MOVE?CT 0, T1CON,0
    MOVE?CB 0, TMR1L
    MOVE?CB 0, TMR1H
    ADD2_TIMER
    endm
    EndAsm


    ' ------[ This is the Interrupt Handler ]---------------------------------------
    ClockCount:
    @ RELOAD_TIMER ; Reload TIMER1
    Ticks = Ticks + 1
    if Ticks = 65535 then
    Ticks = 0

    endif

    @ INT_RETURN ; Restore context and return from interrupt

    '-----====[ END OF TMR1 Interrupt Handler ]====---------------------------------

    interrupt:
    '
    ' Restart counting
    Tsensor = ticks ; Save the timing between sensor pass through
    BitSave = T1CON.0 ; Save TMR1ON bit
    @ LOAD_TIMER ; Load TimerConst
    T1CON.0 = BitSave ; Restore TMR1ON bit
    Ticks = 0

    return
    define LOADER_USED 1
    define OSC 20

    include "DT_INTS-14.bas"
    INCLUDE "ReEnterPBP.bas"
    INCLUDE "Elapsed_INT.bas"

    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler TMR1_INT, _ClockCount, PBP, yes
    endm
    INT_CREATE ; Creates the interrupt processor

    INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts
    ENDASM

    T1CON.1 = 0 ; (TMR1CS) Select FOSC/4 Clock Source
    T1CON.3 = 0 ; (T1OSCEN) Disable External Oscillator
    T1CON.0 = 1 ; (TMR1ON) Start TIMER1

    Main:

    LCDout $FE,$C0, de5 ticks

    GOTO Main


    but i really dont understand, i have the INTERRUPT: subroutine, but how the system knows when my sensor is falling edge, it will getting interrupt and jump to this subroutine??

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