Elapsed timer not working as expected at 64MHz


Closed Thread
Results 1 to 40 of 56

Hybrid View

  1. #1
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

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

    Hi Robert,
    Getting to know the timer is fine, but that would be otherwise extreme for button debounce.
    You can do a program timer to lock the button for a delay after being pushed.

    Code:
    dtimer var byte
    dtimer = 0
    
    main:
    
    IF port.1 = 1 && dtimer = 0 then
    dtimer = 200
    gosub fire ‘oh no, he pushed the button, all hell is going to break loose.
    endif
    
    
    IF dtimer > 0 then
    dtimer = dtimer-1
    endif
    
    goto main
    If you needed interrupt driven buttons it would pay to set the timer in the ISR and
    decrement the timer in your main program, and reenable interrupts when the timer reaches zero.

    It’s good practice to keep interrupts for the thing that really needs it… like keeping real time is a good example

    With regard to the speed, you can’t count to 400 in your Ticks byte,
    but you can count to 240 Seconds (instead of 60 Seconds) to delay the time

    Code:
               IF Seconds = 240 THEN
                  Seconds = 0
                  Minutes = Minutes + 1
                  MinutesChanged = 1
               ENDIF
    Now if you have to display the seconds anywhere just:

    Code:
    DisplaySeconds var byte
    
    DisplaySeconds = Seconds / 4 ‘ divide by four
    ‘print Hours, Minutes, DisplaySeconds.
    If you needed a high speed signal find and asm routine to rotate a byte with carry, and output bit.0 out a pin.
    The benefit of that is ensuring it takes a constant period of time to run the check.
    You might find in this code:

    Code:
    IF flag = 0 then
    flag = 1
    else
    flag = 0
    endif
    once it’s decompiled it could take a cycle less to execute depending on the result.
    So if you’re trying to produce a square wave it could be jagged.
    These things are easier to do with HPWM of you have the hardware though.

  2. #2
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

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

    With the thing running exactly 4 times too fast I would have rotated this byte (with carry),
    and read the value of bit0 each time:
    Code:
    %00001111

Similar Threads

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

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