+ Post New Thread
Results 1 to 2 of 2
  1. #1
    Member level 2
    Points: 443, Level: 4

    Join Date
    Apr 2018
    Posts
    45
    Helped
    0 / 0
    Points
    443
    Level
    4

    Why 'T2CONbits.TOUTPS =4;' instead of '9' to get 2.048 msec delay interrupt

    hi.

    It is a tutorilas where timer2 of pic16f887 with 20MHZ x-tal is being used with following settings and remarks by author,

    Code:
       T2CONbits.TOUTPS =4;   //postsacler is /10 so 204.8us * 10 to 2.048 ms   
    
      T2CONbits.T2CKPS = 1;                                                                 
      TMR2=0x0;

    With the above by author,

    For the case of //T2CONbits.T2CKPS = 1; >>

    FOSC/4(20/4=5MHZ ==0.2US), PS=1, ie., 1:4(datasheet), So, 0.2*4=0.8usec, as PR2 is FF on every reset

    and then TMR2 and PR2 match>> at 0.8*256=204.8 usec. Till here this is OK.



    But for //T2CONbits.TOUTPS =4; >>

    Author stating thet delay 2.048 msec (=204.8*10)

    My question is >>

    Why 'TOUTPS =4' ???

    Its coming at '9' instead of '4' (as datasheet say 1:10 for the value of '9') to get 2.048 msesc delay

    Then only FLAG OF TMR2 AT (10*204.8)=2.048 msec.

    May be I am missing some other things, could you help me out...

    tnx..

    •   AltAdvertisement

        
       

  2. #2
    Super Moderator
    Points: 79,227, Level: 68
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    12,976
    Helped
    4332 / 4332
    Points
    79,227
    Level
    68

    Re: Why 'T2CONbits.TOUTPS =4;' instead of '9' to get 2.048 msec delay interrupt

    Setting the TOUTPS value to 4 (0100 in binary) gives a division ratio of 1:5 not 1:10 so I think the author is wrong, the value should be 9 (1001 in binary).

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



--[[ ]]--