3 Replies Latest reply on Dec 9, 2018 10:27 PM by user_13463998

    Timer_ReadPeriod() Bug?  Always reads 1 lower than period...

    user_385543602

       Hi,

         

      I am doing some math in a project using a timers period, and it always reads 1 less than the actual period of the timer.  See attached.  Is this a bug or am I horribly mistaken?

         

      Thank you,

         

      Tom

        • 1. Re: Timer_ReadPeriod() Bug?  Always reads 1 lower than period...
          user_1377889

          From timer datasheet pg 5

             

          Period (Software Option)
          The Period parameter defines the period of the counter. The max count value (or rollover point) for the Timer component is equal to the Period minus one. The Period minus one is the initial value loaded into the period register. The software can change this register at any time with the Timer_WritePeriod() API. To get the equivalent result using this API, the Period value from the customizer, minus one, must be used as the argument in the function.

             

           

             

          Bob

          • 2. Re: Timer_ReadPeriod() Bug?  Always reads 1 lower than period...
            user_14586677

            You are reading the period register, and that does not change unless you

               

            write to it.

               

             

               

            I think what you want is to read the actual timer value, which would be

               

            to execute Timer_ReadCounter().

               

             

               

            If you simply want to confirm what period you have set the Timer to then you

               

            do use Timer_ReadPeriod(), and as Bob mention, it is 1 less than the actual

               

            period.

               

             

               

            Regards, Dana.

            • 3. Re: Timer_ReadPeriod() Bug?  Always reads 1 lower than period...
              user_13463998

              Hi,

               

              It seems that Timer_ReadPeriod() is returning the "max" value of the counter,

              so Bob-san's answer must be correct.

               

              But meantime, reading the API reference, there is no hint/information that the returned value is "period - 1".

              So, IMHO, the function description in the datasheet is misleading.

               

              I hope that in the future it will be modified something like

              Return Value:

              uint8/16/32: Current period value - 1....

               

              ========================

              uint8/16/32 Timer_ReadPeriod(void)

              Description:

              Reads the period register.

              Parameters:

              None

              Return Value:

              uint8/16/32: Current period value. For 24-bit Timers, the return type is uint32.

              Side Effects:

              None

              ========================

               

              moto