Code running extremly slow on Atmega328PB

Hello,

I have some code written in Arduino which is a PID loop for an external heater with temp and PWM displayed on an OLED. Code works perfectly on Arduino Nano and Uno so its not the code.

On my standalone QNF Atmega328PB-MU the code runs extremly slow.

The OLED updates one line at a time. I have ruled out I2C as the issue sincee PWM updates(on my scope) with the oled changing, which means the whole board is slow, not I2C connections.

My thoughs on what could be the issue:

Is this a clock issue? I dont think the clock is being set correctly? Or something entirley else?
I am using a USBASP which throws an SCK error. This apperently normal according to the internet. No matter if I select internal or external clock in minicore, the outcome stays the same. There is no external clock. It should not work with external clock selected (i think) but it does, so I think the clock is not set properly. ive also set the fuse bits for internal clock.

What could be the issue here? It works fine on an arduino.

Please help if you can, ill provide any additional info. Thanks!!

The fuses are only set when you do "burn bootloader" from within the IDE, or use avrdude manually to set the fuses.

You must do "burn bootloader" or manually set the fuses when using a new '328pb- the factory fuse settings will have it run at 1MHz, which is almost certainly much slower than you expect.

And yeah, the SCK message when using USBAsp is normal. IIRC, avrdude was designed for the official usbasb firmware, which is long-since obsolete and not installed most usbasp boards.

Thanks!

I got it working on the 8mhz internal clock but its still visibly slow on the oled and you can notice it in the PID loop compared to the external clock on the nano. Do you know if theres anyway to speed it up or make it loop faster without adding an external clock?

Did you remember to burn bootloader?

Post the code that is not running at the expected speed.

Fix the problem by adding a 16 MHz crystal and the two required capacitors, and burn the fuses to use it.

jremington:
Fix the problem by adding a 16 MHz crystal and the two required capacitors, and burn the fuses to use it.

I was going to suggest this also, or a 8Mhz cyrstal