0

I'm using ATtiny44 with Arduino IDE according to this tutorial: http://highlowtech.org/?p=1695

I have a problem with millis(). When I use an internal 1 MHz clock it works correctly but when I use external 16 MHz clock it takes millis() much more time than one second to be divisible by 1000.

I tested it with LCD and Hello World sketch, modified to correspond ATtiny's pins. Do millis() actually work with Tiny's?

Why does it work properly with 1MHz and not with 16 MHz which is the same as used in Arduino platform.

  • Did you forget to unprogram CKDIV8? – Ignacio Vazquez-Abrams Jul 13 '16 at 8:20
  • 3
    Testing whether millis() is divisible by 1000 is a terrible idea. With a 16 MHz clock millis does not count every millisecond: it is updated only every 1024 µs and occasionally jumps by 2 ms. – Edgar Bonet Jul 13 '16 at 9:41
  • Please post the Fuses config – Talk2 Jul 13 '16 at 10:40
  • 1
    If you are specific about 'much more time', that will help people to explain the specific problem you observed. As you can see, there are several possible interpretations of the problem. – Sean Houlihane Jul 13 '16 at 12:06
1

Let me guess: "much more time" is about, ohhh, 16 times?

When millis() was written, it had to assume what the input clock was. There is no way to detect the speed of the input clock: to do so would require another clock! So the writers of the function defined a starting constant, set it to 1000000, and required anyone that changed the clock would have to change that constant.

Find the constant, and set it to 16000000. Voilà!

Here's an article on the source code of the function:

https://ucexperiment.wordpress.com/2012/03/16/examination-of-the-arduino-millis-function/

  • I think faster clock and F_CPU 1000000UL results in "much less time", not in "much more time". – KIIV Jul 14 '16 at 10:51
  • Except that he's dividing by 1000 - or is he dividing 1000 by it? There's an inversion going on... Or @EdgarBonet is correct, and he's missing the crucial point in time when it is exactly divisible – John Burger Jul 15 '16 at 0:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.