I've added a slight alteration to Darrel's Elapsed_Int-18 to get 48MHz oscillator. Could somebody please check if this is correct?
The timer seems to run doubly quick like the prescale setting is not being set correctly. If I set the prescale setting in the ADD2_TIMER macro though it works correctly but will increase the amount of instructions required therefore altering the amount of time a tick takes:Code:' ------------------------------------------------------------------------------ ' To calculate a constant for a different crystal frequency - see this web page ' http://www.picbasic.co.uk/forum/showthread.php?t=2031 ' ------------------------------------------------------------------------------ Asm IF OSC == 4 ; Constants for 100hz interrupt from Timer1 TimerConst = 0D8F7h ; Executed at compile time only EndIF If OSC == 8 TimerConst = 0B1E7h EndIF If OSC == 10 TimerConst = 09E5Fh EndIF If OSC == 16 TimerConst = 063C7h EndIF If OSC == 20 TimerConst = 03CB7h EndIF If OSC == 48 ; If an oscillator of 48MHz is used e.g. TimerConst = 015A4h ; in USB PICs, set TimerConst to 015A4h. BSF T1CON,T1CKPS0, 0 ; MUST also set to prescale of 2 NOT 1 EndIF ; ----------------- ADD TimerConst to TMR1H:TMR1L ADD2_TIMER macro ; CHK?RP T1CON BCF T1CON,TMR1ON, 0 ; Turn off timer MOVLW LOW(TimerConst) ; 1 ADDWF TMR1L,F, 0 ; 1 ; reload timer with correct value BTFSC STATUS,C ; 1/2 INCF TMR1H,F, 0 ; 1 MOVLW HIGH(TimerConst) ; 1 ADDWF TMR1H,F, 0 ; 1 endm
Thanks in advanceCode:; ----------------- ADD TimerConst to TMR1H:TMR1L ADD2_TIMER macro ; CHK?RP T1CON BCF T1CON,TMR1ON, 0 ; Turn off timer If OSC == 48 ; IF OSCILLATOR IS 48MHz THEN BSF T1CON,T1CKPS0, 0 ; SET PRESCALE VALUE TO 2 EndIF MOVLW LOW(TimerConst) ; 1 ADDWF TMR1L,F, 0 ; 1 ; reload timer with correct value BTFSC STATUS,C ; 1/2 INCF TMR1H,F, 0 ; 1 MOVLW HIGH(TimerConst) ; 1 ADDWF TMR1H,F, 0 ; 1 endm
Rob




Bookmarks