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

Attiny13 delay function issue #31

Open
dev-board-tech opened this issue Dec 9, 2024 · 8 comments
Open

Attiny13 delay function issue #31

dev-board-tech opened this issue Dec 9, 2024 · 8 comments

Comments

@dev-board-tech
Copy link

My setup is:
uC = ATTiny13A
Override clock sources = Internal oscillator 600Khz
Override frequency = Default
Brown out detection = 2.7V
Use Bootloader = No
Processor Speed = 4.8Mhz Internal oscillator
Mills, Tone support = Mills available, No Tone
Link time optimization = LTO Enabled
Mills accurate = Default
Print support = Bin only
Serial support = Half duplex (Read + Write)
Processor support = Attiny13a

I use Arduino IDE 2.3.4

The issue is that at compilation time instead of being consistent compiling the delay routine for 600Khz, sometime compile it as for 4.8Mhz and sometime for 600Khz, is randomly alternating between the two but only when changes are made into the sketch source code.

Maybe F_CPU is defined twice somewhere, once for 600Khz and once for 4.8Mhz, and depending of the order of compilation will use one or the other.

The fuses are written correctly, as Internal oscillator 4.8Mhz and DIV8 enabled that gives a 600Khz core frequency.

Anyway, thank you for your work, is very useful and let me run from using a VM with windows on it.

@sleemanj
Copy link
Owner

sleemanj commented Dec 9, 2024 via email

@dev-board-tech
Copy link
Author

The application Is very simple:
A bit-bang DHT22 driver, a bit-bang Usart TX and some delays, that's all.

I attach the final code, ehh, not quite final, on what you can see is nothing special, but I have that behavior if I use delay and DelayMicroseconds, of course when the behavior was shown there was no interrupt enabled, was nothing to interfere with the delay routine.

I implemented custom delay into the sketch as of now.

What I observed is that when is compiling for 4.8Mhz the resulted binary is a little bit bigger that if is compiling for the correct frequency 600Khz.

HumTempSensor_Arduino_Attiny13A.zip

@dev-board-tech
Copy link
Author

Open an example for Attiny13 and put the below lines into the main file

#define XSTR(x) STR(x)
#define STR(x) #x
#pragma message XSTR(F_CPU)

You can see that at first building after any source code change will show that F_CPU is 4.8Mhz instead of 600Khz, after fist several retry builds, will show the correct F_CPU frequency 600Khz as long as there is no source code changed, but after the build that show the correct frequency will build it correctly till you change the source code.

At last in Arduino 2.3.4...

But if you use Arduino 1.6.x maybe this issue is not showing...

If you have other version of Arduino and you don't have this issue please tell me, maybe is an Arduino issue and not the F_CPU definition.

@sleemanj
Copy link
Owner

sleemanj commented Dec 10, 2024 via email

@sleemanj
Copy link
Owner

Ok I have confirmed more or less this in 2.x

The reason is no doubt that the Arduino IDE is not respecting the order of the various settings menus, so later ones (as I defined them) are no longer guaranteed to override earlier ones.

As we see, 2.x on the left, 1.x on the right, completely different ordering, only the correct ordering will function correctly

settings-38

I imagine this might be a known problem with 2.x, but as it's been out for quite some time, you'd think it would have been fixed if it was going to be fixed. Perhaps there is a bug report under Arduino's repositories for it somewhere.

@sleemanj
Copy link
Owner

This may be the issue...
arduino/arduino-ide#2036

@sleemanj
Copy link
Owner

Yes I'm fairly certain that is that, or this arduino/arduino-cli#2018 or this arduino/arduino-cli#2209

Whatever the case, this is an Arduino software issue, and I don't see a way to fix it unfortunately. I recommend to use Arduino IDE 1.8.x which behave correctly.

@dev-board-tech
Copy link
Author

Yeah, seems to be the Arduino IDE 2.x.x at fault, Is the first time I seen this issue, is good to let it open, will be useful for those that will have the same issue to know that the issue is in Arduino IDE 2.x.x and not current repo.

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