I just had another idea. I need a base frequency of 120Hz. On a 8Mhz intosc, if i make the frequency 256 x 120Hz = 30720Hz and count 256 interrupts and then fire a pin i should have 120Hz, right ?
If i setup timer0 with a 1:2 prescaler and preload it with 224 it should have 30,303 KHz which is acceptable. However i can't seem to go any higher than 10Khz.
The code below toggle's the pin on every interrupt, so i should see a 15Khz signal, instead i'm getting a 5Khz signal.
Code:'==== Dec's for OSC ===================================== DEFINE OSC 8 'Int OSC @ 8 MHz, for PBP OSCCON = %01110001 'Int OSC @ 8 MHz '==== Set includes ====================================== INCLUDE "DT_INTS-14.bas" 'DTints Interrupt System include "ReEnterPBP.bas" 'Enable PBP int reenter '==== Set defines ======================================= OPTION_REG = %00000000 'Set TMR0 precsaler to 1:256, source Fosc/4 WPU = %00000000 'Weak pull-ups disabled INTCON = %00100000 'Global + Perhip. INT enabled, TMR0 int enabled 'PIE1 = %00000000 'TMR2 to PR2 match INT enabled 'PIE2 = %00000000 'Set TMR1 overflow interrupt 'PIR1 = %00000000 'PIR2 = %00000000 'PCON = %00000000 'IOC = %00000000 'Interrupt On Change disabled 'PCON = %00000000 'Ultra lowpower + BOR disabled ANSEL = %00000000 'Select analog inputs: none ANSELH = %00000000 'Select analog inputs: none ADCON0 = %00000000 'A/D Module is OFF ADCON1 = %00000000 'A/D control register CM1CON0 = %00000000 'Comparator1 Module is OFF CM2CON0 = %00000000 'Comparator2 Module is OFF VRCON = %00000000 'Voltage ref. disabled TRISA = %00000000 'Set Input/Output (0 to 5) PORTA = %00000000 'Ports High/Low (0 to 5) TRISB = %00000000 'Set Input/Output (4 to 7) PORTB = %00000000 'Ports High/Low (4 to 7) TRISC = %00000000 'Set Input/Output (0 to 7) PORTC = %00000000 'Ports High/Low (0 to 7) T2CON = %00000100 'Timer2 is On, T1CON = %00000000 'Timer1 is off CCP1CON = %00000000 'CCP engine is off '==== Setup DTints interrupt handler ==================== ASM INT_LIST macro ;Setup IntSource INT_Handler TMR0_INT, _intTMR0, PBP, YES ;Enable TMR0 interrupts endm INT_CREATE ;Create interrupt processor ENDASM '==== Wait for hardware settle ========================== pause 500 '==== Enable interrupt processing ======================= @ INT_ENABLE TMR0_INT ;Activate TMR0 INT '==== Main program loop ================================= main: @ nop ;Do nothing goto main '==== The End =========================================== theend: ' Endless loop goto theend ' Endless loop 'Routines and Handlers '==== TMR0 Interrupt handler ============================ intTMR0: 'TMR0 INTERRUPT HANDLER TMR0 = 223 'Reload TMR0 toggle PORTC.0 @ INT_RETURN ;Jump back to previous process




Bookmarks