3

Has anyone experience configuring the Atmega328P to work with an 8Mhz external clock?

I want to reduce the power consumption of the device. If I just connect an 8MHz external quartz oscillator then simple programs like LED blink still work (With the time delays doubled), but if I try to use communication like UART, then I am unable to. So no programming new sketches.

8
  • Looks like you are not using the correct "board". F_CPU has to be defined as your clock frequency. You can check LilyPad as an example. Commented Nov 13, 2016 at 13:31
  • Hi could you elaborate a little more on that for me ? I'm using a UNO as an ISP to an Atmega328P.
    – hoboBob
    Commented Nov 13, 2016 at 13:33
  • What "board" are you selecting in the Arduino IDE? Have you checked that the definition of the board has the correct clock frequency? My guess is "no". Commented Nov 13, 2016 at 13:35
  • How do you connect to serial communication? You write communication like UART but no circuit description! Commented Nov 13, 2016 at 13:37
  • 2
    I'd try making the arduino sleep, and turning off unused devices. That will reduce the power more that running at half speed.
    – Gerben
    Commented Nov 13, 2016 at 15:25

3 Answers 3

3

If you reduce the main clock speed by 50% then everything else is reduced by 50% as well.

The whole chip runs at half the speed. That includes things like the UART.

For example, the bootloader is set to run at 115200 baud on a 16MHz chip. If you run that same chip, with the same bootloader, at 8MHz then the bootloader will actually be running at half the baud rate, so 115200 / 2 = 57600 baud.

Unless you tell the IDE that your board is now running at 8MHz (by creating or using the correct board configuration information to set F_CPU to 8000000) then time runs at half the speed in your sketches too. So a delay of one second will last two seconds. Every two milliseconds a single millisecond will pass. And again baud rates will be wrong. If you use:

Serial.begin(9600);

you will actually be running at half that speed (4800 baud) and so you would have to set your serial terminal program to that speed instead of the one you requested.

To to do things properly you will have to:

  1. Replace the crystal
  2. Edit, compile, and install a new version of the bootloader that runs at 8MHz
  3. Create (or edit) a suitable board definition (in boards.txt) to compile sketches that expect to run at 8MHz.
6
  • Hi thanks for the reply, I have replaced the oscillator, and tried to edit the uno.build.f_cpu=16000000L to uno.build.f_cpu=8000000L. But if I do this then when I try to bootload the modified file I get 'avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xff'
    – hoboBob
    Commented Nov 13, 2016 at 13:59
  • Paragraph 3 of my answer.
    – Majenko
    Commented Nov 13, 2016 at 14:01
  • Well I tried it I halved the baud rate to 9600, on the example ISP sketch. Then edited the board.txt file. Changed the oscillator. The bootload worked. but when I try to upload a sketch I get ''avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00'. Makes me think I need to change the Baud rate of the Arduino IDE but I have no idea how to do that. Does anyone??
    – hoboBob
    Commented Nov 13, 2016 at 14:20
  • uno.upload.speed=115200 in boards.txt
    – Majenko
    Commented Nov 13, 2016 at 14:26
  • No, if I change this then the boot load fails
    – hoboBob
    Commented Nov 13, 2016 at 14:44
3

The easiest way is to use the settings:

Tools > Board > Arduino Pro or Pro Mini

Tools > Processor > ATmega328 (3.3V, 8MHz)

The problem with that is the Pro Mini bootloader is 2kB and has a bug that causes an endless reset loop if you do a watchdog reset.

The better option is to use https://github.com/MCUdude/MiniCore, which includes the Optiboot bootloader, saving 1.5kB of flash memory vs using the Pro Mini bootloader and doesn't have the watchdog bug.

After selecting the correct configuration for your hardware from the Tools menu, do Tools > Burn Bootloader, which will set the fuses on your ATmega328P and upload the correct bootloader.

2
  • That is exactly what I was working on last night after someone suggested just using a Pro Mini. It worked well with no problems. I still never figured out why is never worked by changing the CPU and Baud settings in the Boards.txt file.
    – hoboBob
    Commented Nov 14, 2016 at 8:42
  • Same two menu selections work for other boards too, in conjunction with model selection as a third configuration essential if it is available and not already defaulted to the desired choice. Commented Jan 22, 2017 at 7:53
2

Firstly, you can buy 8MHz Atmega328P Pro-Minis from China. They are cheap and run at 3.3V. Look at eBay.

If you want to reduce the power consumption of Arduino boards, you have three primary attack vectors:

  • Removing the power LED
  • Removing the voltage regulator
  • A Low-Power library

All of these have different impacts on the power consumption of your respective board.

An extensive comparison can be found here in this blog-post.

2
  • That is an answer, but the china man won't deliver on Sundays, I could also use the internal 8MHz Oscillator but it also has 10% accuracy to calibrate it I need a 28KHz Oscillator, China man dos't deliver those on sundays either
    – hoboBob
    Commented Nov 13, 2016 at 14:56
  • hmmmm Pro mini perhaps that may work .... Thanks :)
    – hoboBob
    Commented Nov 13, 2016 at 14:58

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.