Author Topic: Major problem(s) with wiring.c  (Read 2370 times)

Crypter

  • Newbie
  • *
  • Posts: 1
Major problem(s) with wiring.c
« on: January 19, 2016, 02:03:38 pm »
This is my first thread here, I'm sorry if I go against some rule, please inform me if I do. I apologize in advance.

I've been experiencing major timing problems with the millis() function that is part of wiring.c (the same library that delivers the so famous delay() function). Once I set the PWM frequency scaller (MS_TIMER_TICK_EVERY_X_CYCLES) to something other than 64 the problems begin. If the scaller is 1 the timings are exactly two times slower than expected, and the problem persists with the rest of the possible values too (8, 256, 1024).

Code: [Select]
//do_someting() will be executed after two seconds if MS_TIMER_TICK_EVERY_X_CYCLES is set to 1
time=millis();
while (millis()-time < 1000) do_nothing();
do_something();

The problem appears only when "Digispark (Default - 16.5MHz)" is selected as a board, with the rest of the options (No USB) everything works as expected. Is it possible that the clock calibration breaks it somehow? Should this be submitted as a bug? Am I doing something wrong?

P.S: The delay() function works OK as far as I noticed.

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: Major problem(s) with wiring.c
« Reply #1 on: April 01, 2016, 04:00:57 pm »
If the Digispark is not plugged into a real computer USB port then it cannot tune its timing on boot to 16.5mhz - could that be the issue you are seeing? (I've never had timing issues with I2C and the Digispark, on or off USB, but it is possible)