4 Replies Latest reply on Dec 27, 2014 8:21 AM by user_1377889

    Clarification for timer restart

    user_343349849

       From what I understand, the Timer component will reload the period register everytime it gets to 0.

         

      Can I simply write the count = 0 to force the timer to start over ?

         

      For example, I want to add a timeout to a serial rx routine...

         

      CY_ISR(mytimerint){

         

        Timer_ReadeStatusRegister(); //clear interrupt

         

        timeout = 1;

         

      }

         

       

         

      in my routine.........

         

      timeout = 0;

         

      Timer_WriteCounter(0);

         

      while(!timeout){

         

        //do my stuff

         

      }

        • 1. Re: Clarification for timer restart
          user_343349849

           Looking through previous posts, I note this issue of being able to reset the timer to form non-blocking version of CyDelay come sup time and again.

             

          Has Cypress not come up with a non-blocking timer function yet? It seems to me that dropping down components and using control components and logic levels simply to get a non-blocking timeout funtion is convoluted.

             

          It appears in my previous post, I would also need to stop the timer before setting counter value and then restart. So, to get a simple non-blocking timeout function I need to set up a volatile flag, create a timer interrupt that sets the flag and clears the interrupt then in code. I need to place a Timer, Low digital level, Clock and isr on the work sheet and then in the main code have to stop the timer, set counter value to 0, reset the timeout flag and start the time again.

             

          Something real simple like below would seem more convenient to me...

             

          CyTimeout(100);

             

          While(!CyTimedOut){

             

          //do stuff

             

          }

          • 2. Re: Clarification for timer restart
            user_1377889

            Yes, you are quite right. This is the exactly the code I used for my own. I'm afraid Cypress cannot provide us with every solution, some we have to do ourselves. You may of course write your own timer/timeout components and use them where required.

               

             

               

            Bob

            • 3. Re: Clarification for timer restart
              user_14586677

              A HW reset via control reg would be an option .....

                 

               

                 

                 

               

                 

              Regards, Dana.

              • 4. Re: Clarification for timer restart
                user_1377889

                I prefer the good ol' software solution...

                   

                You may even set the clock to MHz and get µs resolution

                   

                Example was compiled using Creator 3.1 beta release and a Pioneer BLE kit.

                   

                 

                   

                Bob