MCUdude / MightyCore

Arduino hardware package for ATmega1284, ATmega644, ATmega324, ATmega324PB, ATmega164, ATmega32, ATmega16 and ATmega8535
Other
637 stars 181 forks source link

ATmega32 millis is not right using the 8 MHz internal oscillator? #281

Closed hilmiyafia closed 10 months ago

hilmiyafia commented 10 months ago

I made a program using millis as a delay so it's not blocking. It works correctly at internal 1 MHz, but when I set the clock to internal 8 MHz, the delay become 8 times longer. I compiled this program as hex and put it in using a programmer:

uint32_t timer = 0;
uint8_t state = 0;

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

void loop() {
  if (millis() - timer > 1000) {
    timer = millis();
    state ^= 1;
    digitalWrite(0, state);
  }
}
MCUdude commented 10 months ago

PLease read the docs:

MightyCore supports a variety of different clock frequencies. Select the microcontroller in the boards menu, then select the clock frequency. You'll have to hit "Burn bootloader" in order to set the correct fuses and upload the correct bootloader. Make sure you connect an ISP programmer, and select the correct one in the "Programmers" menu. For time critical operations an external crystal/oscillator is recommended.

You need to click "Burn Bootloader" in order to set the fuses, even if you're not using a bootloader at all

hilmiyafia commented 10 months ago

@MCUdude Thank you, it works now 😊