Symbol not prev defined FSR - Elapsed Timer


+ Reply to Thread
Results 1 to 15 of 15
  1. #1
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,927

    Default Symbol not prev defined FSR - Elapsed Timer

    16F18877

    Program:

    Code:
    #CONFIG
        __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_OFF & _FCMEN_ON
        __config _CONFIG2, _MCLRE_ON & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_ON & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_ON & _DEBUG_OFF
        __config _CONFIG3, _WDTCPS_WDTCPS_11 & _WDTE_OFF & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
        __config _CONFIG4, _WRT_OFF & _SCANE_available & _LVP_OFF
        __config _CONFIG5, _CP_OFF & _CPD_OFF
    #ENDCONFIG
    
    ;--- Interrupts ----------------------------------------------------------------
    
    ;--- Defines -------------------------------------------------------------------
    
    DEFINE OSC 32
    
    RA4PPS = 0                          ' Disable CCP5
    RB0PPS = 0                          ' Disable CCP4
    RB5PPS = 0                          ' Disable CCP3
    RC1PPS = 0                          ' Disable CCP2
    RC2PPS = 0                          ' Disable CCP1
    
    ANSELA = %00000000
    ANSELB = %00000000
    ANSELC = %00000000
    ANSELD = %00000000
    ANSELE = %00000000
    
    ;--- Setup Port directions -----------------------------------------------------
    
    TRISA = %00000000                        
    TRISB = %00000000                      
    TRISC = %00000000                       
    TRISD = %00000000                      
    TRISE = %00001000
    
    INCLUDE "Elapsed_DN_32MHz.bas"  ; Elapsed Timer Routines
    
    Days = 0                  ' set initial time
    Hours = 0
    Minutes = 0
    Seconds = 1
    
      LatB.5 = 0
        GOSUB StartTimer
      LatB.5 = 1
    
    Main:
        IF Ticks > 100 THEN  
            LatB.5 = 0
        ENDIF
      GOTO Main
    end

    Elapsed DN, with 32MHz mod:

    Code:
    '****************************************************************
    '*  Name    : ELAPSED.PBP                                       *
    '*  Author  : Darrel Taylor                                     *
    '*  Notice  : Copyright (c) 2003                                *
    '*  Date    : 12/16/2003                                        *
    '*  Notes   :                                                   *
    '****************************************************************
    
    Define  INTHAND _ClockCount    ' Tell PBP Where the code starts on an interrupt
    Include "ASM_INTS.bas"         ' ASM Interrupt Stubs
    
    Ticks    VAR BYTE   ' 1/100th of a second
    Seconds  VAR BYTE
    Minutes  VAR BYTE
    Hours    VAR BYTE
    Days     VAR WORD
    R0save   VAR WORD
    R1save   VAR WORD
    
    ZERO             VAR BIT
    CountDown        VAR BIT
    SecondsChanged   VAR BIT
    MinutesChanged   VAR BIT
    HoursChanged     VAR BIT
    DaysChanged      VAR BIT
    
    CountDown = 0
    SecondsChanged = 1
    MinutesChanged = 1
    
    Goto OverElapsed
    
    ' ------------------------------------------------------------------------------
    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 == 20
    TimerConst = 03CB7h
      EndIF
      If OSC == 32			     ; T1CON
    TimerConst = 063C7h		     ;   TMR1CS bits 7-6, 00 = FOSC/4
      EndIF				     ;   T1CKPS bits 5-4, 01 = 1:2 Prescale value
      
    ; -----------------  ADD TimerConst to TMR1H:TMR1L
    ADD2_TIMER   macro
        CHK?RP  T1CON
        BCF     T1CON,TMR1ON           ; Turn off timer
        MOVLW   LOW(TimerConst)        ;  1
        ADDWF   TMR1L,F                ;  1    ; reload timer with correct value
        BTFSC   STATUS,C               ;  1/2
        INCF    TMR1H,F                ;  1
        MOVLW   HIGH(TimerConst)       ;  1
        ADDWF   TMR1H,F                ;  1
        endm
    
    ; -----------------  ADD TimerConst to TMR1H:TMR1L and restart TIMER1 
    RELOAD_TIMER  macro
        ADD2_TIMER
        BSF     T1CON,TMR1ON           ;  1    ; Turn TIMER1 back on
        CHK?RP  PIR1
        bcf     PIR1, TMR1IF           ; Clear Timer1 Interrupt Flag
        endm
    
    ; -----------------  Load TimerConst into TMR1H:TMR1L 
    LOAD_TIMER  macro
    EndAsm
        T1CON.0 = 0                    ; Turn OFF Timer1
        TMR1L = 0
        TMR1H = 0
    Asm
        ADD2_TIMER
        endm
    EndAsm
    
    ' ------[ This is the Interrupt Handler ]---------------------------------------
    ClockCount:   ' Note: this is being handled as an ASM interrupt
    @  INT_START                    
    @  RELOAD_TIMER                    ; Reload TIMER1
       R0save = R0                     ; Save 2 PBP system vars that are used during
       R1save = R1                     ; the interrupt
       Ticks = Ticks + 1
       if Ticks = 100 then
          Ticks = 0
          IF CountDown THEN
             IF Seconds > 0 THEN
                Seconds = Seconds - 1
                SecondsChanged = 1
                IF Seconds = 0 THEN
                   IF Days = 0 THEN
                      IF Hours = 0 THEN
                         IF Minutes = 0 THEN
                            GOSUB StopTimer    ; Zero reached
                            ZERO = 1
                         ENDIF
                      ENDIF
                   ENDIF
                ENDIF
             ELSE
                IF Minutes > 0 THEN
                   Minutes = Minutes - 1
                   Seconds = 59
                   SecondsChanged = 1
                   MinutesChanged = 1
                ELSE
                   IF Hours > 0 THEN
                      Hours = Hours - 1
                      Minutes = 59
                      Seconds = 59
                      SecondsChanged = 1
                      MinutesChanged = 1
                      HoursChanged = 1
                   ELSE
                      IF Days > 0 THEN
                         Days = Days - 1
                         Hours = 23
                         Minutes = 59
                         Seconds = 59
                         SecondsChanged = 1
                         MinutesChanged = 1
                         HoursChanged = 1
                         DaysChanged = 1
                      ELSE                     ; Zero already reached, shouldn't get here
                         GOSUB StopTimer
                         ZERO = 1
                      ENDIF
                   ENDIF
                ENDIF
             ENDIF
          ELSE                                ; Counting Up
             Seconds = Seconds + 1
             SecondsChanged = 1
             IF Seconds = 60 THEN
                Minutes = Minutes + 1
                MinutesChanged = 1
                Seconds = 0
             ENDIF
             IF Minutes = 60 THEN
                Hours = Hours + 1
                HoursChanged = 1
                Minutes = 0
             ENDIF
             IF Hours = 24 THEN
                Days = Days + 1
                DaysChanged = 1
                Hours = 0
             ENDIF
          endif
       ENDIF
       R1 = R1save                     ; Restore the PBP system vars
       R0 = R0save
    @ INT_RETURN                      ; Restore context and return from interrupt
    
    '-----====[ END OF TMR1 Interrupt Handler ]====---------------------------------
    
    StartTimer:
      IF NOT ZERO THEN
        T1CON.1 = 0                   ; (TMR1CS) Select FOSC/4 Clock Source
        T1CON.3 = 0                   ; (T1OSCEN) Disable External Oscillator
        PIR1.0  = 0                   ; (TMR1IF) Clear Timer1 Interrupt Flag
        PIE1.0  = 1                   ; (TMR1IE) Enable TMR1 overflow interrupt
        INTCON.6 = 1                  ; (PEIE) Enable peripheral interrupts
        INTCON.7 = 1                  ; (GIE) Enable global interrupts
        T1CON.0 = 1                   ; (TMR1ON) Start TIMER1
      ENDIF
    return
    
    ; -----------------
    StopTimer:
        T1CON.0 = 0                   ; Turn OFF Timer1
    return
    
    ; -----------------
    ResetTime:
        ZERO = 0
        R0save = T1CON.0              ; Save TMR1ON bit
        T1CON.0 = 0                   ; Turn OFF Timer1
        TMR1L = 0
        TMR1H = 0
    @   LOAD_TIMER                    ; Load TimerConst
        T1CON.0 = R0save              ; Restore TMR1ON bit
        Ticks = 0
        Seconds = 0
        Minutes = 0
        Hours = 0
        Days = 0
        SecondsChanged = 1
    return
    
    OverElapsed:

    ASM_INTS.bas:

    Code:
    '****************************************************************
    '*  Name    : ASM_INTS.PBP                                      *
    '*  Author  : Darrel Taylor                                     *
    '*  Notice  : Copyright (c) 2003                                *
    '*  Date    : JAN 4, 2003                                       *
    '****************************************************************
    
    wsave       var byte    $20     SYSTEM          ' location for W if in bank0
    
    ' --- IF any of these three lines cause an error ??  Simply Comment them out to fix the problem ----
    wsave1      var byte    $A0     SYSTEM          ' location for W if in bank1
    wsave2      var byte    $120    SYSTEM          ' location for W if in bank2
    wsave3      var byte    $1A0    SYSTEM          ' location for W if in bank3
    ' ------------------------------------------------------------------------------
    
    ssave       var byte    BANK0   SYSTEM          ' location for STATUS register
    psave       var byte    BANK0   SYSTEM          ' location for PCLATH register
    fsave       var byte    BANK0   SYSTEM          ' location for FSR register
    
    Asm
    INT_START  macro
        IF (CODE_SIZE <= 2)
            movwf   wsave            ; copy W to wsave register
            swapf   STATUS,W         ; swap status reg to be saved into W
            clrf    STATUS           ; change to bank 0 regardless of current bank
            movwf   ssave            ; save status reg to a bank 0 register
            movf    PCLATH,w         ; move PCLATH reg to be saved into W reg
            movwf   psave            ; save PCLATH reg to a bank 0 register
    	EndIF
        movf      FSR,W              ; move FSR reg to be saved into W reg
        movwf     fsave              ; save FSR reg to a bank 0 register
        endm
    EndAsm
    
    Asm
    INT_RETURN   macro
        MOVF    fsave,W              ; Restore the FSR reg 
        MOVWF   FSR
        Movf    psave,w              ; Restore the PCLATH reg
        Movwf   PCLATH
        swapf   ssave,w              ; Restore the STATUS reg			
        movwf   STATUS
        swapf   wsave,f
        swapf   wsave,w              ; Restore W reg
        Retfie                       ; Exit the interrupt routine	
        endm
    EndAsm

    For starters, I'm just trying to get a 100tick interval on the Logic Probe with LatB.5.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,927


    Did you find this post helpful? Yes | No

    Default Re: Symbol not prev defined FSR - Elapsed Timer

    Modded this code for program:

    https://dt.picbasic.co.uk/CODEX/ETimer


    Elapsed_DN.bas came from here:

    https://www.picbasic.co.uk/forum/con...sed-Timer-Demo


    ASM_INTS.bas came from here:

    https://dt.picbasic.co.uk/CODEX/ETimerExamples
    Last edited by Demon; Yesterday at 04:07.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  3. #3
    Join Date
    Aug 2011
    Posts
    438


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: Symbol not prev defined FSR - Elapsed Timer

    There is no FSR in the 16F18877, you have FSR0 and FSR1.

    You need to look at the TMR1 setup... you need to set different registers and bits (ie T1CON and T1CLK).

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,927


    Did you find this post helpful? Yes | No

    Default Re: Symbol not prev defined FSR - Elapsed Timer

    Quote Originally Posted by tumbleweed View Post
    There is no FSR in the 16F18877, you have FSR0 and FSR1...
    I don't see a difference between FSR0 and FSR1. I assume I can use either one?

    Name:  FSR.png
