Skip to content

ATtiny 2 series RTC prescaler value incorrect, millis() and delay() run 32X faster than nominal. #1288

Description

@burnsb

Line 144 of timers.h:

#define _RTC_PRESCALE_VALUE (0x05)

Should be:

#define _RTC_PRESCALE_VALUE (0x28)

This affects line 367 of wiring.c

RTC.CTRLA = (RTC_RUNSTDBY_bm|RTC_RTCEN_bm|_RTC_PRESCALE_VALUE);//fire it up, prescale by 32.

Per pg 274 of the data sheet:

Image

So, the divide by 32 prescaler is 0x05, but it is shifted 3 bits.

To test this, under the tools menu in the Arduino IDE, set millis()/micros() Timer to RTC:

Image

Using the stock blink example, the led will flicker very fast. Adding the following to setup corrects the prescaler value and blink rate:

while(RTC.STATUS);
RTC.CTRLA |= (0x28);

See pull request #1289

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions