pic 18 timer

Author
shanishp
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2007/09/19 01:09:35
  • Location: 0
  • Status: offline
2007/09/19 01:14:32 (permalink)
0

pic 18 timer

hi
    i want to know more about the specification of RD 16 bit(MSB of timer1 and timer3).its function,its need ,how timer value can be read and write in one 16 bit operation and two 8 bit operation.if any knows please reply me back at
  shanishp@esmarttechnologies.net
i will be thankfull if any one explain with example
also want to know where i will get 18 series reference manual

shanishp
junior engineer
esmart cochin
india
#1

9 Replies Related Threads

    assaad
    Super Member
    • Total Posts : 2504
    • Reward points : 0
    • Joined: 2006/03/27 22:51:42
    • Location: Turkey
    • Status: offline
    RE: pic 18 timer 2007/09/19 01:18:14 (permalink)
    0
    please post your m.o.b.i.le phone number , so we can send the answer by  SMS.

    check   www.microchip.com   !
    post edited by assaad - 2007/09/19 01:26:46

    S. ASSAAD
    #2
    magio
    Super Member
    • Total Posts : 2164
    • Reward points : 0
    • Status: offline
    RE: pic 18 timer 2007/09/19 05:31:55 (permalink)
    0
    shanishp the info you are requesting is in every 18F datasheet I've read.

    Is it for homework? if is such a case, you could read the datasheet and then ask a punctual question on your doubts, will make things easier for us and for you

    Embedded Software and Hardware Development


    #3
    shanishp
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2007/09/19 01:09:35
    • Location: 0
    • Status: offline
    RE: pic 18 timer 2007/09/21 04:32:05 (permalink)
    0
    hi
    iam so confused with bit RD16 of timer1.there they have given that by setting the corresponding pin we will be able to read the timer in one 16 bit operation.how is it possible .could u please justify it.

    shanishp
    junior engineer
    esmart cochin
    india
    #4
    DSchabel
    Super Member
    • Total Posts : 1714
    • Reward points : 0
    • Joined: 2005/05/24 14:00:34
    • Location: Western NY State
    • Status: offline
    RE: pic 18 timer 2007/09/21 13:57:16 (permalink)
    0
    ORIGINAL: shanishp

    hi
    iam so confused with bit RD16 of timer1.there they have given that by setting the corresponding pin we will be able to read the timer in one 16 bit operation.how is it possible .could u please justify it.

    i tnk i cld f u wd ask yr ? in a coherent wy but tht doesnt sm likly & i dnt hv the tme 2 decode yr wrtng
    #5
    fraser543
    New Member
    • Total Posts : 23
    • Reward points : 0
    • Joined: 2007/07/29 15:40:27
    • Location: 0
    • Status: offline
    RE: pic 18 timer 2007/09/21 14:20:54 (permalink)
    0
    I believe the question is clear. On timer 1 when you set RD16 (bit 7 of T1CON) what would be an example of C code to read the timer as a 16 bit number?
    #6
    breyno2
    Super Member
    • Total Posts : 533
    • Reward points : 0
    • Joined: 2005/05/20 10:36:36
    • Status: offline
    RE: pic 18 timer 2007/09/22 04:56:53 (permalink)
    0
    This is right out of a data sheet.
     
    When the RD16 control bit (T1CON<7>) is set, the address for TMR1H is mapped to a buffer register for the high byte of Timer1.
     
    A read from TMR1L will load the contents of the high byte of Timer1 into the Timer1 high byte buffer.
     
    This provides the user with the ability to accurately read all 16 bits of Timer1 without having to determine whether a read of the high byte, followed by a read of the low byte, has become invalid due to a rollover between reads.
     
    So reading TMR1L places a snapshot of TMR1H in an internal buffer. Effectively reading all 16-bits of Timer1 at the same time.
     
    You still need to read TMR1H after reading TMR1L, but at least you know TMR1H was captured at the instant TMR1L was.
     

    Regards,

    Bruce
    http://www.rentron.com
    #7
    fraser543
    New Member
    • Total Posts : 23
    • Reward points : 0
    • Joined: 2007/07/29 15:40:27
    • Location: 0
    • Status: offline
    RE: pic 18 timer 2007/09/22 09:27:29 (permalink)
    0
    Thank you however that did not exactly answer Stanishp's question and request. From his input he had read the manual but did not understand it and was requesting a simple code example to help him. What is the name of the buffer for the high byte, TMR1H?
     
    Stanishp, what I would do is read the low byte and put it in a 16 bit variable. read the high byte and put it in another 16 bit variable. Now shift the High byte to the high end of the variable. You can do a left shift or simply multiply it by 16. Now OR the two variables and you will have the whole timer. (I am not the expert here so this is how I see the issue and only trying to help) 
    I'm sure there are other experts here will have a much better way of doing it.
    #8
    breyno2
    Super Member
    • Total Posts : 533
    • Reward points : 0
    • Joined: 2005/05/20 10:36:36
    • Status: offline
    RE: pic 18 timer 2007/09/22 11:09:08 (permalink)
    0
    Here's one way with C18. Note I copied the Timers union from C18 timers.h and t1read.c so it's more visible than including timers.h and using the ReadTimer1 function.

    #include  <p18f2525.h>
    #include  <delays.h>
    #pragma   config OSC=HS,LVP=OFF,WDT=OFF,MCLRE=OFF

    /* used to hold 16-bit timer value */
    union Timers
    {
    unsigned int lt;
    char bt[2];
    };

    void main(void)
    {                     
      unsigned int Timer1Value = 0;
     
      union Timers Timer;
      Timer.bt[0] = TMR1L;    // Read Lower byte
      Timer.bt[1] = TMR1H;    // Read upper byte
     
      TMR1H = 0;
      TMR1L = 0;

      // 16-bit R/W mode, 1:1 prescale, int clk, Timer1 on
      T1CON = 0b10000001;
      
      while(1)
    {
       Delay100TCYx(10);       // wait 100 cycles * 10
       Timer.bt[0] = TMR1L;    // read low byte
       Timer.bt[1] = TMR1H;    // read high byte
       Timer1Value = Timer.lt; // get 16-bit value
       TMR1H = 0;
       TMR1L = 0;                // clear timer1 count
    }
    }

    You can run it through MPSIM, make changes, and see how it works in both modes.
     
    What is the name of the buffer for the high byte, TMR1H?

    Yes it's still named TMR1H. It's just remapped so when in 16-bit mode, you're not actually reading TMR1H directly. It's a shadow buffer that is loaded with the actual Timer1 high byte count on read of TMR1L.
     
    It is a tad confusing I guess, but you don't have direct access to TMR1H in 16-bit R/W mode. Only the shadow buffer that TMR1H is mapped to.
    post edited by breyno2 - 2007/09/22 12:00:09

    Regards,

    Bruce
    http://www.rentron.com
    #9
    fraser543
    New Member
    • Total Posts : 23
    • Reward points : 0
    • Joined: 2007/07/29 15:40:27
    • Location: 0
    • Status: offline
    RE: pic 18 timer 2007/09/22 14:28:20 (permalink)
    0
    Thank you, I appreciate your response and I hope Stanishp passes his class. wink
    #10
    Jump to:
    © 2017 APG vNext Commercial Version 4.5