Hot!MCC PIC18F45K50 Timer 0 16bits mode configuration BUG

Author
laffont
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2018/02/07 10:11:10
  • Location: 0
  • Status: offline
2018/02/09 05:59:09 (permalink)
4 (2)

MCC PIC18F45K50 Timer 0 16bits mode configuration BUG

Hello,

I have strange behaviour, probably a bug.
 
MPLABX 4.05
XC8 1.45
Pickit 3 (01.51.06)
PIC18F45K50 (dip40)
MCC (Core v4.35)
 
With MCC configurator
Using internal oscillator 16Mhz, and D0 as output.
Add Timer0 in 16bits mode (prescaler 128) and 100ms period

Main loop:
...
    while (1)
    {
        IO_RD0_Toggle();
        while(!INTCONbits.TMR0IF);
        INTCONbits.TMR0IF=0;
        TMR0_Reload();
    }
 
Led toggle every 2s (tmr0 timeout) and not 100ms
 
 

Searching :

 
TMR0 Initialisation MCC Generated :


void TMR0_Initialize(void)
{
    // Set TMR0 to the options selected in the User Interface

    // TMR0H 243;
    TMR0H = 0xF3;

    // TMR0L 202;
    TMR0L = 0xCA;
   
    // Load TMR0 value to the 16-bit reload variable
    timer0ReloadVal = (TMR0H << 8) | TMR0L;

    // Clearing IF flag
    INTCONbits.TMR0IF = 0;

    // T0PS 1:128; T08BIT 16 bits; T0SE Increment_hi_lo; T0CS FOSC/4; TMR0ON enabled; PSA assigned;
    T0CON = 0x96;
}


Writing to TMR0H is done as Timer0 is not configured, and thus always in 8bits mode/
So writing to TMR0H is not valid, and timer0ReloadVal is not correct (high nibble is 0).

So TMR0_Reload(); will fail to reload good value after timer0 interrupt.
 
Forcing TmR0 to 16 bits before configurations :
T0CONbits.T08BIT=0;
Everything works as expected.



Sample project attached.
 
Have a nice day.
 
#1

