Why does TIMER slow down when using longer pause


Results 1 to 6 of 6

Threaded View

  1. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by GrandPa View Post
    I would like first to thank Dave and Skimask for their answer. Actually I submitted a simplified version of the proble I got with timer.

    I first tried with this. As you can see I used TIMER1 as the clock source for TIMER3. Then I read TMR3H and TMR3L in a loop.

    Without any interrupt and I can't see why the Timer register is affected by how often it is read during a certain time. This is why I tried with no luck using interrupt. So the question is still the same. Why do I get different values when I use longer pause ???
    I'd be willing to bet that TMR3 is rolling over so fast, that you're not seeing the actual value; you're actually seeing just the lower 16 bits of that value. If TMR3 had 32 bits, you might see the value increasing past 65535.
    The difference between using pause 50 and pause 500 might be just enough difference in the number of instructions to give you that difference that you're seeing.
    Try this and see how fast it actually rolls over:
    I added another counter that'll pick up the number of times that TMR3 rolled over and a counter that'll show you how fast the loop goes thru (which really doesn't have anything to do with how fast TMR3 counts other than the oscillator's speed).
    DEFINE RESET_ORG 800h
    DEFINE OSC 32
    DEFINE LCD_LINES 4
    DEFINE LCD_DREG PORTD
    DEFINE LCD_RSREG PORTC
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTC
    DEFINE LCD_EBIT 1
    OSCCON = %11110000 '8 mhz, internal osc
    OSCTUNE = %11000000 '4x PLL enabled
    T1CON.7 = 1 '16 bits read/write
    T1CON.6 = 0 'clock from internal osc
    T1CON.5 = 1 '1:8 prescale
    T1CON.4 = 1 '1:8 prescale
    T1CON.3 = 0 'osc shut off
    T1CON.2 = 1
    T1CON.1 = 0 'Internal clock
    T1CON.0 = 1 'enabled
    T3CON.7 = 1 '16 bits read/write
    T3CON.5 = 1 '1:8 prescale
    T3CON.4 = 1 '1:8 prescale
    T3CON.1 = 1 'clock from timer1
    T3CON.0 = 1 'enabled
    myTMR var word
    oldmyTMR var word
    myTMR = 0
    rollover var word
    timesthru var word
    TMR3H = 0
    TMR3L = 0
    lcdout $fe , 1
    start:
    myTMR.byte1 = tmr3h
    myTMR.byte0 = tmr3l
    if oldmyTMR > myTMR then rollover = rollover + 1 'TMR3 rolled over back to zero because the old value is greater than the new value
    LCDout $FE,$80, "timer:" , DEC myTMR , " "
    lcdout $fe , $c0, "rollover:",DEC rollover, " "
    lcdout $fe , $94, "times thru:", DEC timesthru, " "
    oldmyTMR = myTMR
    timesthru = timesthru + 1
    goto start
    Last edited by skimask; - 5th July 2007 at 23:17.

Similar Threads

  1. Delayed output 10 secs
    By lilimike in forum mel PIC BASIC Pro
    Replies: 37
    Last Post: - 14th October 2011, 06:28
  2. Old and beyond help ?
    By DavidFMarks in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 11th December 2008, 15:23
  3. Replies: 11
    Last Post: - 12th July 2008, 02:36
  4. Fade out LEDs question
    By Sam in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 22nd June 2008, 10:50
  5. Help Quick Need to make code smaller
    By Programmednew in forum mel PIC BASIC Pro
    Replies: 41
    Last Post: - 25th January 2005, 03:46

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