Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Hardware
  3. Running ATmega328P on internal 8MHz clock

Running ATmega328P on internal 8MHz clock

Scheduled Pinned Locked Moved Hardware
14 Posts 8 Posters 24.4k Views 6 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • BartEB Offline
    BartEB Offline
    BartE
    Contest Winner
    wrote on last edited by BartE
    #1

    Playing around a little bit with GertSanders 50 by 30 mm PCB i was wondering if this board also could run without the external clock (8MHz crystal). Saving not only a couple of components but even better save battery lifetime. It appears the ATmega328 uses less power when running on the internal clock.

    It turned out to be a bigger puzzle than expected i was not able to find a straight answer nor a ready-mate solution. Fortunately i did found a couple partial solution and will try describe the way it worked out for my setup.

    It all starts with a bare ATmega328P chip, they are sold in basically 2 flavors. One with-out a bootloader (see Wikipedia) (or with a non Arduino) they are programmed to run on the 1 MHz internal clock. The second flavor is shipped with a pre-programmed Arduino R3 bootloader these will expect a 16 MHz external clock, (but an 8 MHz crystal will do).

    The clock settings are made by so-called fuses, a better name would be internal dip-switches since a fuse sounds like one-time only programming , while the ATmega's fuses can be re-programmed over and over again. So for both flavors we need change theses fuses and for the first flavor we also need to program a bootloader.

    On the Arduino website we can read how to program a bootloader by connecting it to an Arduio UNO (see here) BUT in this case the programming it selves did not worked out. So wiring is OK the program sequence not:

    • For the empty 328p's this wiring will do (so no Crystal) https://www.arduino.cc/en/uploads/Tutorial/SimpleBreadboardAVR.png

    • For the one with an bootloader one needs to wire the 328P like this: https://www.arduino.cc/en/uploads/Tutorial/BreadboardAVR.png

    A better way to program the Arduino is using the sketch from Bill Westfield which can be found here: https://github.com/WestfW/OptiLoader So download this sketch into the Arduino UNO and when wired liked described above the new Atmega is programmed with a fresh bootloader.

    The last step is the set the correct fuses so the interval 8 MHz clock is used. This turned-out to be not so easy to figure out . There are 3 fuse bytes which need to be set. The "Low", "High" and "Extented" , in the end i did run this page: http://www.engbedded.com/fusecalc/. Where you can selected the appropriate configuration and the site will "calculate" the correct byte's (and vice versa).

    The setting which does work for me are:

    • Low := 0xE2
    • High := 0xDE
    • Ext. := 0xFD

    To set these fuse bytes in the Atmega one needs to change Bill's OptiLoader script around line 730 you can find
    this peace of code:

    const image_t PROGMEM image_328p = {
      {
        "optiboot_atmega328.hex"    }
      ,
      {
        "atmega328P"    }
      ,
      0x950F,				/* Signature bytes for 328P */
      {
         0x3F,0xFF,0xDE,0x05,0   }
      ,
      {
        0x2F,0,0,0,0     }
    

    Once change to this the correct fuse byte's are used

    const image_t PROGMEM image_328p = {
      {
        "optiboot_atmega328.hex"    }
      ,
      {
        "atmega328P"    }
      ,
      0x950F,				/* Signature bytes for 328P */
      {
        // 16 MHz external crystal
    //    0x3F,0xFF,0xDE,0x05,0   
        // 8 MHz internal crystal
          0x3F,0xE2,0xDE,0xFD,0  
    }
      ,
      {
        0x2F,0,0,0,0   
      }
    

    So in short:

    • Connect your new Atmega to an Arduino UNO
    • Download Bill Westfield skecth WITH fuse modifaction into the UNO
    • Give a reset and look at your terminal if the bootloader and fuse where set correctly

    Once the correct bootloader is in. You can place the ATmega328 in GertSanders PCB and program a sketch in in with these type of FTDI USB serial convertors: http://www.ebay.com/itm/320907184616?rmvSB=true.
    Set the Ardiuno IDE to:

    • Tools -> Board -> Arduino Pro or Pro Mini
    • Tools -> Processor -> ATmega328 (3.3V 8 MHz)
    • Tools -> Board -> ArduinoISP

    And have fun with it...

    1 Reply Last reply
    7
    • siodS Offline
      siodS Offline
      siod
      wrote on last edited by
      #2

      Hi BartE,

      I´ve read the internal clock at 8 MHz is not as good as an external 8MHz clock because the accuracy of the internal oscillator seems to be only 10% (Atmel Datasheet page 323). What are your experiences? Would you recommend using internal or external OScillator?

      Also I am wondering why most people are running their custom PCB´s using 8MHz clocks instead of 16MHz. Is it only because of reducing the energy consumption? I think so.

      I originally planned to use 16MHz clocks, but now, from the energy consumption point of view, I will probably switch to the 8MHz variant...

      still learning...

      E 1 Reply Last reply
      0
      • tbowmoT Offline
        tbowmoT Offline
        tbowmo
        Admin
        wrote on last edited by
        #3

        @siod

        Yes, the lower your frequency is, the lower the power consumption is while running the program, but also the longer it takes to execute the program. So there is some trade offs on it.

        Although the RC oscillator isn't that accurate, it doesn't matter that much. Not many node types are that dependent on highly accurate timings, so it's not necessary to use an xtal oscillator, and thus you can save some $ on components.

        1 Reply Last reply
        0
        • BartEB Offline
          BartEB Offline
          BartE
          Contest Winner
          wrote on last edited by
          #4

          @siod Using a 16 MHz clock requires a 5 volt source. So running on 2 AA(A) batteries and thus 3 volt also limits the clock frequency to 8 MHz

          1 Reply Last reply
          0
          • siodS Offline
            siodS Offline
            siod
            wrote on last edited by
            #5

            @BartE
            Oh, didn´t know that 3 V automatically limits to 16MHz but good to know. I´ve already ordered a bunch of 16MHz Oscillators which I could still install and just run in 8MHz by powering with 2 AA batteries. Also I would stay flexible If I´d need 16MHz; Just use 5V!

            @tbowmo
            thanks for your explanation! After I used up my 16MHz Oscillators I will test a setup using the internal clock.

            still learning...

            1 Reply Last reply
            0
            • G Offline
              G Offline
              gloob
              wrote on last edited by gloob
              #6

              If you use an 16MHz oscillator and power the board with 3V, the board will run unstable as the ATMega does not support 16Mhz with 3V.
              If you just change the power, will not change the oscillator frequenzy. You have to Switch to the internal clock signal when powering the board with 3V and you have a 16MHz clock installed.

              1 Reply Last reply
              0
              • tbowmoT Offline
                tbowmoT Offline
                tbowmo
                Admin
                wrote on last edited by
                #7

                @gloob

                I think that there is a typo in your comment? I think you mean that "If you use an 16Mhz oscillator and power the board with 3V..."

                That would make the most sense in my world :)

                G 1 Reply Last reply
                0
                • tbowmoT tbowmo

                  @gloob

                  I think that there is a typo in your comment? I think you mean that "If you use an 16Mhz oscillator and power the board with 3V..."

                  That would make the most sense in my world :)

                  G Offline
                  G Offline
                  gloob
                  wrote on last edited by
                  #8

                  @tbowmo
                  You are right. I did modify my post.

                  1 Reply Last reply
                  0
                  • siodS Offline
                    siodS Offline
                    siod
                    wrote on last edited by
                    #9

                    Ah Ok, so I misunderstood BartE´s post.

                    So what should I do now with my bunch of 16MHz Osc´s? Maybe useful for some other project in the future...

                    still learning...

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      HarryDutch
                      wrote on last edited by
                      #10

                      Have a look here:
                      http://www.gammon.com.au/breadboard

                      This is the easyiest way to bootload you Atmega328p with 8Mhz. Works like a charm.

                      dakkyD 1 Reply Last reply
                      1
                      • H HarryDutch

                        Have a look here:
                        http://www.gammon.com.au/breadboard

                        This is the easyiest way to bootload you Atmega328p with 8Mhz. Works like a charm.

                        dakkyD Offline
                        dakkyD Offline
                        dakky
                        wrote on last edited by
                        #11

                        @HarryDutch Hu awesome link. Thanks!

                        Controller: Raspberry Pi 2 :: Openhab2 :: with @TimO MySensors Binding
                        Gateway: Arduino MEGA 2560 R3 :: W5100 :: Ethernet GW

                        Software: MySensors 2.0development

                        1 Reply Last reply
                        0
                        • E Offline
                          E Offline
                          eeichinger
                          wrote on last edited by
                          #12

                          a bit late but a word of warning for anyone embarking on this idea: the internal 8MHz clock is very inaccurate (%10 according to the datasheet), which likely will break asynchronous protocols like UART. As long as you are using only synchronous protocols like I2C you should be fine. More details can be found in this excellent thread on stackexchange https://electronics.stackexchange.com/a/32433/216828

                          1 Reply Last reply
                          0
                          • siodS siod

                            Hi BartE,

                            I´ve read the internal clock at 8 MHz is not as good as an external 8MHz clock because the accuracy of the internal oscillator seems to be only 10% (Atmel Datasheet page 323). What are your experiences? Would you recommend using internal or external OScillator?

                            Also I am wondering why most people are running their custom PCB´s using 8MHz clocks instead of 16MHz. Is it only because of reducing the energy consumption? I think so.

                            I originally planned to use 16MHz clocks, but now, from the energy consumption point of view, I will probably switch to the 8MHz variant...

                            E Offline
                            E Offline
                            eeichinger
                            wrote on last edited by
                            #13

                            @siod yes, mostly because of power consumption. You can run an ATmega328P on a 3V battery, but then you need to use 8MHz instead of 16MHz according to the datasheet.
                            As I replied separately, you don't want to use an inaccurate clock for async protocols like UART that require precise timing.

                            bjacobseB 1 Reply Last reply
                            0
                            • E eeichinger

                              @siod yes, mostly because of power consumption. You can run an ATmega328P on a 3V battery, but then you need to use 8MHz instead of 16MHz according to the datasheet.
                              As I replied separately, you don't want to use an inaccurate clock for async protocols like UART that require precise timing.

                              bjacobseB Offline
                              bjacobseB Offline
                              bjacobse
                              wrote on last edited by
                              #14

                              @eeichinger
                              Yes an old thread, but still useful.
                              well if you plan to run on a low voltage, you must disable BOD, else per default the 328 will switch off at 2,7V. And then you need to run 1 at MHz

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              10

                              Online

                              11.7k

                              Users

                              11.2k

                              Topics

                              113.0k

                              Posts


                              Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • MySensors
                              • OpenHardware.io
                              • Categories
                              • Recent
                              • Tags
                              • Popular