Program runs half expected speed

Hi all, I am using Atmega328p-AU chips and program runs at half speed. (i.e. 1000ms blink takes 2 seconds to flicker).

I have set my fuses to run on the internal oscillator at 8MHz, and disabled the clock divider.

Here are my fuse settings:

board_fuses.hfuse = 0xDF    ;smallest flash section size 256 since not using a bootloader with ICE programmer
board_fuses.lfuse = 0xE2    ;int 8MHz crystal (16MHz not working with less than 3.78V PSU)
board_fuses.efuse = 0xFE    ;BOD at 1.8V, perfect for low power

It looks as though the MCU thinks its running on a 16MHz crystal... Otherwise how else would it be running at half speed?

I am uploading a blink sketch, that is all. Any idea what could be wrong?

The MCU has no idea.

The Arduino IDE needs to know the oscillator frequency. Select that under the Tools>Board menu.

I use platformIO. but I have burnt the fuses, isnt it what setting the oscillator frequency does in the arduino IDE?

How do you tell platformIO what the oscillator frequency is?

Do you expect it to read the fuses?

1 Like

You were right! That is something I didnt realize, when building a program, values like delay() are arbitrary until they are compiled is assembly code, which I guess require the compiler to know how many clock cycles are required to reach a given time value?

That is how you tell PIO what is the clock speed: board_build.f_cpu = 8000000L

It works now, thank you!

Exactly.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.