Menu

TMR2 bug in FF3.6

2010-12-05
2012-11-19
  • Mikael Nordman

    Mikael Nordman - 2010-12-05

    Hi Mikael,
    Thanks for the update on tmr2 in FF 3.6.

    I made the changes and played with tmr3 and tmr2 assembles.

    Just for information, here are my results…

    Putting a square wave on the o'scope, and looking at 1 sec pulses I get:

    Using the command    1000 ms_test   (decimal of course).
      TMR3      ~1.012 sec high and low periods.
      TMR2      ~1.016 sec high and low periods.

    ms_test  ( n - )
       begin
         porte c@ $0f and porte c!          \ turn 4 LEDs on
         dup ms                             \ pause
         porte c@ $f0 or porte c!           \ turn 4 LEDS off
         dup ms                             \ pause
         key?
       until  drop  ;

    Pete

    On 12/5/2010 2:25 AM, Mikael Nordman wrote:
    > Hi Pete.
    > Looked at this problem and found bug in WARM.
    > I have not used TMR2 for a long time.
    > I have not tested the correction but it shud
    > be alright. You have to undo your change in the
    > config file of course.
    >
    > 73s Mike
    >
    > #ifdef MS_TMR2
    >         ;; Timer 2 for 1 ms system tick
    >         movlw   h'7d'      ; Prescale = 4, Postscale = 16
    >         movwf   T2CON, A
    >         setf    PR2, A
    >         bsf     PIE1, TMR2IE, A
    > #else
    >
    > SHOULD BE :
    >
    > #ifdef MS_TMR2
    >         ;; Timer 2 for 1 ms system tick
    >         movlw   h'7d'      ; Prescale = 4, Postscale = 16
    >         movwf   T2CON, A
    >         movlw   tmr2ms_val
    >         movwf   PR2, A
    >         bsf     PIE1, TMR2IE, A
    > #else
    >
    >
    >
    > On 26.11.2010 20:34, Pete Zawasky wrote:
    >> Hi Mikael,
    >> I am back on 3.6 and the 18F6527 for a while.
    >>
    >> I noticed that TMR2 gives me double the MS timing.
    >> e.g. 2000 ms -- a 2 sec pause actually gives me a 4 sec pause.
    >>
    >> Changing the tmr2postscaler from d'16' to d'8' seems to correct the timing.
    >>
    >> TMR3 seems OK.
    >>
    >> Pete
    >>
    >
    >

     
  • Pete Zawasky

    Pete Zawasky - 2010-12-10

    Hi Mikael,
    With TMR2 and TMR3 working about the same,  I decided to stay with TMR3 in the Configure file, as I believe you have.
    I also took a look at  MS to tighten the timing up a bit:

    Here is a slight change to get rid of an extra ms time period that shows up on my PIC18F6527 (32MHz) apps.  Note the addition of 1- in the definition of MS.

    ; ms  +n -      Pause for n millisconds
    ; : ms ( +n - )    
    ;   ticks +
    ;   begin
    ;     pause dup ticks  -  1-  0<
    ;   until drop ;
    ;
            dw      link
    link    set     $
            db      NFA|2,"ms"
    MS:
            rcall   TICKS
            call    PLUS
    MS1:   
            call    PAUSE
            rcall   DUP_A
            rcall   TICKS
            call    MINUS
            call    ONEMINUS
            call    ZEROLESS
            movf    Sminus, W, A
            iorwf   Sminus, W, A
            bz      MS1
            goto    DROP

    Pete

     
  • Pete Zawasky

    Pete Zawasky - 2010-12-10

    But…. based on the definition of MS :

    ms         ( +n - )
               Wait for at least +n milliseconds,
               but not more than +n plus 2x the resolution of the TICK clock.

    I am back to your original MS code and TMR3 providing TICKs.

    TMR2 will be used for other things….

    Pete

     
  • Mikael Nordman

    Mikael Nordman - 2010-12-10

    Good that you found the actual definition of MS.
    I was going to look it up also.
    I had a similiar definition in mind.

    Mike

     

Log in to post a comment.