I think there is a bug in timer.h, function: SInitTimer0 (line 152), that affects to the counter mode.
This is the actual fuction:
Sub SInitTimer0
OPTION_REG = OPTION_REG AND 192
SET OPTION_REG.PSA OFF
if TMR0Source = Osc THEN SET OPTION_REG.T0SE OFF
if TMR0Source = Ext THEN SET OPTION_REG.T0SE ON
clrwdt
OPTION_REG = OPTION_REG OR TMR0Pres
End Sub
The error is in: OPTION_REG.T0SE when it should be OPTION_REG.T0SC (source clock)
I also suggest an easy optimization:
Sub Sub SInitTimer0 OPTION_REG = OPTION_REG AND 192 if TMR0Source = Ext THEN SET OPTION_REG.T0SC ON OPTION_REG = TMR0Pres OR OPTION_REG clrwdt End Sub
All bit refering to timer0 are cleared at: OPTION_REG AND 192 Then the lines that clear a bit are no needed:
SET OPTION_REG.PSA OFF if TMR0Source = Osc THEN SET OPTION_REG.T0SE OFF
And This line generates a shorter asm code than the original:
OPTION_REG = TMR0Pres OR OPTION_REG
Greetings.
Sorry there is a typo error in my previous post:
OPTION_REG.T0SC is erroneus
it should be: OPTION_REG.T0CS
Log in to post a comment.
I think there is a bug in timer.h, function: SInitTimer0 (line 152), that affects to the counter mode.
This is the actual fuction:
Sub SInitTimer0
OPTION_REG = OPTION_REG AND 192
SET OPTION_REG.PSA OFF
if TMR0Source = Osc THEN SET OPTION_REG.T0SE OFF
if TMR0Source = Ext THEN SET OPTION_REG.T0SE ON
clrwdt
OPTION_REG = OPTION_REG OR TMR0Pres
End Sub
The error is in: OPTION_REG.T0SE when it should be OPTION_REG.T0SC (source clock)
I also suggest an easy optimization:
Sub Sub SInitTimer0
OPTION_REG = OPTION_REG AND 192
if TMR0Source = Ext THEN SET OPTION_REG.T0SC ON
OPTION_REG = TMR0Pres OR OPTION_REG
clrwdt
End Sub
All bit refering to timer0 are cleared at: OPTION_REG AND 192
Then the lines that clear a bit are no needed:
SET OPTION_REG.PSA OFF
if TMR0Source = Osc THEN SET OPTION_REG.T0SE OFF
And This line generates a shorter asm code than the original:
OPTION_REG = TMR0Pres OR OPTION_REG
Greetings.
Sorry there is a typo error in my previous post:
OPTION_REG.T0SC is erroneus
it should be: OPTION_REG.T0CS