Elapsed_Int-18 Alteration


Results 1 to 6 of 6

Threaded View

  1. #1
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    94

    Default Elapsed_Int-18 Alteration

    I've added a slight alteration to Darrel's Elapsed_Int-18 to get 48MHz oscillator. Could somebody please check if this is correct?

    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
    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:
    ; -----------------  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
    Thanks in advance

    Rob
    Last edited by Rob; - 30th January 2008 at 10:20. Reason: Further Information

Similar Threads

  1. Config Settings for the 18 series
    By Ioannis in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 30th June 2009, 21:03
  2. PICPROTO 18 Prototyping Board Examples
    By rick hardy in forum General
    Replies: 9
    Last Post: - 21st April 2008, 05:19
  3. Replies: 3
    Last Post: - 31st January 2008, 07:30
  4. Real Time Clock & Eeprom
    By smart_storm in forum General
    Replies: 8
    Last Post: - 17th February 2006, 19:03
  5. PIC16F62x 18 pin SMT breakout PCB
    By jdgrotte in forum Adverts
    Replies: 1
    Last Post: - 1st January 2004, 08:59

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