Interrupt problem.


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2005
    Location
    Up the bush, Western Plains, NSW Au
    Posts
    216

    Default Interrupt problem.

    G'day all you smart people. Would someone be so kind as to help me out with an interrupt (and Timer1) problem. Sometimes we old blokes get caught up with all this new technology.
    I have been playing with PICs for a few years, but this is the first time I have used interrupts or Timer1.
    This is the reelvent code:


    Blah, Blah, usual setup stuff here.


    T1CON = %00111001 '1:8 prescaler

    PRESET = 12000

    'This should load the counter
    'ELAPSED = 0
    MAINLOOP:
    T1CON.0 = 0 'stop the clock
    TMR1H = PRESET.highbyte 'RELOAD THE COUNTER
    TMR1L = PRESET.Lowbyte ' "
    T1CON.0=1 'START THE CLOCK
    PIR1.0=0
    ON INTERRUPT GOTO TICKER
    PIE1.0=1
    INTCON.6=1
    INTCON.7=1
    LCDOUT $fe,1, elapsed 'this is only for seeing what happens - 'NOT required in final
    TOGGLE PORTB.5 'nor this bit
    ELAPSED = ELAPSED + 1

    GOTO MAINLOOP

    DISABLE
    TICKER:
    T1CON.0 = 0 'stop the clock
    TMR1H = PRESET.highbyte
    TMR1L = PRESET.Lowbyte
    'PAUSE 1000
    'toggle portb.5 'same as above note
    T1CON.0=1
    PIR1.0=0



    RESUME
    ENABLE

    OK, when I look at the LCD and Portb.5 in the mainloop, the port line toggles OK, the LCD is too fast to read, but something is on the display, just can't see it.....So far so good.
    When I disable the LCD and port in mainloop and enable it in the interrupt loop, the port line does not toggle, neither does the LCD show anything.
    Quite obviously the thing is not jumping to the interrupt handler, or an interrupt is not being generated.
    I have to ask someone for some help, as I ain't got any hair left to pull out. Been working on this now for 3 nights.........

    Thank you, in advance,
    Peter Moritz.

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


    Did you find this post helpful? Yes | No

    Default

    Hi Peter,

    Looks like you're reloading timer1 before it can over-flow (not sure without knowing the osc speed), but try something like this.
    Code:
    PRESET  VAR WORD
    ELAPSED VAR BYTE
    PRESET = 12000 
    
        T1CON=%00110000  ' Set timer1 prescaler as 1:8
        PIR1.0=0	       ' Clear timer1 overflow flag		
        PIE1=%00000001      ' Enable interrupt on timer1 overflow	
        TMR1H=PRESET.highbyte  ' Load timer1 high byte
        TMR1L=PRESET.Lowbyte  ' Load timer1 low byte
        T1CON.0=1               ' Turm on timer1
        INTCON=%11000000   ' Global & peripheral interrupts enabled
      	
        ON INTERRUPT goto TICKER
        
    MAINLOOP:
        TOGGLE PORTB.5
        ELAPSED = ELAPSED + 1
        GOTO MAINLOOP
        
        DISABLE
    TICKER:
        TOGGLE PORTB.0          ' Toggle PORTB.0
        TMR1H = PRESET.highbyte ' Load timer1 high byte
        TMR1L = PRESET.Lowbyte  ' Load timer1 low byte
        PIR1.0=0                ' Clear TMR1 overflow flag
        RESUME
        ENABLE
    
        END
    HTH....;o}
    Last edited by Bruce; - 12th August 2005 at 17:26.
    Regards,

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

  3. #3
    Join Date
    Jun 2005
    Location
    Up the bush, Western Plains, NSW Au
    Posts
    216


    Did you find this post helpful? Yes | No

    Thumbs up

    Yeah, Thanks Bruce, that done it.
    Isn't it amazing, once again my problem was so simple that I couldn't see it for trying. Makes me feel like a bloody idiot, (as is usual with my little errors) when that happens. The theory was right, just the placement wrong. Anyway, thanks a lot Bruce for your assistance.
    Regards,
    Peter Moritz.

Similar Threads

  1. problem using GOSUB under interrupt
    By fobya71 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 5th March 2010, 19:52
  2. Problem with Interrupt on PIC18F4620 PORTB
    By rookie in forum Off Topic
    Replies: 1
    Last Post: - 22nd March 2007, 01:34
  3. Interrupt Problem
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th November 2005, 20:58
  4. Interrupt stack overflow problem with Resume {label}
    By Yuantu Huang in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 3rd May 2005, 01:17
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

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