tmr2 interrupt problem


Results 1 to 28 of 28

Threaded View

  1. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    TRY
    Code:
            @ __CONFIG  _INTRC_OSC_NOCLKOUT & _MCLRE_ON  &  _LVP_OFF & _WDT_OFF & _PWRTE_ON  & _BODEN_ON  
    
            CMCON=7
            TRISA=0
            TRISB=0
            PORTA=0
            PORTB=0
          
            PIE1 =  %00000010
                    '0------- Disable EE write complete interrupt
                    '-0------ Disable comparator interrupt
                    '--0----- Disable USART receive interrupt
                    '---0---- Disable USART transmit interrupt
                    '----x--- unimplemented
                    '-----0-- Disable CCP1 interrupt
                    '------1- Enable TMR2 to PR2 match interrupt
                    '-------0 Disable TMR1 overflow interrupt
                    
            T2CON = %00000010
                    'X------- Unimplemented
                    '-0000--- postscale 1:1
                    '-----0-- Timer2 off
                    '------10 prescaler 1:16
                    
                            
            GIE     VAR INTCON.7
            PEIE    VAR INTCON.6
            TMR2IF  VAR PIR1.1
            TMR2ON  VAR T2CON.2
            RELOAD CON 131
            
            ON INTERRUPT GOTO ISR
            TMR2 = RELOAD
            PR2 = 0
            PEIE = 1    ' Enable peripheral interupt
            GIE = 1     ' enable Global interrupt
            TMR2ON = 1  ' TMR2 ON
            GOTO LOOP                
    
            disable
    ISR:
            TOGGLE PORTB.0
            TMR2ON = 0
            TMR2 = RELOAD
            TMR2ON = 1
            TMR2IF = 0  ' Clear interrupt flag
            resume
            enable
            
    LOOP:
            'TOGGLE PORTB.1
            GOTO LOOP
    or another variant of
    Code:
            @ __CONFIG  _INTRC_OSC_NOCLKOUT & _MCLRE_ON  &  _LVP_OFF & _WDT_OFF & _PWRTE_ON  & _BODEN_ON  
    
            CMCON=7
            TRISA=0
            TRISB=0
            PORTA=0
            PORTB=0
          
            PIE1 =  %00000010
                    '0------- Disable EE write complete interrupt
                    '-0------ Disable comparator interrupt
                    '--0----- Disable USART receive interrupt
                    '---0---- Disable USART transmit interrupt
                    '----x--- unimplemented
                    '-----0-- Disable CCP1 interrupt
                    '------1- Enable TMR2 to PR2 match interrupt
                    '-------0 Disable TMR1 overflow interrupt
                    
            T2CON = %00000010
                    'X------- Unimplemented
                    '-0000--- postscale 1:1
                    '-----0-- Timer2 off
                    '------10 prescaler 1:16
                    
                            
            GIE     VAR INTCON.7
            PEIE    VAR INTCON.6
            TMR2IF  VAR PIR1.1
            TMR2ON  VAR T2CON.2
            
            ON INTERRUPT GOTO ISR
            PR2 = 124   ' load period register for 2mSec 
            PEIE = 1    ' Enable peripheral interupt
            GIE = 1     ' enable Global interrupt
            TMR2ON = 1  ' TMR2 ON
            GOTO LOOP                
    
            disable
    ISR:
            TOGGLE PORTB.0
            TMR2IF = 0  ' Clear interrupt flag
            resume
            enable
            
    LOOP:
            'TOGGLE PORTB.1
            GOTO LOOP
    The second one is probably the best method to deal with Timer2. have a look to section 6.0 of your datasheet.
    Last edited by mister_e; - 27th December 2007 at 20:07.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Problem with Interrupt on PIC18F4620 PORTB
    By rookie in forum Off Topic
    Replies: 1
    Last Post: - 22nd March 2007, 01:34
  2. Problem with PBP interrupt and Serin, please help
    By rgregor in forum mel PIC BASIC
    Replies: 0
    Last Post: - 22nd August 2006, 19:02
  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