16F1937 8bit timer 2/4 & 6

Moderator: Benj

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8394
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2395 times
Been thanked: 3425 times
Contact:

16F1937 8bit timer 2/4 & 6

Postby medelec35 » Fri Aug 23, 2019 8:31 am

As timer 2/4 & 6 are 8 bits, they should not default to(or allow) 256 rollover value:
8 bit timer.png
8 bit timer.png (25.05 KiB) Viewed 260 times

When OK is clicked on the values are excepted.
These users thanked the author medelec35 for the post:
Benj (Wed Aug 28, 2019 4:00 pm)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
Benj
Matrix Staff
Posts: 14243
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4369 times
Been thanked: 4103 times
Contact:

Re: 16F1937 8bit timer 2/4 & 6

Postby Benj » Wed Aug 28, 2019 3:58 pm

Hi Martin,

The rollover of 256 as the default is correct.

The interrupt occurs when the count register goes from 255 to 0 e.g. the 256th count.

0 to 1 = count 1
1 to 2 = count 2
...
254 to 255 = count 255
255 to 0 = count 256

We use the rollover value - 1 behind the scenes in the rollover register so 256 would become 255 for say the PR2 register.
These users thanked the author Benj for the post:
medelec35 (Wed Aug 28, 2019 4:21 pm)
Rating: 5.26%
 

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8394
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2395 times
Been thanked: 3425 times
Contact:

Re: 16F1937 8bit timer 2/4 & 6

Postby medelec35 » Wed Aug 28, 2019 4:16 pm

Hi Ben,
Benj wrote:We use the rollover value - 1 behind the scenes in the rollover register so 256 would become 255 for say the PR2 register.

Ah I did not know that.
Thank you, that would explain it
These users thanked the author medelec35 for the post:
Benj (Wed Aug 28, 2019 4:19 pm)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.