Announcement

Collapse
No announcement yet.

asm error : address label duplicated ot different in second pass

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • richard
    replied
    the 24bit version is a bit awkward so i will explain the 32 bit version


    there are two timers used tmr1 and tmr3

    tmr1 is driven by the 32khz xtal extosc / 8 that gives 1 tick per 244uS.
    on overflow the isr tock adds 0xffff to the 32bit system time ticks , this occurs every 15.8 seconds
    this timer is never interfered with so it can maintain accuracy.

    the system time a timestamp is the top 24bits of ticks + timer1

    the get_now sub will get the system time for you and load the "timestamp" into the 32bit var sn


    tmr3 is only used to time display printouts

    its isr tick reloads the 20ms tconstant and every nth time sets a flag to indicate the display needs a refresh [nth = 40 or 400 depending on version]


    delta_time
    calculates 32bit difference between to timestamps



    dhms_time
    breaks a 32 bit timestamp into days,hours,minutes,seconds,hundtedths or millies if req [depending on version]

    to time an interval simply save a begining timestamp ,and ending timestamp call delta_time then use dhms_time to
    split it into hms quantities
    Last edited by richard; 08-09-2016, 08:42 PM.

    Leave a comment:


  • longpole001
    replied
    thanks richard i have sent you a pm ,

    Leave a comment:


  • longpole001
    replied
    hi richard i am trying to follow your 24bit ver so i can undertand it better with comments , can you fillin some blanks in the comments


    Code:
    '*  Notes   : 24 bit ver                                        *
    '*          :                                                   *
    '*          :  downloaded so i can comment and try understand it    *
    '*                                                              *
    '****************************************************************
    
                    
     DEFINE OSC 64 
            
     include "dt_ints-18c.bas"   ;  mod to work with mplabx   THIS NEW , NEED TO LOOK AT mplabx ver  and changes 
     Include "REENTERPBP-18.bas"
    
    ASM
    INT_LIST macro
            INT_Handler TMR1_INT , _TOCK,pbp,yes       ; timer1 overflow int call routine 
            INT_Handler TMR3_INT , _TICK,pbp,yes       ; timer3 overflow int call routine  
           endm
            INT_CREATE
        ENDASM 
    
       DEFINE DEBUG_REG PORTB       ; setup debug port of terminal 
       DEFINE DEBUG_BIT 7
       DEFINE DEBUG_BAUD 9600
       DEFINE DEBUG_MODE 0
    
    T3CON=$31 'set 1:8 prescale     ' T3CON  = %00110001     ' Timer 3 ,bit7-6 = TMR3 CLK source 00 = Instuction Clk(Fosc/4),01 =sys clk,10=ext clk,11=cap sense osc
              ' enable timer        ' bit5-4 = TMR3 prescale 00= 1:1,01= 1:2 ,10=1:4,,11=1:8   ,bit3=0 LP off,bit2=1 no sync ext CLK ,bit1= 0 n/a,Bit0=0 Timer 1 on/off
              ' place 8 bit loads
              ' uses sytem clk 
                                     
    T1CON=$8f ' set timer1 ext clk , t1clki pin (rising edge)   - external clock ref connected to pin 
              ' set 1:1 prescale              
              ' set no sync with ext clk, 
              ' 16bit operation 
              ' enable timer
    
    
    trisc=$ff
    trisb=$fc
    ANSELB=0
    ANSELC=0
    OSCCON=$70
    OSCTUNE.6=1
    TRISB.7=0  ;DEBUG
    LATB.7=1   ;DEBUG
    pause 2000
    
    @timer1 =TMR1L                ; place preload lower 8bit   into 16bit value into timer1 var 
    @timer3 =TMR3L                ; place preload lower 8bit   inot 16bit value into timer3 var 
    timer1 var word ext           ' setup the word ext varable 
    timer3 var word ext           ' setup word ext varable 
    
    seconds var word
    sn var word      ; now seconds
    tl var word                      ' ???
    te var word                      ' time ela
    tn var word      ;no tmr1 ticks    ???
    dup var bit                       '???
    dn  var word     ;display timer counter
    
    @ INT_ENABLE  TMR1_INT       ; start the interupts enable routines 
    @ INT_ENABLE  TMR3_INT
    Debug "Start",13 ,10
    
    
    seconds=0
    dn=0
    ' ---------- Main program ---------- 
     mainloop:
    
       if dup then                                                  ; if flag = 1 then 
           gosub getnow                                             ' do sub 
           te= tn-tl                                                ' te = timer1 ticks - 
           tl=tn
           Debug "loop t ",dec te,13 ,10,10
           te=tn**1998                                             ' ?????
           sn=sn+te/1000                                           ' seconds elapsed  = current seconds elapsed + timer1 ticks / 1000 ????????????
           Debug "elapsed t ",dec sn,".",dec3 te//1000, 13 ,10,10
           dup=0
       endif
     
     goto mainloop         
    
    '-----------sub Routines --------------
    ' 
     getnow:
        tn= timer1               ' save timer1 ticks to varable 
        pie1.0=0                 ' clear timer 1 interupt - why now ??? 
        sn = seconds             ' save seconds count to varable for display
        pie1.0=1                 ' set  timer1 interupt  - why now  ???
     return
    
    ' ---- ISR for timer1 ------------
    TOCK: 
     latb.0 = !latb.0                      '  timer1 clock input when low ? ???
     seconds=seconds+2                     ' increment secs by 2 for every count of input ?
    
    @    INT_RETURN 
        
    ' ----- ISR for timer3 -------------
    TICK: 
    t3con.0=0                               ' turn off timer3 
    timer3=timer3+25536      ;20mS          ' ??? not sure where these figures come from for preload value into timer 3 
    t3con.0=1                               ' turn on timeer 3 
    dn=dn+1                                 ' increment display timer counter 
    if dn>39 then                           ' if display count > 39 then - why 39 ???
        dup=1                               ' set flag so that it loads timer1 value ???
    endif
     
    
    @    INT_RETURN

    Leave a comment:


  • richard
    replied
    here's a stopwatch demo using a 32bit counter for 244uS ticks , its a lot simpler and can deliver millie second accuracy

    Code:
    '****************************************************************
    '*  Name    : ?.pbp                                 *
    '*  Author  : richard                                           *
    '*  Notice  :                                                   *
    '*          :                                                   *
    '*  Date    :                                                   *
    '*  Version :    18f25K22     @5.0 volts                        *
    '*  Notes   :   32k ext xtal clk for timer1                     *
    '*          :                                                   *
    '*            
    '****************************************************************
      
    #CONFIG
      CONFIG  FOSC = INTIO67
      CONFIG  PLLCFG = ON
      CONFIG  PRICLKEN = ON
      CONFIG  FCMEN = OFF
      CONFIG  IESO = OFF
      CONFIG  PWRTEN = ON
      CONFIG  BOREN = SBORDIS
      CONFIG  BORV = 190
      CONFIG  WDTEN = ON
      CONFIG  WDTPS = 32768
      CONFIG  CCP2MX = PORTC1
      CONFIG  PBADEN = OFF
      CONFIG  CCP3MX = PORTB5                                
      CONFIG  T3CMX = PORTC0
      CONFIG  HFOFST = ON
      CONFIG  P2BMX = PORTB5
      CONFIG  MCLRE = EXTMCLR
      CONFIG  STVREN = ON
      CONFIG  LVP = OFF
      CONFIG  XINST = OFF
      CONFIG  DEBUG = OFF
      CONFIG  CP0 = OFF
      CONFIG  CP1 = OFF
      CONFIG  CP2 = OFF
      CONFIG  CP3 = OFF
      CONFIG  CPB = OFF
      CONFIG  CPD = OFF
      CONFIG  WRT0 = OFF
      CONFIG  WRT1 = OFF
      CONFIG  WRT2 = OFF
      CONFIG  WRT3 = OFF
      CONFIG  WRTC = OFF
      CONFIG  WRTB = OFF
      CONFIG  WRTD = OFF
      CONFIG  EBTR0 = OFF
      CONFIG  EBTR1 = OFF
      CONFIG  EBTR2 = OFF
      CONFIG  EBTR3 = OFF
      CONFIG  EBTRB = OFF
    #ENDCONFIG
                    
     DEFINE OSC 64 
     PRECISION       CON 4 SYSTEM        
     include "dt_ints-18c.bas"
     Include "REENTERPBP-18.bas"
     Include "N-Bit_MATH.pbp"
    
    ASM
    INT_LIST macro
            INT_Handler TMR1_INT , _TOCK,pbp,yes
            INT_Handler TMR3_INT , _TICK,pbp,yes
           endm
            INT_CREATE
        ENDASM 
    
    DEFINE DEBUG_REG PORTB
    DEFINE DEBUG_BIT 7
    DEFINE DEBUG_BAUD 9600
    DEFINE DEBUG_MODE 0
    
    T3CON=$31
    T1CON=$Bf
    trisc=$ff
    trisb=$fc
    ANSELB=0
    ANSELC=0
    OSCCON=$70
    OSCTUNE.6=1
    TRISB.7=0  ;DEBUG
    LATB.7=1   ;DEBUG
    pause 2000
    @timer1 =TMR1L
    @timer3 =TMR3L
    timer1      var word ext
    timer3      var word ext
    ticks     var byte[4]
    sn          var byte[4]
    tmp         var byte[4]
    res         var byte[4] 
    start_sec   var byte[4]
    stop_sec    var byte[4] 
    start_tn    var word
    stop_tn     var word
    sw          var  portc.7
    elday       var byte
    elhour      var byte
    elmin       var byte
    elsec       var byte
    elmillie    var word
    tl          var word
    te          var word
    tn          var word
    dup         var bit
    tip         var bit
    sub         var bit
    dn          var word
    
    
    @ INT_ENABLE  TMR1_INT
    @ INT_ENABLE  TMR3_INT
    Debug "Start",13 ,10
    @  MATH_CLR  _ticks   ; clear an N-Bit variable   seconds=0
    @  MOVE?CP 354000000,  _ticks    ;day rollover  test
    dn=0
    tip=0
    dup=0
    sub=0
    
    mainloop:
    
    if !sw  then
        if tip  then
            gosub get_now
           
            @  MOVE?PP _sn ,_stop_sec 
            gosub dhms_time
            Debug 13,10,"stopwatch end ",9,dec elday,":",dec2 elhour,":",dec2 elmin,":",dec2 elsec,".",dec2 elmillie
            gosub delta_time 
            
             gosub dhms_time
            
            Debug 13,10,"elapsed    ",9,dec elday,":",dec2 elhour,":",dec2 elmin,":",dec2 elsec,".",dec2 elmillie
            tip=0
           
        else
            gosub get_now
           
            @  MOVE?PP _sn ,_start_sec 
            gosub dhms_time
            Debug 13,10,"stopwatch go ",9,dec elday,":",dec2 elhour,":",dec2 elmin,":",dec2 elsec,".",dec2 elmillie
            tip=1 
        endif
        while  !sw 
        wend
    endif
    if dup then
        gosub get_now
        te=tn-te
        gosub dhms_time
        Debug 13,10,"loop t ",dec te,13 ,10,10
        Debug 13,10,"current t ",dec elday,":",dec2 elhour,":",dec2 elmin,":",dec2 elsec,".",dec2 elmillie, 13 ,10,10
        te=tn
        dup=0
    endif
    
     
    goto mainloop         
    
    
    get_now:
        tn= timer1
        pie1.0=0
        @  MOVE?PP  _ticks, _res    
        pie1.0=1
        @  MOVE?WP _tn, _tmp
        @  MATH_ADD  _res , _tmp , _sn   ;  sn = ticks
        
    return
     
     
    
        
    dhms_time:       
        latb.0 = 1
        ;days
        @  MOVE?CP 354098360, _tmp
        @  MATH_DIV  _sn, _tmp, _res 
        @  MOVE?PB  _res, _elday
        @  MOVE?PP REG_Z, _sn
        ;hours
        @  MOVE?CP 14754098, _tmp
        @  MATH_DIV  _sn, _tmp, _res 
        @  MOVE?PB  _res, _elhour
        @  MOVE?PP REG_Z, _sn
        ;min
        @  MOVE?CP 245901, _tmp
        @  MATH_DIV  _sn, _tmp, _res 
        @  MOVE?PB  _res, _elmin
        @  MOVE?PP REG_Z, _sn
        ;sec
        @  MOVE?CP 4098, _tmp
        @  MATH_DIV  _sn, _tmp, _res 
        @  MOVE?PB  _res, _elsec
        @  MOVE?PW REG_Z, _tl
        elmillie=tl**1599       ;244uS ticks
        latb.0 = 0
    return    
        
        
       
        
        
    
    delta_time:
    
        @  MATH_SUB  _stop_sec , _start_sec , _sn
     
    
    return       
        
       
        
       
        
    
     
     
    
    
    TOCK: 
        
        @  MOVE?CP 65536, _tmp
        @  MATH_ADD  _ticks , _tmp , _res
        @  MOVE?PP _res, _ticks
    @    INT_RETURN    
     
    
    
    
    TICK: 
        t3con.0=0
        timer3=timer3+25536      ;20mS
        t3con.0=1
        dn=dn+1
        if dn>399 then
            dn=0
            dup=1
        endif
    @    INT_RETURN

    Leave a comment:


  • longpole001
    replied
    thanks richard

    i have also been looking at roman blacks works with timers

    some intreresting work in getting the system clock accurate as well

    Leave a comment:


  • richard
    replied
    24 bit version , should be good for 99 days

    Code:
    '****************************************************************
    '*  Name    : ?.pbp                                 *
    '*  Author  : richard                                           *
    '*  Notice  :                                                   *
    '*          :                                                   *
    '*  Date    :                                                   *
    '*  Version :    18f25K22     @5.0 volts                        *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '*            
    '****************************************************************
      
    #CONFIG
      CONFIG  FOSC = INTIO67
      CONFIG  PLLCFG = ON
      CONFIG  PRICLKEN = ON
      CONFIG  FCMEN = OFF
      CONFIG  IESO = OFF
      CONFIG  PWRTEN = ON
      CONFIG  BOREN = SBORDIS
      CONFIG  BORV = 190
      CONFIG  WDTEN = ON
      CONFIG  WDTPS = 32768
      CONFIG  CCP2MX = PORTC1
      CONFIG  PBADEN = OFF
      CONFIG  CCP3MX = PORTB5                                
      CONFIG  T3CMX = PORTC0
      CONFIG  HFOFST = ON
      CONFIG  P2BMX = PORTB5
      CONFIG  MCLRE = EXTMCLR
      CONFIG  STVREN = ON
      CONFIG  LVP = OFF
      CONFIG  XINST = OFF
      CONFIG  DEBUG = OFF
      CONFIG  CP0 = OFF
      CONFIG  CP1 = OFF
      CONFIG  CP2 = OFF
      CONFIG  CP3 = OFF
      CONFIG  CPB = OFF
      CONFIG  CPD = OFF
      CONFIG  WRT0 = OFF
      CONFIG  WRT1 = OFF
      CONFIG  WRT2 = OFF
      CONFIG  WRT3 = OFF
      CONFIG  WRTC = OFF
      CONFIG  WRTB = OFF
      CONFIG  WRTD = OFF
      CONFIG  EBTR0 = OFF
      CONFIG  EBTR1 = OFF
      CONFIG  EBTR2 = OFF
      CONFIG  EBTR3 = OFF
      CONFIG  EBTRB = OFF
    #ENDCONFIG
                    
     DEFINE OSC 64 
     PRECISION       CON 3 SYSTEM        
     include "dt_ints-18c.bas"
     Include "REENTERPBP-18.bas"
     Include "N-Bit_MATH.pbp"
    
    ASM
    INT_LIST macro
            INT_Handler TMR1_INT , _TOCK,pbp,yes
            INT_Handler TMR3_INT , _TICK,pbp,yes
           endm
            INT_CREATE
        ENDASM 
    
      DEFINE DEBUG_REG PORTB
       DEFINE DEBUG_BIT 7
       DEFINE DEBUG_BAUD 9600
       DEFINE DEBUG_MODE 0
    
    T3CON=$31
    T1CON=$8f
    trisc=$ff
    trisb=$fc
    ANSELB=0
    ANSELC=0
    OSCCON=$70
    OSCTUNE.6=1
    TRISB.7=0  ;DEBUG
    LATB.7=1   ;DEBUG
    pause 2000
    @timer1 =TMR1L
    @timer3 =TMR3L
    timer1 var word ext
    timer3 var word ext
    seconds var byte[3]
    sn var byte[3]
    tmp   var byte[3]
    res   var byte[3] 
    
    elday     var byte
    elhour    var byte
    elmin     var byte
    elsec     var byte
    elmillie  var word
    
    tl var word
    te var word
    tn var word
    dup var bit
    dn  var word
    
    @ INT_ENABLE  TMR1_INT
    @ INT_ENABLE  TMR3_INT
    Debug "Start",13 ,10
    @  MATH_CLR  _seconds   ; clear an N-Bit variable   seconds=0
    
    dn=0
    mainloop:
    
    if dup then
    gosub getnow
    
    te= tn-tl
    tl=tn
    Debug "loop t ",dec te,13 ,10,10
    
    Debug "elapsed t ",dec elday,":",dec2 elhour,":",dec2 elmin,":",dec2 elsec,".",dec3 elmillie, 13 ,10,10
    dup=0
    endif
    
     
    goto mainloop         
    
    
    getnow:
     tn= timer1
     pie1.0=0
     @  MOVE?PP  _seconds, _sn ;  sn = seconds    
     pie1.0=1
    elmillie=tn**1998 
    if    (elmillie/1000) then
    elmillie=elmillie//1000 
    @  MATH_INC  _sn 
    endif
    ;days
    @  MOVE?CP 86400, _tmp
    @  MATH_DIV  _sn, _tmp, _res 
    @  MOVE?PB  _res, _elday
    @  MOVE?PP REG_Z, _sn
    ;hours
    @  MOVE?CP 3600, _tmp
    @  MATH_DIV  _sn, _tmp, _res 
    @  MOVE?PB  _res, _elhour
    @  MOVE?PW REG_Z, _te
    ;min
    elmin=te/60
    ;sec
    elsec= te//60
    
    return
    
     
     
    
    
    TOCK: 
     latb.0 = !latb.0
     @  MATH_INC  _seconds
     @  MATH_INC  _seconds
    @    INT_RETURN 
    
    
    
    TICK: 
    t3con.0=0
    timer3=timer3+25536      ;20mS
    t3con.0=1
    dn=dn+1
    if dn>39 then
    dn=0
    dup=1
    endif
     
    
    @    INT_RETURN
    Last edited by richard; 08-08-2016, 10:30 PM.

    Leave a comment:


  • richard
    replied
    a simple system like this with your txco could easily deliver millisecond accuracy, if the seconds counter is made 24 bit then durations upto 194 days are possible


    simple ,easy adapatable [kiss]

    Code:
    '****************************************************************
    '*  Name    : ?.pbp                                 *
    '*  Author  : richard                                           *
    '*  Notice  :                                                   *
    '*          :                                                   *
    '*  Date    :                                                   *
    '*  Version :    18f25K22     @5.0 volts                        *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '*            
    '****************************************************************
      
    #CONFIG
      CONFIG  FOSC = INTIO67
      CONFIG  PLLCFG = ON
      CONFIG  PRICLKEN = ON
      CONFIG  FCMEN = OFF
      CONFIG  IESO = OFF
      CONFIG  PWRTEN = ON
      CONFIG  BOREN = SBORDIS
      CONFIG  BORV = 190
      CONFIG  WDTEN = ON
      CONFIG  WDTPS = 32768
      CONFIG  CCP2MX = PORTC1
      CONFIG  PBADEN = OFF
      CONFIG  CCP3MX = PORTB5                                
      CONFIG  T3CMX = PORTC0
      CONFIG  HFOFST = ON
      CONFIG  P2BMX = PORTB5
      CONFIG  MCLRE = EXTMCLR
      CONFIG  STVREN = ON
      CONFIG  LVP = OFF
      CONFIG  XINST = OFF
      CONFIG  DEBUG = OFF
      CONFIG  CP0 = OFF
      CONFIG  CP1 = OFF
      CONFIG  CP2 = OFF
      CONFIG  CP3 = OFF
      CONFIG  CPB = OFF
      CONFIG  CPD = OFF
      CONFIG  WRT0 = OFF
      CONFIG  WRT1 = OFF
      CONFIG  WRT2 = OFF
      CONFIG  WRT3 = OFF
      CONFIG  WRTC = OFF
      CONFIG  WRTB = OFF
      CONFIG  WRTD = OFF
      CONFIG  EBTR0 = OFF
      CONFIG  EBTR1 = OFF
      CONFIG  EBTR2 = OFF
      CONFIG  EBTR3 = OFF
      CONFIG  EBTRB = OFF
    #ENDCONFIG
                    
     DEFINE OSC 64 
            
     include "dt_ints-18c.bas"   ;  mod to work with mplabx
     Include "REENTERPBP-18.bas"
    
    ASM
    INT_LIST macro
            INT_Handler TMR1_INT , _TOCK,pbp,yes
            INT_Handler TMR3_INT , _TICK,pbp,yes
           endm
            INT_CREATE
        ENDASM 
    
       DEFINE DEBUG_REG PORTB
       DEFINE DEBUG_BIT 7
       DEFINE DEBUG_BAUD 9600
       DEFINE DEBUG_MODE 0
    
    T3CON=$31
    T1CON=$8f
    trisc=$ff
    trisb=$fc
    ANSELB=0
    ANSELC=0
    OSCCON=$70
    OSCTUNE.6=1
    TRISB.7=0  ;DEBUG
    LATB.7=1   ;DEBUG
    pause 2000
    @timer1 =TMR1L
    @timer3 =TMR3L
    timer1 var word ext
    timer3 var word ext
    seconds var word
    sn var word      ; now seconds
    tl var word
    te var word
    tn var word    ;no tmr1 ticks
    dup var bit
    dn  var word  ;display timer counter
    
    @ INT_ENABLE  TMR1_INT
    @ INT_ENABLE  TMR3_INT
    Debug "Start",13 ,10
    seconds=0
    dn=0
    mainloop:
    
    if dup then
    gosub getnow
    
    te= tn-tl
    tl=tn
    Debug "loop t ",dec te,13 ,10,10
    te=tn**1998
    sn=sn+te/1000
    Debug "elapsed t ",dec sn,".",dec3 te//1000, 13 ,10,10
    dup=0
    endif
    
     
    goto mainloop         
    
    
    getnow:
     tn= timer1
     pie1.0=0
     sn = seconds
     pie1.0=1
     return
    
    
    TOCK: 
     latb.0 = !latb.0
     seconds=seconds+2
    
    @    INT_RETURN 
     
       
    
    TICK: 
    t3con.0=0
    timer3=timer3+25536      ;20mS
    t3con.0=1
    dn=dn+1
    if dn>39 then
    dn=0
    dup=1
    endif
     
    
    @    INT_RETURN

    Leave a comment:


  • longpole001
    replied
    Originally posted by richard View Post

    the txco accuracy < 2 parts per million, your isr error > 3 parts /1000 (might as well use the internal clock)
    ?
    well if you have an example of how to do the code , that uses varables in the isr as i have it , using the TXCO output that is more accurate than what i am doing now ,

    other wise i think the system clock with the standard ISR is better than using the TXCO and jumping counts and still have a 4us error over 3 cycles

    the system clock can be setup to be accurate , for the time its setup ,

    Txco is consistant accurate , but not exact into any time period of 1/100th,

    Leave a comment:


  • longpole001
    replied
    well unfortunately i really need to use this isr as it the timer / varables for a lot of things

    all the variables are used directly to display / record times , etc , so to change the approach now is not practical
    there are multiple counters and other timers that use these varables for when and how things are used and displayed

    i have been able to get the exact time of 10ms by using the system clock , and then using osctune to get it exact , plus some padding of 1us within the timer code

    but its only exact while there is no drift in the system osc , and osctune is a only avaiable for the internal sys clock

    i was going to put an external tcxo to the pic , but soon found that would not help alot when can not do fine tuning for timer1 using osctune with an external TCXO

    i cant see a way to pad the isr code to give me small tuning when using an external ref of 32.768khz clock , except by doing what i have been for fine tune and it not nice way to do it

    thanks richard ,

    if you have any further way i might get it more accurate given the current isr then please post

    cheers from perth


    sheldon

    sheldon

    Leave a comment:


  • richard
    replied
    I can't see the point of having an accurate txco clock and mangling its output by adding or skipping counts. how is that ever going to result in accurate timings ? you are just introducing more error .the concept is flawed .


    the txco accuracy < 2 parts per million, your isr error > 3 parts /1000 (might as well use the internal clock)

    why is this 50 HZ mentioned / why 10mS /why 2.5ms
    how fast does a display really need to be updated [so its not a meaningless blur] ?

    whats more important accurate timing or fancy bluring numbers on a display ?
    Last edited by richard; 08-08-2016, 04:20 AM.

    Leave a comment:


  • richard
    replied
    that's not what I mean ,forget that isr completely





    timer1 isr would count 1 sec per overflow

    lets say the display is updated 4 times per sec via another isr

    the display isr would go

    hun=(timer1 ** 9994)/100
    arraywrite disp,[dec4 sec,".",dec2 hun,0]

    Leave a comment:


  • longpole001
    replied
    well i tried loading 327 x 30.5 = 9.9735ms in theory , measured at 49.9537hz ,
    when i removed /4 in the code for the pulse , so no gains over the last approch , and when i do 326 as a count i get 50.1005hz
    , again the same as when i had i added an extra count

    Code:
     ASM
     CLRF T_CNT                       ;  clear T_Cnt AT START
    TimerConst = 326                 ; 81 x 30.5us cycles from timer 1 clock 
    TimerConst = 65536 - TimerConst  ; set value for timer1 preload
    ;----------------- TimerConst value select ---------------------------
    TIME_CONST  macro 
         MOVLW   LOW(TimerConst)       ;  1
         ADDWF   TMR1L,F, 0            ;  1    
         BTFSC   STATUS,C              ;  1/2
         INCF    TMR1H,F, 0            ;  1
         MOVLW   HIGH(TimerConst)      ;  1
         ADDWF   TMR1H,F, 0            ;  1
         endm                                                            
    ;-----------------  ADD TimerConst to TMR1H:TMR1L -------------------------
    ADD2_TIMER   macro
         local notload4                ; keep the label local to the macro 
         BCF     T1CON,TMR1ON, 0       ;  1 Turn off timer
         TIME_CONST                    ;  get the base time const and load it into timer 1 
    ;     INCF T_CNT,F                  ;  Increment T_cnt
    ;     MOVLW 11                      ;  set 11 for value to compare ???
    ;     CPFSGT T_CNT                  ;  compare T_cnt > 3 - skip over label if greater  ?????
    ;     GOTO notload4                 ;  if not greater than 3 then goto label 
    ;     MOVLW 1                       ;  value to be added to const 
    ;     ADDWF TMR1L,F, 0              ;  add 1 to the const load value on the 4th time load to decrease time 
    ;     CLRF T_CNT                    ;  clear T_Cnt
    notload4
         endm
     ; -----------------  ADD TimerConst to TMR1H:TMR1L and restart TIMER1 ------
    RELOAD_TIMER  macro
         ADD2_TIMER
         BSF     T1CON,TMR1ON, 0       ;  1   Turn TIMER1 back on  (8 cycles)
         endm
    
    ; -----------------  Load TimerConst into TMR1H:TMR1L ----------------------
    LOAD_TIMER  macro
         MOVE?CT  0, T1CON,TMR1ON
         MOVE?CB  0, TMR1L
         MOVE?CB  0, TMR1H
         ADD2_TIMER
         endm
     ENDASM
    
    ' ------[ This is the Interrupt Handler ]-----------------------------------
    EL_ClockCount:
    
    @ RELOAD_TIMER  
    ;  EL_Ticks = EL_Ticks  + 1    ; each tick is 2.5ms
     
    
      IF EL_CountDown = 1 THEN             ' if countdown = 1 then count down enabled    
           EL2_allow = 0                    ' force no extra timeres when countdown else will display incorect overtime/timeleft : note need to allow count up otpion when conting down in extra timers 
     ;      if EL_ticks // T1PS =  0  THEN   ' if modulas of tips (4) = 0 
               IF EL_Days = 0 THEN
                  IF EL_Hours = 0 THEN
                    IF EL_Minutes = 0 THEN
                      IF EL_Seconds = 0 THEN
                         if EL_100th = 0 then 
                            EL_ZERO = 1
                         ENDIF
                      ENDIF
                    ENDIF
                  ENDIF
               endif
               if EL_100th > 0 then
                  EL_100th = EL_100th - 1 
                  EL_100thChanged = 1 
               else  
                  IF EL_Seconds > 0  THEN
                     EL_Seconds = EL_Seconds - 1
                     EL_100TH = 100
                     EL_SecondsChanged = 1
                  ELSE
                    IF EL_Minutes > 0 THEN
                       EL_Minutes = EL_Minutes - 1
                       EL_Seconds = 59
                       EL_SecondsChanged = 1
                       EL_MinutesChanged = 1
                    ELSE 
                        IF EL_Hours_EN = 1 and EL_Hours > 0 THEN
                           EL_Hours = EL_Hours - 1
                           EL_Minutes = 59
                           EL_Seconds = 59
                           EL_SecondsChanged = 1
                           EL_MinutesChanged = 1
                           EL_HoursChanged = 1
                        ELSE
                            IF EL_Days_EN = 1 and EL_Days > 0 THEN
                               EL_Days = EL_Days - 1
                               EL_Hours = 23
                               EL_Minutes = 59
                               EL_Seconds = 59
                               EL_SecondsChanged = 1
                               EL_MinutesChanged = 1
                               EL_HoursChanged = 1
                               EL_DaysChanged = 1
                            ELSE                      ; Zero already reached, shouldn't get here
                               EL_ZERO = 1            ; set flag for 0 reached 
                            ENDIF
                        ENDIF
                    ENDIF
                  ENDIF
               ENDIF
          ; ENDIF
      else                                     ' counting  up 
         ; if EL_ticks // T1PS = 0  THEN      ' if modulas of tips (4) = 0 
             if Internal_Cal = 1 then           ' if the internal calibration flag set - used with cro to check 10ms pulse 
               IF LATE.4 = 0 THEN           ' debug pin 
                   LATE.4 = 1
                ELSE 
                   LATE.4 = 0
                ENDIF   
             endif
              EL_100th = EL_100th + 1 
              EL_100thChanged = 1
              IF EL_100TH  = 100 THEN
                  EL_100TH = 0
                  EL_Seconds = EL_Seconds + 1      
                  EL_SecondsChanged = 1
                  IF EL_Seconds = 60 THEN
                     EL_Seconds = 0
                     EL_Minutes = EL_Minutes + 1
                     EL_MinutesChanged = 1
                  eNDIF
                  IF EL_Hours_EN = 1 and EL_Minutes = 60 THEN
                     EL_Minutes = 0
                     EL_Hours = EL_Hours + 1
                     EL_HoursChanged = 1
                  ENDIF
                  IF EL_Days_EN = 1 and EL_Hours = 24 THEN
                     EL_Hours = 0 
                     EL_Days = EL_Days + 1
                     EL_DaysChanged = 1
                  ENDIF
              eNDIF
         ; endif
      ENDIF

    Leave a comment:


  • richard
    replied
    not quite , when you update the display the 100 ths figure is timer1/655
    timer1 ** 9994 woyl give you 100 th s x 100

    Leave a comment:


  • longpole001
    replied
    ah ok i thikn i follow you now you say count 655 on timer 1 and just display the 1/100th

    Leave a comment:


  • richard
    replied
    TIMER1/655= 100th's of a second

    Leave a comment:

Working...
X