Millis and Delay On Timer0 For ATtiny85 using 1.6.1

Hi All,

I am sorry if this has been answered, but I have been searching for days and have not found how to do this. I would like to use timer1 for my project and read in a few places that you should be able to move millis and delay to timer0, but I cannot find a how-to on this. There is some old posting saying that you have to change "TIMER_TO_USE_FOR_MILLIS" somewhere, but I have searched my arduino install and cannot find the files the postings are alluding to. Is this still possible on 1.6.1 and if so, how do I do it?

Thanks, Jose

Depends on the core you're using - the default core only supports millis() being on timer 0. https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/wiring.c

If you're using a custom core, many of them do have support for a TIMER_TO_USE_FOR_MILLIS, so that you can specify a different timer - but all the cores I've seen default to using timer0 for millis, not timer1, so you should be all set anyway. It's possible that some cores exist where this is not the case.

DrAzzy: ...but all the cores I've seen default to using timer0 for millis, not timer1...

https://github.com/SpenceKonde/arduino-tiny-841

https://github.com/SpenceKonde/arduino-tiny-841/blob/master/avr/cores/tiny/core_build_options.h#L153 https://github.com/SpenceKonde/arduino-tiny-841/blob/master/avr/cores/tiny/core_build_options.h#L168

:wink:

:-P

Well, do note that my tiny841 core doesn't support those parts - only 841 and 1634. I didn't look at the debris from the old arduino-tiny code. Why did they use timer1 for millis on that version of the core?

DrAzzy: Why did they use timer1 for millis on that version of the core?

I suspect Google will reveal a post containing the answer much faster than I can create yet another one.

Hummm - I can't seem to find it, in that case. I've gotten a few pages into the search results, without any information on this...

I can find lots of people discussing the fact that timer1 is used for millis by default (which is no longer true if you use the core that comes with the IDE), and what a timer is, but not why the choice to use timer1 instead of timer0 for millis on the '85 was made.

DrAzzy: Hummm - I can't seem to find it, in that case.

I can't either. Sorry about that. I know I've written about it several times but I just cannot find the right incantation for the Great and Wise Gorcle.

As far as I can tell, timer 1 with the x5 family is one of a kind. There is no other timer like it in the AVR world.

Timer 0, on the other hand, is just like timer 0 on nearly all other AVR processors and is nearly identical to all eight-bit ATmega timers.

Having the core use the strange timer 1 makes the familiar timer 0 available for the user.

Thanks!

I can't say I agree with that logic, but I can see why that might have some appeal. The problem is that people normally avoid timer0 and use the other timers, because timer0 is used for millis, so manipulating timer0 is less familiar than it's ubiquity would suggest.

The timer1 on the '861 is also weird, but it's much weirder than the '85's (both are weird for the same reason, i think - they're high-speed timers that can run off the PLL)

Timer1 is a much cooler timer, since it can use the PLL, and has that 14-bit prescaler. You can run it as high as 64mhz, or as low as 512hz with the chip running at 8mhz.

DrAzzy:
The problem is that people normally avoid timer0 and use the other timers, because timer0 is used for millis, so manipulating timer0 is less familiar than it’s ubiquity would suggest.

I assume you missed this…

…and is nearly identical to all eight-bit ATmega timers.

The x5 timer 0 is nearly identical to the m328 timer 2; a timer very familiar to Arduino folks.

The timer1 on the '861 is also weird…

Everything about the t861 is weird. But it is a good choice for three-phase motor control.