3
\$\begingroup\$

I am designing a circuit for arduino. I will be using Atmega328p, and will connect few male header for pin access and 6 male headers for programming (MOSI,MISO,SCK,RST,Vcc,GND). So is it compulsory to use ext oscillator. I know MCU can also work using int oscillator but not sure that while programming it through USBasp it will work or not. I heard somewhere that while programming it using USBasp ext osciallator is required. So ext oscillator is required or not.?

\$\endgroup\$
1
  • \$\begingroup\$ what problem you are getting in connecting ext oscillator to your circuit? \$\endgroup\$
    – Aircraft
    Oct 7, 2015 at 6:01

2 Answers 2

2
\$\begingroup\$

The default clock source for the atmega328p is the internal RC oscillator @ 8MHz with the CKDIV8 fuse programmed. See page 28 here.

You can absolutely program the part using the internal RC oscillator. After all the part ships with this default configuration. Assuming that you want to program the part using the arduino IDE and have everything behave as expected you will need to change some settings in you arduino boards.txt file so that the internal clock source is selected (as you know the arduino boards that use the atmega328 ship with an external oscillator and the boards.txt file by default instructs the part to use the external oscillator) and then burn the boot loader. In boards.txt you'll have to modify the fuses to select the proper clock source. One easy solution is to modify the uno board settings since that board uses the same chip. Copy/paste all the uno settings so that you have a new board (call it yourUno or something) entry in the file. The Uno board has the following settings:

uno.bootloader.low_fuses=0xff
uno.bootloader.high_fuses=0xde
uno.build.f_cpu=16000000L

You'll want to modify that to:

yourUno.bootloader.low_fuses=0xe2
yourUno.bootloader.high_fuses=0xda
yourUno.build.f_cpu=8000000L

This should select the internal 8MHz RC as your clock source. Note that per the comments below there are other ways of doing this if you're OK with a 1 MHz clock.

\$\endgroup\$
19
  • \$\begingroup\$ Note that the fuse settings are only used when Burn Bootloader is selected in the Arduino IDE. If you intend to never use this option then there is no need to change that part of the configuration. Also note that the default bootloader for the Uno assumes a 16MHz clock; you will need to modify and rebuild it if you want it to operate at 8MHz. \$\endgroup\$ Oct 7, 2015 at 6:14
  • \$\begingroup\$ @IgnacioVazquez-Abrams yeah good point, but I'm assuming he's going to program the part using the arduino IDE/library. If he doesn't burn the bootloader then things like delay() won't behave as expected. \$\endgroup\$
    – Doov
    Oct 7, 2015 at 6:17
  • \$\begingroup\$ yes I need to upload the bootloader first. So you mean to say while uploading bootloader, I need to change uno.build.f_cpu=16000000L to Uno.build.f_cpu=8000000L and then I can design my circuit without oscilator. and during programming i'll choose the internal oscillator. Am I right.? \$\endgroup\$ Oct 7, 2015 at 6:19
  • 1
    \$\begingroup\$ The bootloader is not at all required in order to use Arduino libraries on the chip. \$\endgroup\$ Oct 7, 2015 at 6:19
  • 1
    \$\begingroup\$ @user46573544 yes -- you can directly program the part from the arduino IDE. It will not work as expected though! The IDE assumes you're operating your part at 16 MHz -- you aren't!! The default clock is 1 MHz so you need to modify something so that everything works as expected. The solution I provided will utilize an 8 MHz internal clock. If you are OK with 1 MHz then you can use Ignacio's solution. \$\endgroup\$
    – Doov
    Oct 7, 2015 at 6:39
2
\$\begingroup\$

An external oscillator is only required during programming if the fuses are programmed to require one during normal operation. There is no requirement for it to be a crystal though; it is possible to inject a clock at least 3 times faster than the programming clock via XTAL1 if one is required. See the "Memory Programming" section, "Serial Downloading" subsection of the ATmega328P datasheet for details.

\$\endgroup\$

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.