AnsweredAssumed Answered

Timer/PWM inizialization

Question asked by roberto.m on Oct 13, 2010
Latest reply on Oct 14, 2010 by roberto.m

Hi to all.
I'm using Timer/PWM Module, on my qe64, to get a timer. Until today I need only one timer
and with this code:

void init_tpm ()
{
   // Impostazioni: attivazione clock alla periferica TPM1
  SCGC1_TPM1 = 1;          

  // Impostazioni  TPM1
   TPM1SC = 0x48;

  // 0b01001000
  //   ||||||||   Divisore del clock della sorgente 111>>128;000>>1
  //   |||||||+-- TPM1SC_PS0   = 0; 
  //   ||||||+--- TPM1SC_PS1   = 0; 
  //   |||||+---- TPM1SC_PS2   = 0;
  //   ||||| 
  //   |||||   Settando i bit CLSKA/B del registro TPM1SC si
  //   |||||   sceglie come clk di riferimento il clk del bus
  //   |||||
  //   ||||+----- TPM1SC_CLKSA = 1;
  //   |||+------ TPM1SC_CLKSB = 0;
  //   ||+-------
  //   |+-------- TPM1SC_TOIE  = 1;
  //   +--------- Sola lettura
  
  // Impostazione del modulo del contatore: quando lo raggiunge si resetta  
  TPM1MOD = 20000;          

  
  // Impostando i bit EdgeLevelSelect il controllo delle porte non è
  // della periferica TPM
 
   TPM1C0SC_ELS0B = 0;
   TPM1C0SC_ELS0A = 0;                   

   TPM1C1SC_ELS1B = 0;         
   TPM1C1SC_ELS1A = 0;         

   TPM1C2SC_ELS2B = 0;
   TPM1C2SC_ELS2A = 0; 
}

and:

__interrupt VectorNumber_Vtpm1ovf void TI1_Interrupt (void)

 {                                        
    // Reset del flag di overflow
   TPM1SC_TOF = 0;
 
   DisableInterrupts;                      

  ...
  ...
  ... 

   EnableInterrupts;
 }

Now I need more timers. So i thinked to set the TPM counter as a free running timer counter and use
two channels.
I started with one channel. Here is the code:

void init_tpm1 ()
 { 
   // Impostazioni: attivazione clock alla periferica TPM1
   SCGC1_TPM1 = 1;          

  // Impostazioni  TPM1
   TPM1SC = 0x08; // no TOF - interrupt ENABLE
 
  TPM1MOD = 0; // free running timer counter

   // CH 0
  TPM1C0SC = 0x40;

  TPM1C0V = 20000;

    // CH 1
 
  TPM1C1SC = 0;
  TPM1C1V = 0;

 
  // CH 2 
  TPM1C2SC = 0;
  
  TPM1C2V = 0;   
  
 }

and:

__interrupt VectorNumber_Vtpm1ch0 void TI0CH_Interrupt (void)

 {                                        
    // Reset del flag di overflow
   TPM1C0SC_CH0F = 0;
 
   DisableInterrupts;                      

   ...
  ...
  ...

   EnableInterrupts;
 }

I expected to have the same behaviour. But I never reach __interrupt VectorNumber_Vtpm1ch0 void TI0CH_Interrupt (void)
Where I'm wrong?

Outcomes