I need help to init and run timer for LPC17XX

58 Views Asked by At

To check that my timer works, I put a counter that increments every 1us. when I checked its value I found that it increments less quickly than it should can you check the configuration Example : In 529000 us -> counter = 123832 MR0I, MR0S et MR0S : TIMER match control register CE et CR : TIMER control register

#define PRESCALER_3   2
#define MR0I     0x00000001
#define MR0R     0x00000002
#define MR0S     0x00000004
#define CE  0x00000001
#define CR  0x00000002
    void TI_InitTimer(uint8_t u8_NumTimer, uint32_t u32_TempsUs, uint8_t u8_AutoRestart)
    {
        uint32_t u32_Horloge;
        uint32_t u32_Frequence;
    
       u32_Horloge = SY_PeriphClock();           // lire la fr�quence p�riph�rique
       u32_Frequence = 1000000 / u32_TempsUs;
    
       switch(u8_NumTimer)
       {
          case TIMER3:
          {
             PCONP |= PCTIM3;                     // Activer l'horloge du module timer 3
             T3PR = PRESCALER_3 - 1;              // Prescaler = 1 ==> clock / 2
             T3CTCR = 0;                          // Mode timer (comptage par fr�quence interne)
             T3MR0 = (u32_Horloge / PRESCALER_3) / u32_Frequence;
             T3MCR = 0;                           // Fonction comparateur inutilis�e
             T3EMR = 0;                           // Fonctions baculement de sortie inutilis�e
             T3MCR |= MR0R;                      
             T3MCR &= ~MR0S;                       
             T3MCR |= MR0I;                        
             T3TCR &= ~CE;
             T3TCR |= CR;                         
             T3TCR &= ~CR;
             T3TCR |= CE;                         
             IT_InitIrq(INT_TIMER3,PRIO_INT_TIMER3); 
             g_u8_CompteurTimer3 = 0;
             g_u8_AutoRestartTimer3 = u8_AutoRestart;
             break;
          }
          default: break;
       }
    }
    
    
    
    void TIMER3_IRQHandler(void)
    {
    uint8_t u8_Source;
    
       u8_Source = (uint8_t)T3IR;
       if((u8_Source & 0x01) != 0)                   // comparateur 0 ?
       {
           if(g_u8_AutoRestartTimer3 == OFF)
           {
              TI_ActiveTimer(TIMER3, OFF);
           }
           g_u8_CompteurTimer3++;
       }
       T3IR = u8_Source;
    }
0

There are 0 best solutions below