'628 tmr1 interrupts


Closed Thread
Results 1 to 2 of 2
  1. #1
    jpeakall's Avatar
    jpeakall Guest

    Default '628 tmr1 interrupts

    Hi,

    I posted this to the piclist, but thought (hoped!) I might get a faster reply here. I have been learning how to use the interrupts on a '628. I have it working, sort of. I want to have the interrupt occur when tmr1 overflows. The code I am using is:

    @ DEVICE HS_OSC,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF
    DEFINE OSC 20 ' We're using a 20MHz crystal

    ATN con 254 'prefix value for LCD addresses
    CLR con 1 'LCD clear command
    line2 con 192 'Address for 1st char of second line

    rawCount var word
    tmra var rawcount.lowbyte
    tmrb var rawcount.highbyte
    i var byte

    pause 1000
    SEROUT2 portb.0,16468,[atn,CLR] 'Clears LCD
    pause 10
    serout2 portb.0,16468,[ "Initializing.."]
    pause 1000
    SEROUT2 portb.0,16468,[atn,CLR] 'Clears LCD

    intcon = %01000000
    pie1 = 1
    pir1 =1
    on interrupt goto int
    enable


    tmr1l =0
    tmr1h =0
    T1CON = %00000101
    pauseus 400


    loop:
    input portb.3

    goto loop

    int:
    disable
    T1CON = %00000000
    tmra = tmr1l
    tmrb = tmr1h
    serout2 portb.0,16468,["TIMER: ",dec rawcount]
    pause 500
    SEROUT2 portb.0,16468,[atn,CLR]
    pause 1000
    tmr1l =0
    tmr1h =0
    T1CON = %00000101
    pauseus 400
    enable
    resume


    With this code, I alwats get a result of 2007. The 2000 is from the 400us pause. The 7 would be about what I expect the loop to take. Why is it immedailty jumping out of the loop insted of waiting for timr1 to roll over?

    Thanks,

    Jonathan

    www.madlabs.info

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


    Did you find this post helpful? Yes | No

    Default

    By setting PIR1 = 1 you are setting the TMR1IF interrupt flag (PIR1.0). So it doesn't wait for the timer to overflow, it just goes straight to the interrupt routine.

    Then once in the interrupt code, it gets caught in an endless loop because the TMR1IF never gets reset. The 2000 count is actually from the 400us pause in the interrupt routine, +7 for the resume and repeat interrupt call.

    So, change PIR1 = 1 to PIR1 = 0 Then add the same line "PIR1=0" to the end of the interrupt routine, to reset the interrupt flag before resume.

    Or, to be more precise, PIR1.0 = 0

    HTH

Similar Threads

  1. Instant Interrupts - Revisited
    By Darrel Taylor in forum Code Examples
    Replies: 772
    Last Post: - 17th February 2016, 22:14
  2. Clock using Instant Interrupts
    By PICpocket in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th February 2009, 21:43
  3. Microcode studio - PIC16F877A Interrupts
    By mcbeasleyjr in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th January 2009, 06:10
  4. DT's Instant Interrupts trouble
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th November 2008, 20:48
  5. help: TMR0 interrupts disabling PORTAchange interrupts???
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th August 2008, 15:10

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