Views: 188
Size:  103.1 KB

    EDIT: Wooops, highlighted the wrong one, but you get the idea. FSR1 is right there as well, and it points to the same blocks as FSR0.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,927


    Did you find this post helpful? Yes | No

    Default Re: Symbol not prev defined FSR - Elapsed Timer

    16F18877

    I start the timer, but I don't get a pulse on Logic Probe after 100 Ticks.


    Code:

    Code:
    #CONFIG
        __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_OFF & _FCMEN_ON
        __config _CONFIG2, _MCLRE_ON & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_ON & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_ON & _DEBUG_OFF
        __config _CONFIG3, _WDTCPS_WDTCPS_11 & _WDTE_OFF & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
        __config _CONFIG4, _WRT_OFF & _SCANE_available & _LVP_OFF
        __config _CONFIG5, _CP_OFF & _CPD_OFF
    #ENDCONFIG
    
    ;--- Interrupts ----------------------------------------------------------------
    
    ;--- Defines -------------------------------------------------------------------
    
    DEFINE OSC 32
    
    define  CCP1_REG     0              ' Must clear unused CCP pins or else unpredictable results
    DEFINE  CCP1_BIT     0
    define  CCP2_REG     0
    DEFINE  CCP2_BIT     0
    DEFINE  CCP3_REG     0
    DEFINE  CCP3_BIT     0
    define  CCP4_REG     0
    DEFINE  CCP4_BIT     0
    define  CCP5_REG     0              ' Must clear unused CCP pins or else unpredictable results
    DEFINE  CCP5_BIT     0
    
    RA4PPS = 0                          ' Disable CCP5
    RB0PPS = 0                          ' Disable CCP4
    RB5PPS = 0                          ' Disable CCP3
    RC1PPS = 0                          ' Disable CCP2
    RC2PPS = 0                          ' Disable CCP1
    
    ANSELA = %00000000
    ANSELB = %00000000
    ANSELC = %00000000
    ANSELD = %00000000
    ANSELE = %00000000
    
    ;--- Setup Port directions -----------------------------------------------------
    
    TRISA = %00000000                        
    TRISB = %00000000                      
    TRISC = %00000000                       
    TRISD = %00000000                      
    TRISE = %00001000
    
    INCLUDE "Elapsed_DN_Timer3_32MHz.bas"   ' Elapsed Timer Routines
    'Include "ASM_INTS_FSR0.bas"             ' Required in folder to compile
    
    Days = 0                  ' set initial time
    Hours = 0
    Minutes = 1
    Seconds = 0
    
      LatB.0 = 0            ' Set interrupt trace low
      LatB.1 = 0            ' Set heartbeat trace low
        GOSUB StartTimer
      LatB.0 = 1            ' Beginning of interrupt
    
    Main:
      LatB.1 = 1            ' Pulse heartbeat
        IF Ticks > 100 THEN  
            LatB.0 = 0      ' End of interrupt
        ENDIF
      LatB.1 = 0            ' Reset heartbeat trace
      GOTO Main
    end

    Elapsed_DN_Timer3_32MHz.bas, modified for Timer3 and 32MHz:

    Code:
    '****************************************************************
    '*  Name    : ELAPSED.PBP                                       *
    '*  Author  : Darrel Taylor                                     *
    '*  Notice  : Copyright (c) 2003                                *
    '*  Date    : 12/16/2003                                        *
    '*  Notes   :                                                   *
    '****************************************************************
    '*  Name    : Elapsed_DN_Timer3_32MHz.bas                       *
    '*  Author  : Robert H                                          *
    '*  Date    : 2024-10-05                                        *
    '*  Notes   : Added support for 16F18877:                       *
    '             a) Added 32MHz                                    *
    '             b) Used Timer3 instead of Timer1:                 *
    '                  - changed Timer1 to Timer3                   *
    '                  - changed T1 to T3                           *
    '                  - changed TMR1 to TMR3                       *
    '                  - changed PIR1 to PIR4                       *
    '                  - changed PIE1 to PIE4                       *
    '             c) Changed T3CON,TMR3ON to T3CON,ON               *
    '             d) Used FSR0 in ASM_INTS_FSR0.bas                 *
    '****************************************************************
    
    Define  INTHAND _ClockCount    ' Tell PBP Where the code starts on an interrupt
    Include "ASM_INTS_FSR0.bas"    ' ASM Interrupt Stubs
    
    Ticks    VAR BYTE   ' 1/100th of a second
    Seconds  VAR BYTE
    Minutes  VAR BYTE
    Hours    VAR BYTE
    Days     VAR WORD
    R0save   VAR WORD
    R1save   VAR WORD
    
    ZERO             VAR BIT
    CountDown        VAR BIT
    SecondsChanged   VAR BIT
    MinutesChanged   VAR BIT
    HoursChanged     VAR BIT
    DaysChanged      VAR BIT
    
    CountDown = 0
    SecondsChanged = 1
    MinutesChanged = 1
    
    Goto OverElapsed
    
    ' ------------------------------------------------------------------------------
    Asm
      IF OSC == 4                       ; Constants for 100hz interrupt from Timer3
    TimerConst = 0D8F7h                 ; Executed at compile time only
      EndIF
      If OSC == 8
    TimerConst = 0B1E7h
      EndIF
      If OSC == 10
    TimerConst = 09E5Fh
      EndIF
      If OSC == 20
    TimerConst = 03CB7h
      EndIF
      If OSC == 32			     ; T3CON
    TimerConst = 063C7h		     ;   TMR3CS bit 1,   0  = FOSC/4
      EndIF				     ;   T3CKPS bit 5-4, 01 = 1:2 Prescale value
      
    ; -----------------  ADD TimerConst to TMR3H:TMR3L
    ADD2_TIMER   macro
        CHK?RP  T3CON
        BCF     T3CON,TMR3ON           ; Turn off timer
        MOVLW   LOW(TimerConst)        ;  1
        ADDWF   TMR3L,F                ;  1    ; reload timer with correct value
        BTFSC   STATUS,C               ;  1/2
        INCF    TMR3H,F                ;  1
        MOVLW   HIGH(TimerConst)       ;  1
        ADDWF   TMR3H,F                ;  1
        endm
    
    ; -----------------  ADD TimerConst to TMR3H:TMR3L and restart Timer3 
    RELOAD_TIMER  macro
        ADD2_TIMER
        BSF     T3CON,TMR3ON           ;  1    ; Turn Timer3 back on
        CHK?RP  PIR4
        bcf     PIR4, TMR3IF           ; Clear Timer3 Interrupt Flag
        endm
    
    ; -----------------  Load TimerConst into TMR3H:TMR3L 
    LOAD_TIMER  macro
    EndAsm
        T3CON.0 = 0                    ; Turn OFF Timer3
        TMR3L = 0
        TMR3H = 0
    Asm
        ADD2_TIMER
        endm
    EndAsm
    
    ' ------[ This is the Interrupt Handler ]---------------------------------------
    ClockCount:   ' Note: this is being handled as an ASM interrupt
    @  INT_START                    
    @  RELOAD_TIMER                    ; Reload Timer3
       R0save = R0                     ; Save 2 PBP system vars that are used during
       R1save = R1                     ; the interrupt
       Ticks = Ticks + 1
       if Ticks = 100 then
          Ticks = 0
          IF CountDown THEN
             IF Seconds > 0 THEN
                Seconds = Seconds - 1
                SecondsChanged = 1
                IF Seconds = 0 THEN
                   IF Days = 0 THEN
                      IF Hours = 0 THEN
                         IF Minutes = 0 THEN
                            GOSUB StopTimer    ; Zero reached
                            ZERO = 1
                         ENDIF
                      ENDIF
                   ENDIF
                ENDIF
             ELSE
                IF Minutes > 0 THEN
                   Minutes = Minutes - 1
                   Seconds = 59
                   SecondsChanged = 1
                   MinutesChanged = 1
                ELSE
                   IF Hours > 0 THEN
                      Hours = Hours - 1
                      Minutes = 59
                      Seconds = 59
                      SecondsChanged = 1
                      MinutesChanged = 1
                      HoursChanged = 1
                   ELSE
                      IF Days > 0 THEN
                         Days = Days - 1
                         Hours = 23
                         Minutes = 59
                         Seconds = 59
                         SecondsChanged = 1
                         MinutesChanged = 1
                         HoursChanged = 1
                         DaysChanged = 1
                      ELSE                     ; Zero already reached, shouldn't get here
                         GOSUB StopTimer
                         ZERO = 1
                      ENDIF
                   ENDIF
                ENDIF
             ENDIF
          ELSE                                ; Counting Up
             Seconds = Seconds + 1
             SecondsChanged = 1
             IF Seconds = 60 THEN
                Minutes = Minutes + 1
                MinutesChanged = 1
                Seconds = 0
             ENDIF
             IF Minutes = 60 THEN
                Hours = Hours + 1
                HoursChanged = 1
                Minutes = 0
             ENDIF
             IF Hours = 24 THEN
                Days = Days + 1
                DaysChanged = 1
                Hours = 0
             ENDIF
          endif
       ENDIF
       R1 = R1save                     ; Restore the PBP system vars
       R0 = R0save
    @ INT_RETURN                      ; Restore context and return from interrupt
    
    '-----====[ END OF TMR3 Interrupt Handler ]====---------------------------------
    
    StartTimer:
      IF NOT ZERO THEN
        T3CON.1 = 0                   ; (TMR3CS) Select FOSC/4 Clock Source
        T3CON.3 = 0                   ; (T3OSCEN) Disable External Oscillator
        PIR4.0  = 0                   ; (TMR3IF) Clear Timer3 Interrupt Flag
        PIE4.0  = 1                   ; (TMR3IE) Enable TMR3 overflow interrupt
        INTCON.6 = 1                  ; (PEIE) Enable peripheral interrupts
        INTCON.7 = 1                  ; (GIE) Enable global interrupts
        T3CON.0 = 1                   ; (TMR3ON) Start Timer3
      ENDIF
    return
    
    ; -----------------
    StopTimer:
        T3CON.0 = 0                   ; Turn OFF Timer3
    return
    
    ; -----------------
    ResetTime:
        ZERO = 0
        R0save = T3CON.0              ; Save TMR3ON bit
        T3CON.0 = 0                   ; Turn OFF Timer3
        TMR3L = 0
        TMR3H = 0
    @   LOAD_TIMER                    ; Load TimerConst
        T3CON.0 = R0save              ; Restore TMR3ON bit
        Ticks = 0
        Seconds = 0
        Minutes = 0
        Hours = 0
        Days = 0
        SecondsChanged = 1
    return
    
    OverElapsed:

    ASM_INTS_FSR0.bas, modified for FSR0:

    Code:
    '****************************************************************
    '*  Name    : ASM_INTS.PBP                                      *
    '*  Author  : Darrel Taylor                                     *
    '*  Notice  : Copyright (c) 2003                                *
    '*  Date    : JAN 4, 2003                                       *
    '*  Notes   :                                                   *
    '****************************************************************
    '*  Name    : ASM_INTS_FSR0.bas                                 *
    '*  Author  : Robert H                                          *
    '*  Date    : 2024-10-05                                        *
    '*  Notes   : Added support for 16F18877:                       *
    '             a) Changed FSR to FSR0                            *
    '****************************************************************
    
    wsave       var byte    $20     SYSTEM          ' location for W if in bank0
    
    ' --- IF any of these three lines cause an error ??  Simply Comment them out to fix the problem ----
    wsave1      var byte    $A0     SYSTEM          ' location for W if in bank1
    wsave2      var byte    $120    SYSTEM          ' location for W if in bank2
    wsave3      var byte    $1A0    SYSTEM          ' location for W if in bank3
    ' ------------------------------------------------------------------------------
    
    ssave       var byte    BANK0   SYSTEM          ' location for STATUS register
    psave       var byte    BANK0   SYSTEM          ' location for PCLATH register
    fsave       var byte    BANK0   SYSTEM          ' location for FSR0 register
    
    Asm
    INT_START  macro
        IF (CODE_SIZE <= 2)
            movwf   wsave            ; copy W to wsave register
            swapf   STATUS,W         ; swap status reg to be saved into W
            clrf    STATUS           ; change to bank 0 regardless of current bank
            movwf   ssave            ; save status reg to a bank 0 register
            movf    PCLATH,w         ; move PCLATH reg to be saved into W reg
            movwf   psave            ; save PCLATH reg to a bank 0 register
    	EndIF
        movf      FSR0,W              ; move FSR0 reg to be saved into W reg
        movwf     fsave              ; save FSR0 reg to a bank 0 register
        endm
    EndAsm
    
    Asm
    INT_RETURN   macro
        MOVF    fsave,W              ; Restore the FSR0 reg 
        MOVWF   FSR0
        Movf    psave,w              ; Restore the PCLATH reg
        Movwf   PCLATH
        swapf   ssave,w              ; Restore the STATUS reg			
        movwf   STATUS
        swapf   wsave,f
        swapf   wsave,w              ; Restore W reg
        Retfie                       ; Exit the interrupt routine	
        endm
    EndAsm

    I used 18F4450 as an example of "default" settings.

    18F4450, bit 0 is called TMR1ON in the datasheet.
    16F18877, bit 0 is called ON.

    If I rename the bit to ON, I get Symbol not previously defined (ON).


    I must have missed something.
    Last edited by Demon; Yesterday at 22:33.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: Symbol not prev defined FSR - Elapsed Timer

    I would start off with interrupt and in routine just add to a counter then in Basic do the math to get seconds, minutes etc. Otherwise that is a lot of code to fumble through.

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,492


    Did you find this post helpful? Yes | No

    Default Re: Symbol not prev defined FSR - Elapsed Timer

    there are more problems here than i can count

    1, timer3 has no clock source
    2, how can ticks ever get beyond 100
    Code:
    main:  LatB.1 = 1            ' Pulse heartbeat
        IF Ticks > 100 THEN  
            LatB.0 = 0      ' End of interrupt
        ENDIF
      LatB.1 = 0            ' Reset heartbeat trace
      GOTO Main
    when
    Code:
    ClockCount:   ' Note: this is being handled as an ASM interrupt
    @  INT_START                    
    @  RELOAD_TIMER                    ; Reload Timer3
       R0save = R0                     ; Save 2 PBP system vars that are used during
       R1save = R1                     ; the interrupt
       Ticks = Ticks + 1
       if Ticks = 100 then
          Ticks = 0
          IF CountDown THEN
    3, a 16f18877 like all enhanced core pic16's has Auto context save
    the entire int_start / int_return macros are inappropriate

    4, you need to rethink that, that is for timer1 not 3
    Code:
    StartTimer:
      IF NOT ZERO THEN
        T3CON.1 = 0                   ; (TMR3CS) Select FOSC/4 Clock Source
        T3CON.3 = 0                   ; (T3OSCEN) Disable External Oscillator
        PIR4.0  = 0                   ; (TMR3IF) Clear Timer3 Interrupt Flag
        PIE4.0  = 1                   ; (TMR3IE) Enable TMR3 overflow interrupt
        INTCON.6 = 1                  ; (PEIE) Enable peripheral interrupts
        INTCON.7 = 1                  ; (GIE) Enable global interrupts
        T3CON.0 = 1                   ; (TMR3ON) Start Timer3
      ENDIF
    return
    Warning I'm not a teacher

  8. #8
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,927


    Did you find this post helpful? Yes | No

    Default Re: Symbol not prev defined FSR - Elapsed Timer

    I'm already using Timer1, hence why I hoped to use Timer3.

    I'll swap what I'm doing, so I can use DT's routine without changing Timer1.

    (At the restaurant, so can't post elaborate reply)
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  9. #9
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,927


    Did you find this post helpful? Yes | No

    Default Re: Symbol not prev defined FSR - Elapsed Timer

    Quote Originally Posted by richard View Post
    ... how can ticks ever get beyond 100 ...
    I only wanted 1 interval, so I'd know the mods were working with the 16F18877.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  10. #10
    Join Date
    May 2013
    Location
    australia
    Posts
    2,492


    Did you find this post helpful? Yes | No

    Default Re: Symbol not prev defined FSR - Elapsed Timer

    how big would Ticks have to be to make this true ?


    IF Ticks > 100 THEN
    Warning I'm not a teacher

  11. #11
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,927


    Did you find this post helpful? Yes | No

    Default Re: Symbol not prev defined FSR - Elapsed Timer

    Quote Originally Posted by richard View Post
    how big would Ticks have to be to make this true ?

    IF Ticks > 100 THEN
    I have a feeling I'll be waiting a while for that to happen. I've brought that down to Ticks > 1.

    I've started again with the original includes, and:
    - added 32MHz
    - changed PIE1 to PIE4
    - changed PIR1 to PIR4
    - changed FSR to FSR0


    ...I'm adding T1CON and T1CLK now...


    I'm still puzzled by T1CON,TMR1ON. The datasheet doesn't have TMR1ON, it's just ON.


    EDIT: Confirmed, it works once I added T1CON and T1CLK. I was blindly following the instructions on the Book of Interrupts and forgetting that this PIC is different.

    a) I'm still puzzled why TMR1ON works though; seems contradictory to me.

    b) so 1 Tick is 66.4ms on a 16F18877.


    Blissful ignorance is a wonderful thing...
    Last edited by Demon; Today at 03:55.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  12. #12
    Join Date
    May 2013
    Location
    australia
    Posts
    2,492


    Did you find this post helpful? Yes | No

    Default Re: Symbol not prev defined FSR - Elapsed Timer

    all bit definitions are in the mpasmx folder *.inc files. the datasheet refers to any timer1 type timer for that chip, ie tmr1 tmr3 tmr5

    eg
    Name:  Untitled.jpg