8 Replies Related Threads

    davekw7x
    Entropy++
    • Total Posts : 1569
    • Reward points : 0
    • Joined: 2012/01/16 12:01:07
    • Location: Left Coast, USA
    • Status: offline
    Re: MCC PIC18F45K50 Timer 0 16bits mode configuration BUG 2018/02/09 12:47:09 (permalink)
    0
    laffont
    ...probably a bug...

    Definitely a bug.  I don't think I would have encountered it in my "normal" modus operandi, since I don't use reloadable timers when timers with period registers are available.
     
    Bottom line:
    Your analysis and explanation were so very good that I didn't have to look at it closer, but just for the heck of it I created my own MCC project, similar to yours, and found exactly the same (bad) code and same fix.  (Verified on my PIC18F45K50 development board.)
     
    Submit a ticket to Microchip.
     
    Thanks for posting!  (+1)
     
    Regards,

    Dave
    post edited by davekw7x - 2018/02/10 08:58:14

    Sometimes I just can't help myself...
    #2
    DaveTiffTaylor
    Starting Member
    • Total Posts : 36
    • Reward points : 0
    • Joined: 2012/01/24 05:11:39
    • Location: 0
    • Status: offline
    Re: MCC PIC18F45K50 Timer 0 16bits mode configuration BUG 2018/03/08 08:13:49 (permalink)
    0
    Hi did you get a reply
     
    I have the same issue, MCC has created the code that generates an error.
     
    79 timer0ReloadVal = (TMR0H << 8) | TMR0L;
     
    mcc_generated_files/tmr0.c:79: warning: (373) implicit signed to unsigned conversion
     
    Regards, Dave
    #3
    qɥb
    Monolothic Member
    • Total Posts : 3329
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: MCC PIC18F45K50 Timer 0 16bits mode configuration BUG 2018/03/08 12:11:05 (permalink)
    0
    Learn the difference between an "error" and a "warning"
    DaveTiffTaylor
    ...
    I have the same issue, MCC has created the code that generates an error.
     
    79 timer0ReloadVal = (TMR0H << 8) | TMR0L;
     
    mcc_generated_files/tmr0.c:79: warning: (373) implicit signed to unsigned conversion

    This is the latest version of the compiler being a bit picky. There are a number recent topics discussing this.
    It is only a warning.

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #4
    RISC
    Super Member
    • Total Posts : 5301
    • Reward points : 0
    • Status: offline
    Re: MCC PIC18F45K50 Timer 0 16bits mode configuration BUG 2018/03/08 16:07:48 (permalink)
    0
    Hi,
    This issue was reported and will be fixed in the next MCC plugin version
    Regards
    #5
    DaveTiffTaylor
    Starting Member
    • Total Posts : 36
    • Reward points : 0
    • Joined: 2012/01/24 05:11:39
    • Location: 0
    • Status: offline
    Re: MCC PIC18F45K50 Timer 0 16bits mode configuration BUG 2018/03/09 01:32:20 (permalink)
    0
    qɥb
    Learn the difference between an "error" and a "warning"

     
    It may flag it as a warning but as the 1st post states
    laffont
    "So writing to TMR0H is not valid, and timer0ReloadVal is not correct (high nibble is 0)."

     
    I have the same problem, my timer0 high byte is always re-loaded with 0, which is a bug or error.
     
    Re Dave
    #6
    qɥb
    Monolothic Member
    • Total Posts : 3329
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: MCC PIC18F45K50 Timer 0 16bits mode configuration BUG 2018/03/09 01:48:22 (permalink)
    0
    Yes, that's a problem, but it has nothing to do with the warning issued by the compiler.
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #7
    1and0
    Access is Denied
    • Total Posts : 8458
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: MCC PIC18F45K50 Timer 0 16bits mode configuration BUG 2018/03/09 02:13:06 (permalink)
    4 (1)
    DaveTiffTaylor
    It may flag it as a warning but as the 1st post states
    laffont
    "So writing to TMR0H is not valid, and timer0ReloadVal is not correct (high nibble is 0)."

    I have the same problem, my timer0 high byte is always re-loaded with 0, which is a bug or error.

    As Qub said, the bug and the warning are two different things. Timer0 is configured as an 8-bit timer/counter upon Reset, and as such TMR0H is not used in 8-bit mode.
     
    The warning message, as said, is _not_ an error message. For this statement
    timer0ReloadVal = (TMR0H << 8) | TMR0L;

    the | operator promotes both its operand to signed int, and the result is a signed int but assigns to an unsigned int; hence the warning by the picky compiler.
    #8
    1and0
    Access is Denied
    • Total Posts : 8458
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: MCC PIC18F45K50 Timer 0 16bits mode configuration BUG 2018/03/09 03:29:19 (permalink)
    4 (1)
    Speaking of this MCC code
     // TMR0H 243; 
    TMR0H = 0xF3;
     // TMR0L 202;
    TMR0L = 0xCA;

    // Load TMR0 value to the 16-bit reload variable
    timer0ReloadVal = (TMR0H << 8) | TMR0L;

    it would be more efficient to do this instead
     // TMR0H 243; 
    TMR0H = 0xF3;
     // TMR0L 202;
    TMR0L = 0xCA;

    // Load value to the 16-bit reload variable
    timer0ReloadVal = 0xF3CA;

    and avoid this bug all together.
     
    Edit: However, the initial Timer0 value may not loaded correctly until it is configured to 16-bit mode. Still, it is more efficient to initialize the reload variable with a literal -- Pro mode might be smarter.
    post edited by 1and0 - 2018/03/09 03:38:37
    #9
    Jump to:
    © 2018 APG vNext Commercial Version 4.5