0

I am currently working on a pcb that uses smd atmega 328p (au). I will be powering it through a lipo battery and a ldo regulator for 3.3v input. I am using the multiwii flight controller code. I know that atmega runs at 8mhz at 3.3v and 16mhz at 5v without overclocking the chip. The question is that should I use the internal 8mhz oscillator or external 8mhz? I will definitely make the chip more accurate as given in some forums but still does this effects anything or not?

2
  • How much accuracy do you need for your project and is the internal oscillator accurate enough for this goal? – StarCat Mar 26 at 13:51
  • I'm guessing you have an unstated concern. I doubt it's power usage, since you're talking about a flight controller. If you say what it is you'll probably get more useful answers. – timemage Mar 26 at 14:07
0

If the 8 MHz oscillator is off by a handful of percentage points, it will affect timing measurements you make using millis() and micros(). It could affect the baud-rates of Serial or SoftwareSerial. If these are not of any concern, the only remaining difference would be how fast your code can be executed. It's unlikely that the code pushes the chip runs so close to its maximum capability that it would matter, even at ~8 MHz.

Update:

... I just want to know if clock frequency effects the code and if I need to change code a bit like for example blink sketch runs at different time intervals on 8mhz and 16mhz(I tested it).

If you do nothing else, then yes, millis() will appear to run at half speed. You need to add a board definition to the IDE for an Arduino Uno running at 8 MHz. Then millis() and micros will be adjusted for the slower processor clock. How you do this depends on whether you choose the internal and less accurate 8 Mhz oscillator, or an external 16 MHz crystal.

For the internal oscillator, there is a board-definition on Github with instructions to load it into your IDE.

For an external oscillator, this article describes how to select the board type as "Arduino Pro or Pro Mini" and then be able to select the board frequency, using the Tools menu twice.

2
  • I don't know how much accuracy I need for this purpose but I know that the project will use i2c protocol for mpu6050 accelerometer and communication through nrf24l01 . I m a noob at coding but I just want to know if clock frequency effects the code and if I need to change code a bit like for example blink sketch runs at different time intervals on 8mhz and 16mhz(I tested it). – Anmol Kumar Mar 27 at 6:47
  • Thanks Robert for the answer . I will look forward for both internal and external oscillator 😀 – Anmol Kumar Mar 28 at 5:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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