Views: 130
Size:  81.4 KB
    Last edited by richard; Today at 04:35.
    Warning I'm not a teacher

  13. #13
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,927


    Did you find this post helpful? Yes | No

    Default Re: Symbol not prev defined FSR - Elapsed Timer

    I want to post my code in Code Examples.

    What would be a good label for new PICs like the 16F18877 that need modified includes?
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  14. #14
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,927


    Did you find this post helpful? Yes | No

    Default Re: Symbol not prev defined FSR - Elapsed Timer

    Quote Originally Posted by richard View Post
    all bit definitions are in the mpasmx folder *.inc files.
    Should we edit those includes to match the names In the datasheet?

    Or is that opening another can of worms?
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  15. #15
    Join Date
    May 2013
    Location
    australia
    Posts
    2,492


    Did you find this post helpful? Yes | No

    Default Re: Symbol not prev defined FSR - Elapsed Timer

    Should we edit those includes to match the names In the datasheet?
    absolutely not, there is no problem to solve

    if you want to use mpasm bit names in your code then use the bit names that microchip have created for them
    there is zero point in inventing names that mpasmx will not recognize.
    the proper and correct names are in the mpasmx picxxxxx.inc files
    Warning I'm not a teacher

Similar Threads

  1. Replies: 11
    Last Post: - 23rd August 2024, 02:13
  2. Replies: 7
    Last Post: - 2nd January 2018, 04:17
  3. Symbol not previously defined - lib file
    By Scampy in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 2nd November 2015, 00:33
  4. symbol not prev. def. _INTRC_OSC 16F88
    By MarkR in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 29th July 2011, 22:33
  5. Symbol not previously defined
    By Archangel in forum Code Examples
    Replies: 2
    Last Post: - 27th December 2008, 09:52

Members who have read this thread : 8

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