Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2.0.0. ATtiny85 Delay() too long at 4MHz and 2MHz internal OSC speed #818

Open
hmeijdam opened this issue Nov 5, 2023 · 1 comment
Open

Comments

@hmeijdam
Copy link
Contributor

hmeijdam commented Nov 5, 2023

While playing with the ADC clock and the USI 4-bit timer, I noticed odd things at 4MHz clock speed when using V2.0.0. Then I noticed that delay() was also off at 4MHz.

This sketch should demonstrate the issue, as it's supposed to produces 100Hz on PB1 at 16, 8, 4, 2 and 1MHz

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {  // 100Hz on pin PB1
  digitalWrite(LED_BUILTIN, HIGH);
  delay(5);
  digitalWrite(LED_BUILTIN, LOW);
  delay(5);
}

The results are:

16MHz PLL : 100Hz
8MHz internal osc : 100Hz
4MHz internal osc : 25Hz
2MHz internal osc : 50Hz
1MHz internal osc : 100Hz

I looked in wiring.c if i could see something obvious going wrong with the clock prescaling but could not find a cause.

I suspected it has to do with clock prescaling, because the ADC clock (manually prescaled by me) also slowed down by a factor 8 while I expected a factor 2 when I switched from 8MHz to 4MHz.

On the board managers release 1.5.2 the delay worked fine and I got 100Hz on all clock frequencies.

@ahshah
Copy link

ahshah commented Jan 17, 2024

Took some time during lunch to narrow this down. Breaking change seemed to occur @ e8209f4
If you can get passed the compilation error on the '85 here, you'll see bad clocking. But not at the commit previous:
579388e

Please use supplied patch and confirm things are working again. I don't know if the patch is technically what we want, but it sure makes the waveforms better. Note the boards.txt changes- it requires a restart of the IDE and a reflash of the bootloader to set the fuses.
0001-Fix-up-clocks-4mhz.patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants