Menu

Timer0

Santiago
2009-03-26
2013-05-30
  • Santiago

    Santiago - 2009-03-26

    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.

     
    • Santiago

      Santiago - 2009-03-26

      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.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.