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,172


    Did you find this post helpful? Yes | No

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

    OSC 64 (16 + PLL)

    PS:00000000 00000100 <--- Dec=4
    TC:01100011 11001000 <--- Dec=25544

    I had same results manually this afternoon.

    Robert
    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
    May 2013
    Location
    australia
    Posts
    2,680


    Did you find this post helpful? Yes | No

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

    ok next whats in T1CON ?

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


    Did you find this post helpful? Yes | No

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

    Looking at the datasheet for 18F44K22, timer 1 has a 2 bit prescaler.

    4 (100) takes 3 bits.

    Gonna try timer 2.

    ...
    13.0 TIMER2/4/6 MODULE p.175
    ...
    • 8-bit Timer and Period registers (TMRx and PRx,
    respectively)
    • Readable and writable (both registers)
    • Software programmable prescaler (1:1, 1:4, 1:16)
    • Software programmable postscaler (1:1 to 1:16)
    ...

    EDIT: Darn, DT Elapsed include only has Timer1...

    Robert
    Last edited by Demon; - 23rd December 2014 at 03:31.
    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!

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


    Did you find this post helpful? Yes | No

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

    Was looking at T1CON register and noticed this:

    TxCKPS<1:0>: Timer1/3/5 Input Clock Prescale Select bits
    11 = 1:8 Prescale value
    10 = 1:4 Prescale value
    01 = 1:2 Prescale value
    00 = 1:1 Prescale value
    So that is 2 bits.


    Code:
    bit 7-6 TMRxCS<1:0>: Timer1/3/5 Clock Source Select bits
      11 =Reserved. Do not use.
      10 =Timer1/3/5 clock source is pin or oscillator:
        If TxSOSCEN = 0:
          External clock from TxCKI pin (on the rising edge)
        If TxSOSCEN = 1:
          Crystal oscillator on SOSCI/SOSCO pins
      01 =Timer1/3/5 clock source is system clock (FOSC)
      00 =Timer1/3/5 clock source is instruction clock (FOSC/4)
    
    bit 5-4 TxCKPS<1:0>: Timer1/3/5 Input Clock Prescale Select bits
      11 = 1:8 Prescale value
      10 = 1:4 Prescale value
      01 = 1:2 Prescale value
      00 = 1:1 Prescale value
    
    bit 3 TxSOSCEN: Secondary Oscillator Enable Control bit
      1 = Dedicated Secondary oscillator circuit enabled
      0 = Dedicated Secondary oscillator circuit disabled
    
    bit 2 TxSYNC: Timer1/3/5 External Clock Input Synchronization Control bit
        TMRxCS<1:0> = 1X
      1 = Do not synchronize external clock input
      0 = Synchronize external clock input with system clock (FOSC)
        TMRxCS<1:0> = 0X
      This bit is ignored. Timer1/3/5 uses the internal clock when TMRxCS<1:0> = 1X.
    
    bit 1 TxRD16: 16-Bit Read/Write Mode Enable bit
      1 = Enables register read/write of Timer1/3/5 in one 16-bit operation
      0 = Enables register read/write of Timer1/3/5 in two 8-bit operation
    
    bit 0 TMRxON: Timer1/3/5 On bit
      1 = Enables Timer1/3/5
      0 = Stops Timer1/3/5
        Clears Timer1/3/5 Gate flip-flop
    T1CON=00000000

    Robert
    Last edited by Demon; - 23rd December 2014 at 03:42.
    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
    May 2013
    Location
    australia
    Posts
    2,680


    Did you find this post helpful? Yes | No

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

    ITS NOT using the prescaler those bits need to be 00 ie 1:1
    @64mhz with a preload of 25544 you get a tmr1 int every 2.5mS dt's int routine inc's the tips counter till its 4 then inc's the elapsed time clock I count ie once every 10mS

    next step after confirming t1con is ok is to toggle a pin in the int routine as per what Sheldon suggested and verify 2.5mS ints are occurring

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


    Did you find this post helpful? Yes | No

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

    In the Elapsed include:

    Code:
    ...
    ' -------------- calc timer reload Constants -------------------------------
    ASM
    T1PS = 1                             ; start with 1:1 postscaler
    TimerConst = ((OSC*1000000)/4/100)   ; how many timer ticks will it take
      while TimerConst > 65400           ; if it's more than the timer can count
    T1PS = T1PS * 2                      ;   double the postscaler
    TimerConst = TimerConst / 2          ;   halve the count
      endw
    TimerConst = 65536 - TimerConst + 8  ; final reload value
    ...
    Darryl talks about a post-scaler. Timers 1, 3 and 5 have none for a 18F44K22?

    Neither does Timer 0, only Timers 2,4 and 6 have pre and post-scalers.

    Robert
    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!

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


    Did you find this post helpful? Yes | No

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

    Darryl talks about a post-scaler. Timers 1, 3 and 5 have none for a 18F44K22?

    Neither does Timer 0, only Timers 2,4 and 6 have pre and post-scalers
    hence the T1PS VAR

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    2,680


    Did you find this post helpful? Yes | No

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

    t1con looks good should be 0 or 1 (on or off) depending on what the int routine is up to

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 : 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