I have only programed a couple atmega328s and mostly fairly standard set up (nano like). I am looking at building out a weather station and one of the components I need is 3.3v. I know the atmega will run at 3.3, but I also know at 10 mhz. Does that mean I would wire it up like normal, but use a 10mhz crystal? Or do I use a 16mhz, but set a fuse or program setting to make it run at 10mhz?
srnet:
Why do you want to run the processor at 10Mhz ?
Standard Arduino IDE support is for 16Mhz and 8Mhz.
You can buy Arduino Pro Minis for 3.3V and 8Mhz operation.
The plan is to use an atmega328 chip and at 3.3v I have read the max is 10 mhz, which should be plenty. 8 is probably plenty. Just curious how I do anything but 16mhz crystal.
Bob
No, you can use 16 MHz crystal at 3.3V . You can use 8 or 10MHz crystal or do not connect crystal at all but fuse atmega to use an internal 8Mhz oscillator.
16MHz at 3.3v is outside the manufacturers specification. It may work or it may not.
As you are building a weather station, I assume that the 328 will be exposed to the elements, rather than in a controlled environment. All the more reason to stick with the manufacturers specs.
markd833:
16MHz at 3.3v is outside the manufacturers specification. It may work or it may not.
As you are building a weather station, I assume that the 328 will be exposed to the elements, rather than in a controlled environment. All the more reason to stick with the manufacturers specs.
Right, so do I use a 10mhz crystal or use a 16, but tell the chip to run at 10mhz? I guess the question was more of a how do I get the atmega to run at 10 or less. As pointed out, I could use the internal 8mhz, but I also want to know options as I may have different needs in the future.
Bob
Stick to 8MHz for battery operation. Its fine to use the internal oscillator unless you know you need very high timing accuracy over very short periods for some reason. Can't think why a weather station would need that.
If you need very accurate timing over long periods, you can use a 32KHz watch crystal. That's not a beginner project, however. Another alternative is to use an rtc module.
In almost all the arduino projects I have done, 8MHz has been more than fast enough. In a tiny number of projects 16MHz was not fast enough. I've never had a project where 8MHz was too slow but 16MHz was fast enough.
At 3.3v, I think the maximum clock speed you can use is 13.333MHz (if my calculations are correct!).
However, I recently put out a question to the Microcontrollers section of the forum about a development board I had that ran at 3.3V using a 16MHz crystal/resonator. There is a hint in the 328p datasheet that suggests that the chip can be clocked at a higher frequency and then the system clock divided down.
The datasheet (Microchip 2018 - DS40002061A) is talking about an 8MHz clock but here is what it says: Section 9.6 - Calibrated Internal RC Oscillator - table 9-11 note 2 says "If 8MHz frequency exceeds the specification of the device (depends on VCC), the CKDIV8 Fuse can be programmed in order to divide the internal frequency by 8."
The indications are that you can divide down the clock to generate a frequency that is within spec for the voltage you are running the chip at. What it doesn't say is whether this is only true if you use the CKDIV8 fuse or whether you can use the system clock prescaler instead which allows you to divide the clock by 1,2,4,8,16,32,64,128 or 256.
You also need to know that if you change the crystal to a value other than 8MHz or 16MHz, then you will most likely need to build a bootloader specifically for that frequency. Also, changing the clock affects the clock used by the UART for serial communications. If the system thinks it has a 16MHz clock and you use an 8MHz clock, then your baud rates will be wrong. Setting 9600 baud will actually result in a 4800 baud data stream (because the clock is running at half the expected speed).
Thanks all, I think 8mhz would probably be fine. Do I have to tell the code it is running at 8mhz or just use the fuse settings to run it from the internal or both?
Burn an 8MHz (internal) bootloader. That sets the flags and everything. I use the MiniCore, an Uno and the Arduino as ISP example to bootload my 8MHz projects. Follow the instructions on the linked page to install the core.
groundFungus:
Burn an 8MHz (internal) bootloader. That sets the flags and everything. I use the MiniCore, an Uno and the Arduino as ISP example to bootload my 8MHz projects. Follow the instructions on the linked page to install the core.
You must burn bootloader for 8 MHz and have 8 MHz selected when you compile + upload.
It is worth noting that on classic AVR devices (that would be an 8-bit AVR released prior to 2016, when Microchip introduced a new and radically improved AVR architecture), the Arduino core screws up timekeeping pretty badly when 64 is not evenly divisible by the clock speed in microseconds.
Pretty sure the official post-2016 AVR (arduino calls this architecture "megaavr" - a term which I dislike, because Microchip uses "megaavr" and "tinyavr" to refer to specific product lines (and the Dx-series is a third one) - but all three of those product lines contain parts with the new architecture, while "megaAVR" in official parlance refers to all parts released by Atmel/Microchip with "ATmega" in the name) core also screws up under those circumstances, but that's been fixed in third party cores. It has generally not been fixed in classic AVR cores (ATTinyCore does it more correctly than most, though)
DrAzzy:
You must burn bootloader for 8 MHz and have 8 MHz selected when you compile + upload.
It is worth noting that on classic AVR devices (that would be an 8-bit AVR released prior to 2016, when Microchip introduced a new and radically improved AVR architecture), the Arduino core screws up timekeeping pretty badly when 64 is not evenly divisible by the clock speed in microseconds.
Pretty sure the official post-2016 AVR (arduino calls this architecture "megaavr" - a term which I dislike, because Microchip uses "megaavr" and "tinyavr" to refer to specific product lines (and the Dx-series is a third one) - but all three of those product lines contain parts with the new architecture, while "megaAVR" in official parlance refers to all parts released by Atmel/Microchip with "ATmega" in the name) core also screws up under those circumstances, but that's been fixed in third party cores. It has generally not been fixed in classic AVR cores (ATTinyCore does it more correctly than most, though)
Good to know. But I think 8mhz should be more than enough for me. And since it is built in, easier.
Bob