Elapsed timer not working as expected at 64MHz


Closed Thread
Results 1 to 40 of 56

Hybrid View

  1. #1
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Elapsed timer not working as expected at 64MHz

    Roger, oveur.
    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
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: Elapsed timer not working as expected at 64MHz

    yep there was no elapsed-18_k22

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,643


    Did you find this post helpful? Yes | No

    Default Re: Elapsed timer not working as expected at 64MHz

    seems to me the easiest way to restore correct function for "ticks" when the post scaler is in use is to move the ticks loop inside the post scale loop , no extra vars no extra overhead

    Code:
    ClockCount:
    @ RELOAD_TIMER                   ; Reload TIMER1
    
        T1Post = T1Post + 1
        IF T1Post = T1PS THEN
          T1Post = 0
         Ticks = Ticks + 1
            IF Ticks = 100 THEN
               Ticks = 0
               Seconds = Seconds + 1
               SecondsChanged = 1
               IF Seconds = 60 THEN
                  Seconds = 0
                  Minutes = Minutes + 1
                  MinutesChanged = 1
               ENDIF
               IF Minutes = 60 THEN
                  Minutes = 0
                  Hours = Hours + 1
                  HoursChanged = 1
               ENDIF
               IF Hours = 24 THEN
                  Days = Days + 1
                  DaysChanged = 1
                  Hours = 0
               ENDIF
           ENDIF
        ENDIF
    @ INT_RETURN                     ; Restore context and return from interrupt

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Elapsed timer not working as expected at 64MHz

    I can only think that there was a reason why Darrel did it as he did. The dude could probably code this stuff while playing ping pong; the Bruce Lee of PBP and ASM.

    There's more than one way to solve a problem, he probably took the one that worked for all PICs (until the K22 series came along). And even that he's solved the problem, it just wasn't widely known. I can only think he had greater concerns on his mind. Can you imagine how much of a headache it must have been tracking the new releases versus his routines? Makes me appreciate and miss him even more.

    I now fear the day when Microchip releases a new product line. I love the K22 like I loved the 16F628 and 16F877, I'm not changing unless I'm forced to change.

    Shoot, I might even stay on PBP 2.6. LOL

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,643


    Did you find this post helpful? Yes | No

    Default Re: Elapsed timer not working as expected at 64MHz

    it has nothing to do with the k22's its the problem exists whenever the T1PS value is >1 on any chip
    its all to do with the way he implemented the post scaling , the loops are inside out . its no bigie to fix . its only apparent if you need to use "ticks" .
    imho most of the time using ticks is pointless by the time you process the reading and then display it it's already meaningless and out of date . if you want to time events to such accuracy trigger times need to be allowed for and properly sync'ed , there are much better ways
    ps
    the k22 interrupt vagaries are a separate issue and unrelated to ticks not being 100th's of a sec
    Last edited by richard; - 24th December 2014 at 02:16. Reason: ps

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Elapsed timer not working as expected at 64MHz

    its only apparent if you understand what's going on .
    There, fixed it for you. LOL

    I never dealt with timer guts before. I always thought pre-scaling and post-scaling were what the fish looked like when my mom prepared them.

    Oh and I don't like fish.

    Robert

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


    Did you find this post helpful? Yes | No

    Default Re: Elapsed timer not working as expected at 64MHz

    you have to toggle your led at the correct place in the loop
    the interrupt runs at 4x the speed required (because of high fosc not chip type ) for timing so the post scaler divides it by 4


    ClockCount:
    @ RELOAD_TIMER ; Reload TIMER1

    T1Post = T1Post + 1
    Robert toggle your pin here eg latd.0=!latd.0 for 2.5mS
    IF T1Post = T1PS THEN
    T1Post = 0
    Ticks = Ticks + 1
    Robert toggle your pin here eg latd.1=!latd.1 for 10mS
    IF Ticks = 100 THEN
    Ticks = 0
    Seconds = Seconds + 1
    SecondsChanged = 1
    IF Seconds = 60 THEN
    Seconds = 0
    Minutes = Minutes + 1
    MinutesChanged = 1
    ENDIF
    IF Minutes = 60 THEN
    Minutes = 0
    Hours = Hours + 1
    HoursChanged = 1
    ENDIF
    IF Hours = 24 THEN
    Days = Days + 1
    DaysChanged = 1
    Hours = 0
    ENDIF
    ENDIF
    ENDIF
    @ INT_RETURN ; Restore context and return from interrupt

  8. #8
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Elapsed timer not working as expected at 64MHz

    Quote Originally Posted by richard View Post
    you have to toggle your led at the correct place in the loop
    the interrupt runs at 4x the speed required (because of high fosc not chip type ) for timing so the post scaler divides it by 4
    I know that now because I've spent 3 days on this. LOL

    But ask me in a week and I won't remember, I'll spend another day running around my tail wondering why I get 4 times too many ticks at 64MHz.

    I might eventually remember this long-term, if I do it for weeks. But I have sleep apnea that can't be treated completely, so what I experience during the day doesn't always get stored properly overnight in my sleep. Consider me as obsessive compulsive against my will. I can leave comments about quadruple ticking, but I'll glance over the comment and ignore it until it bites my face for a day or so. LOL

    Shoot, my wife gave me $600 a month ago and I totally forgot.

    Robert

  9. #9
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Elapsed timer not working as expected at 64MHz

    Quote Originally Posted by richard View Post
    ...imho most of the time using ticks is pointless by the time you process the reading and then display it it's already meaningless and out of date . if you want to time events to such accuracy trigger times need to be allowed for and properly sync'ed , there are much better ways
    ps
    the k22 interrupt vagaries are a separate issue and unrelated to ticks not being 100th's of a sec
    I disagree. This is the first time I have a specialized need for a timer and it requires knowing how long a tick really is. I want to debounce using interrupts, so I press a button, look how long it takes for the contact to close and open again, take an arbitrary average and add maybe 25%, that's my debounce in mSeconds.

    I know others use timers in what I consider a more complicated way, I have no clue how a preload value works and can never remember if the timer counts up or down from there (I have a hard time remembering little details like that). To them it's easier, I prefer the elapsed timer approach.

    I turn a LED on and off, check the interval on the Saleae probe (I should get a commission every time I typed that), and that's it. Ticks=10mS is stuck in my brain ever since I first saw it on Darrel's include. I just count the ticks until I get my interval.

    When you think about it, if we were that concerned with accuracy, we'd program in assembler.

    Robert

Similar Threads

  1. I2CRead & I2CWrite not working as expected
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 30
    Last Post: - 27th October 2021, 18:36
  2. PORTB.3 Input not working as expected.
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th March 2013, 09:58
  3. Elapsed Timer Demo
    By Darrel Taylor in forum Code Examples
    Replies: 111
    Last Post: - 29th October 2012, 17:39
  4. SPWM and Elapsed Timer
    By CocaColaKid in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 8th May 2008, 03:16
  5. DT Elapsed Timer
    By rwskinner in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 9th March 2008, 23:17

Members who have read this thread : 2

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