This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

General Purpose Timer 1

Hi

I have been going through example and I am struck on one thing....

Need to generate 250mS

So I look at the table, the fastest rate which allws timer T3 to have a period of 250mS is 156.25 kHz hence T31= 100b

250mS/420 = 59.52 where 420mS is the maximum period.

The intial value of the timer register is 39009 (65535*0.595)...

I am still baffled with value of T3_RELOAD=100 so can someone kindly tell where 100 come from?

Thank you

#include <reg167.h>

#define T3_RELOAD 39009      /* T3 reload value : 250 ms */
//#define T3_RELOAD 100      /* T3 reload value : 250 ms */

/* Timer T3 ISR */
void T3_elapsed(void) interrupt 0x23 {

   T3 = T3_RELOAD;           /* reset T3 */
   P2 ^= 0x0001;             /* toggle P2.1 */

}

/* main program */
void main(void) {

  DP2 |= 0x0001;             /* P2.1 : output */
  P2  |= 0x0001;             /* initially: LED off */

  T3 = T3_RELOAD;            /* load initial timer value T3 */

  /* T3 in timer mode, counting down, pre-scale factor 128, period: 420 ms  */
  /* alternate output function disabled */
  /* T3CON = 0000.0000.1000.0100 = 0x0084 */
  T3CON = 0x0084;
  T3IC  = 0x0044;            /* enable T3 interrupt, ILVL = 1, GLVL = 0 */

  IEN = 1;                   /* allow all interrupts to happen */

  T3R = 1;                   /* start timer (T3CON |= 0x0040) */

  while(1);                  /* forever... */

} /* main */

Parents Reply Children
  • Sorry

    It is C166 processor

    Fiona

  • Hi

    I have the similar problem with general purpose timer.

    I have been following a similar example but on XC161 processor....

    250ms

    According to table 14-8 (XC161 Volume 2 Peripheral Units), I intend to use fSYS=40MHz and 156.25kHz (419.4ms)which indicates that I need to implement 256 for overall divider factor.

    Now should I look at table 14-6 to select any Block Prescaler 1 then find Tx1?

    I am bit lost there at the moment

    Any help would be greatly appreicated

    Eric Boon

  • Hi Fiona,

    Is the example you are referring to public? You have not given enough information as to the context of the original example to understand why the 100 is used for a reload value.

    To your example, the cpu is running at 20MHz I guess? So to generate a period of 250ms then you need a prescaler of at least 128.

    20MHz/128 = 156.25KHz timer clock or 6.4usec per tick.

    You have the T3 counting down so you simply need to put in a reload value that brings you closest to 250msec.

    250msec/6.4usec = 39062.5 so this is rounded to 39062 which ends up at 250.003msec. The underflow happens when 0 goes to 65535

    Eric,

    The XC16x devices have additional capabilities defined in the peripheral and also a system clock prescaler.

    So you also need to be aware of the BPS1 bitfield and use the default value of 0, which then brings you to the same calculation as to the period.

    Given a fSYS=40MHz, the GPT1 needs a prescaler of 256 to have a maximum period of 419.4msec.

    //  Configuration of Timer Block Prescaler 1:
    //  - prescaler for timer block 1 is 8
    
    //  Configuration of the GPT1 Core Timer 3:
    //  -----------------------------------------------------------------------
    //  - timer 3 works in timer mode
    //  - external up/down control is disabled
    //  - prescaler factor is 256
    //  - up/down control bit is set
    //  - alternate output function T3OUT (P3.3) is disabled
    //  - timer 3 output toggle latch (T3OTL) is set to 0
    
    GPT12E_T3CON  =  0x0085;
    GPT12E_T3 =  0x9896;
    

    If you really want to be accurate you can use T2 to automatically reload T3.

    //  -----------------------------------------------------------------------
    //  Configuration of the GPT1 Auxiliary Timer 2:
    //  - timer 2 works in reload mode
    //  - external up/down control is disabled
    //  - timer 2 is clocked by any transition of output toggle latch T3OTL
    //  - timer 2 run bit is reset
    GPT12E_T2CON   =  0x0027;
    GPT12E_T2      =  0x9896;
    

  • Happy new year 2006 Chris....


    Can you please kindly explain where the value comes from GPT12E_T3?

    Eric

  • Ah I got it now...

    39062 = 0x9896

    Btw do you have any more example of using general peripheral ranging from CAPCOM and PWM?

    Eric

  • ...do you have any more example of using general peripheral ranging from CAPCOM and PWM?


    Try http://www.hitex.co.uk or http://www.hitex.co.uk/download/c166examples/examplesrequest.html


    You'll find a wealth of information here, as well as many "must-have" tools for C16x development.

    Steph-

  • Eric,

    A short answer your question is no.

    I think like a lot of people, I answer questions in the forum on my own time so my preference (effort) would be to answer a specific question not generate code examples. Very simple code is fine to get the point across but I think it is more important for you to understand the underlying concepts. Here I am more than willing to go the extra mile to try to answer your questions.

    -Chris

  • I suggest: use Infineon DaVE together with the simulator to find out how the peripherals work.

    See: http://www.keil.com/appnotes/docs/apnt_182.asp