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

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
ToVa_285016
Level 5
Level 5
100 replies posted 50 replies posted 50 questions asked

 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

0 Likes
3 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

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.

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

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

0 Likes