0

Instead of using the regular Arduino board I have purchased the atmega328p-pu along with this components:

  1. 22pf ceramic capacitor
  2. 10K resistor
  3. 16mhz crystal
  4. 47uF capacitor
  5. 3.3 Volts Power supply

The diagram looks like this:

enter image description here

Because the atmega328p chip that I purchased already comes loaded with arduino bootloader I can program this chip right away! This video explains in more detail how to upload the code to the chip. It is very simple.

The reason why I run my atmega328p chip with a 3.3V power supply is because of these reasons:

  1. I have multiple sensors like the NRF24L01 that cannot take 5 volts.
  2. I run this project of a 3.3 battery as well in order to save power.
  3. I do not want to use voltage regulators as they are inefficient and they will waste my battery.
  4. Everything works great.

Even though everything works great if I am running atmega328P at 16mhz @ 3.3V I am not following the specifications. In order to do things correct I will like to run my code at 8mhz so that I am in within the specs

Question

What is the correct way of running this project at 8mhz? If I change the 16mhz crystal for a 8mhz it runs at 8mhz but everything is half the speed. I have to divide all time related functions by 2. Moreover, I cannot upload new code if it has a 8mhz crystal. In order to upload new code I have to place the 16mhz crystal upload the code and then change the crystal again.

Can I still use my 16mhz crystal and run at 8mhz so that I do not have to keep replacing the crystal? I want my millis function and other time dependent functions to have the correct time. I do not want to have to divide everything by 2.

Do I have to burn a different bootloader for this to work? Where can I find a tutorial that can explain me all this?

There are tutorials on how to use the internal 8mhz crystal from the atmega328 chip but still want to use an external crystal as it is much more accurate

Edit

I just found this link that explains how to do it. Edgar Bonet answer seems a lot simpler so I will stick to that.

1 Answer 1

2

If you run your MCU at 8 MHz, everything will run at this frequency: not only the CPU core but also the timers, including Timer 0 which is used for millis(), delay(), etc. So you will have to use a modified version of the Arduino timing functions in order to cope with this clock frequency.

Fortunately, such version already exists. Actually, it is even supported by the standard Arduino core, since it supports the 3.3 V version of the Arduino Pro Mini, which uses an ATmega328P clocked at 8 MHz.

I thus suggest you install an 8 MHz crystal, burn in the bootloader for the 3.3 V Pro Mini, and tell your IDE that you are using that board. In the Tools menu:

  • set board to "Arduino Pro or Pro Mini"
  • set processor to ""ATmega328P (3.3V, 8 MHz)"
2
  • How can I burn the bootloader for the 3.3V Pro mini? Is that a different bootloader than the one that it came with? The rest of the answer I understand perfectly fine. Thanks for the help Edgar.
    – Tono Nam
    Commented May 29, 2020 at 19:42
  • @TonoNam: you will need an ISP programmer, or an Arduino running the ArduinoISP sketch. The Tools menu of the Arduino IDE has a “Burn Bootloader” item. You can search the internet for instructions on how to use it. Commented May 29, 2020 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.