14 Replies Latest reply on Mar 12, 2015 5:57 PM by user_343349849

    Timer dropping out too soon

    user_343349849

       I am using the code below (copied from an example on the web) to provide a timeout feature for a routine.

         

      However, whatever value I use when calling the routine (100, 1000, 5000), the timeout seems to happen immediatly and not at 100ms or 1000 ms or 5000 ms.

         

      The timer component is set up as 32 bit timer with 24MHz clock and interrupt on TC.

         

      Help much appreciated

         

       

         

      CY_ISR(TimerINT){

         

          Timer_ReadStatusRegister();

         

          Timer_Flag = 1;

         

      }

         

       

         

      void ms_delay (uint32 ms) {

         

          Timer_Init(); // config but don't start the timeout counter

         

          isr_Timer_StartEx(TimerINT);

         

          uint32 period = 24000000/1000*ms;

         

          Timer_WritePeriod(period);

         

          Timer_Enable(); // start the timeout counter

         

          while(!Timer_Flag){};

         

          Timer_Stop();

         

              Timer_Flag = 0;

         

      }