Quantcast
Channel: MEL PICBASIC Forum
Viewing all articles
Browse latest Browse all 4787

timer0 10ms setting check

$
0
0
HI guys , i transfer some code from another processor which from the data sheet hs the same registers but seem to be getting a 20ms timer0 , not a 10ms interupt

all looks correct but it cant be , can someone have a look and see where i made the error

pic 18f46k80
osc32 internal,
timer 0 to give a 10ms interupt

Code:


;----- CONFIG1L Options --------------------------------------------------
    CONFIG XINST    = OFF
    CONFIG SOSCSEL  = DIG        ; Digital (SCLKI) mode; I/O port functionality of RC0 and RC1 is enabled
    CONFIG INTOSCSEL = LOW        ; LF-INTOSC in low-power mode during Sleep
    CONFIG RETEN    = ON        ; Ultra Low power regulator is Enabled  (Controlled by SRETEN bit)when in sleep

;----- CONFIG1H Options --------------------------------------------------
    CONFIG IESO      = OFF
    CONFIG FCMEN    = OFF
    CONFIG PLLCFG    = ON
    CONFIG FOSC      = INTIO2    ; Internal RC oscillator  , PORTA.6 , PORTA.7 as I/O


Code:

  OSCCON  = %01100000    ' Select 32Mhz - using 8Mhz internal with PPLx4 in Config1H<3:0>  =  IDLEN =0 , 8Mhz , OSTS=0,RFIOFS=1,RC_Run (1x) OSC using PLL 
                            ' Bit 7 IDLEN =0 ( sleep mode when sleep instraction executed)
                            ' Bits 6-4 -  111 = 16Mhz , 110 = 8MHz ,101 = 4 MHz, 100 = 2MHz 011 = 1MHz
                            ' If INTTSRC=0 and MFIOSEL= 0 then 010 = HF-INTOSC/32 (500Khz), 001 = HF-INTOSC/64 (250Khz) ,000 = LF-INTOSC    (31.25Khz)
                            ' If INTTSRC=0 and MFIOSEL= 1 then 010 = MF-INTOSC    (500Khz), 001 = MF-INTOSC/2  (250Khz) ,000 = LF-INTOSC    (31.25Khz)
                            ' If INTTSRC=1 and MFIOSEL= 0 then 010 = HF-INTOSC/32 (500Khz), 001 = HF-INTOSC/64 (250Khz) ,000 = HF-INTOSC/512 (31.25Khz)
                            ' If INTTSRC=1 and MFIOSEL= 1 then 010 = MF-INTOSC    (500Khz), 001 = MF-INTOSC/2  (250Khz) ,000 = MF-INTOSC/16  (31.25Khz)
                            ' Note: INTSRC = OSCTUNE<7> and MFIOSEL = OSCCON2<0>
                            ' Bit 3 - OSTS = 0 - Osc startup time out  is ruinning from internal OSC ( HF, MF or LF-INTOSC)
                            ' Bit 2 - HFIOFS =1 ( INTOSC Frq stable bit  -  1 = stable , 0 = not stable
                            ' Bits 1-0 - 00= Dephalt Pri OSc ( OSC1/2 or HF-INTOSC with/without PLL set in FOSC,3:0> config1H <3.0>
                            '            01 = SOSC osc
                            '            1x = Internal osc ( LF, MF,HF-INTOSC) 
 
  ' OSCCON2 = $00            ' Bit 7 n/a , Bit 6 - SOSCRUN - Run status bit , Bit 5-4 n/a,
                            ' Bit 3 = SOASCGO - Osc Start control bit 1 = OSC running , 0 = OSC shut off if no requests for it
                            ' Bit 2 n/a , Bit 1 - MFIOFS 1= MFINTOSC stable  0 = Not stable
                            ' Bit 0 MFIOSEL - 1 = MF-INTOSC replaces HF-ISTOSC Freq for 500Khz,250Khz,31.25KHz) 0 = MF-INTOSC not used
 
  OSCTUNE = %01000000      ' Bit 7  - INTSRC - internal LF Source Select 1 = 31.25 from 16Mhz Internal /512 HF-INTOSC ) 0 = Internal 31khz OSC
                            ' Bit 6 - PLLEN - 1 PLL enabled  , 0 = PLL disabled
                            ' Bits 5-0 Frequancy callibaration 00000 = centre Frq

Code:



  ' ---------- Timer 0 Register Setups ----------------
    INTCON2.2 = 1          ' TMR0IP  - TIMER 0 Overflow Interupt Priority - 1 = High Priorty , 0 = Low Priority
    T0CON.7 = 1            ' Bit7 - TMR0 1= Enable 0 = Stop timer
    T0CON.6 = 0            ' Bit6 - TMR0 8/16bit control 1= 8bit 0=16bit,
    T0CON.5 = 0            ' Bit5 - TMR0 Clock Source 1=clk on T0CKI pin input 0=Internal clcck (Fosc/4)
    T0CON.4 = 0            ' Bit4 - TMR0 Source Edge Select 1= H/L of TOCKI 0= L/H of TOCKI ,
    T0CON.3 = 0            ' Bit3 - TMR0 PSA select 1=TMR0 Bypass Prescaler 0= CLK Input from Prescaler output     
    T0CON.2 = 0            ' Bit2-0 - Timer0 prescaler Rate Select bits 2-0(set to 1:256)       
    T0CON.1 = 0            ' 000 = 1:2  , 001= 1:4  , 010 = 1:8  , 011 = 1:16     
    T0CON.0 = 0            ' 100 = 1:32 , 101 = 1:64, 110 = 1:128 , 111 = 1:256

Code:

' ---------- Set up DT_INTS-18 Routine for Instant Interupt handling  -----------
 
    INCLUDE "DT_INTS-18.bas"      ; Base Interrupt System for 18FxxK80 processors
    INCLUDE "ReEnterPBP-18.bas"    ; Include if using PBP interrupts
   
ASM
INT_LIST macro        ; IntSource  ,    Label    , Type, ResetFlag?

  INT_Handler TMR0_INT, _Timer0_Count,  PBP, yes      ; call Timer0_Count subroutine
 
 endm
 INT_CREATE                                                                ; Creates the Interrupt Processor
ENDASM


Code:



' ============ Timer 0 Interupt handler ================
 ' a 10 ms timer interupt

  Timer0_Count:
   
    INTCON.5 = 0                ' STOP TIMER
  T0Count1 = T0Count1 + 1      ' inc counter on interupt flag
    TMR0H = $63              ' preset Timer 0 to a 10ms timer
    TMR0L = $C0                             
    INTCON.5 = 1                ' START TIMER
@ INT_RETURN
    RETURN


Viewing all articles
Browse latest Browse all 4787

Trending Articles