Timer issue


Results 1 to 13 of 13

Thread: Timer issue

Threaded View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,116

    Default Timer issue

    I am not getting the time I expect from the following Interrupt Driven timer.

    Controller is 16F887,internal OSC at 8MHz, expected interrupt every 25usec and I get every 101usec.

    If I change the reload value to 63, the expected interrupt is 100usec and I get 146usec.

    A check on the IntOSC with Clock out on RA6 prooves that the Clock is correct @ 2MHz (8MHz/4).

    I tested also with the Timer2 w/o pre-post scalers with exactly the same results.

    Here is the test code that is making me nervous:

    Code:
    DEFINE OSC 8
    
    OSCCON = %01110001 'SET SYSTEM CLOCK SWITCH BIT
    
    @Line1 = _DEBUG_OFF & _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_ON
    @Line2 = _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
    
    @ __CONFIG _CONFIG1, Line1 & Line2
    
    @ __CONFIG _CONFIG2, _WRT_HALF & _BOR40V
    
    PORTA=0:PORTB=0:PORTC=0:PORTD=0:PORTE=0
    
    TRISA=%00101101
    TRISB=%00000000
    TRISC=%10000000
    TRISD=%00000011
    TRISE=%00000000
    
    OPTION_REG=00001111
    
    WPUB = %00111111
    
    ADCON0 = %11000001
    ADCON1 = %00000000	'Set PORTA/E analog/digital, right justify result
    ANSEL  = %00101101  'lower port A as Analog input
    ANSELH = %00000000  'all others Digital inputs
    
    DEFINE ADC_BITS 10  'Number of bits in Adcin result
    DEFINE ADC_CLOCK 3  'ADC clock source (rc = 3)
    DEFINE ADC_SAMPLEUS 50
                         
    pwm1            var portc.2
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    '**************************************************************************
    '****
    '****                            Initialization
    '****
    '**************************************************************************
    
    't2con = %0000100    ;Fosc/4, no prescaler, no postscaler
    
    't1con = %00110001   'Enable Timer1 (16bit) /8 prescaller, int. Fosc/4 clock
                        '@ 20MHz times out every 104,86ms
    ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    ASM
    INT_LIST  macro    ; IntSource,        Label,       Type, ResetFlag?
    			INT_Handler   TMR0_INT,  _UpdateTimer,   PBP,  yes
    ;			INT_Handler   AD_INT,    _ADC_Sub,       PBP,  yes
    	endm
    	INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::       
    
    @ INT_ENABLE  TMR0_INT      ; enable Timer 1 interrupts
    ;@ INT_ENABLE  AD_INT        ; enable ADC Interrupt
    
    CLEAR
    
    loop1:
    pause 100
    goto loop1
    
    UpdateTimer:                        'This interrupt should happen every 25usec :(
        tmr0=213
        toggle portc.2
    @ INT_RETURN
    I miss something here but ... what?

    Ioannis
    Last edited by Ioannis; - 2nd January 2011 at 18:07.

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