Missunderstanding regarding the external crystal


I am working to built my own PCB for a heated enclosure using as MCU the ATMEGA328P-PU. The chip software was written using Arduino IDE, and tested using an Arduino Uno (the same board will be used to program the brand new ATMEGA that will be soldered on the board). Now, today I recieved the parts needed for the board, and I noticed that the supplier made an error and the 2 crystals ordered are rated at 14.3 MHz instead of 16 MHz. Now, my question is the following: if I wrote the code in the Arduino IDE , which is rated on 16 MHz, and burn it to a chip that will be soldered on a board which has a 14.3 MHz crystal, will the code work on the new board? Except the update of the delay() and millis() functions accordingly, I need to do any other changes in the code? As a note, the application is not time sensitive, thus I have no problem at all if the heated element temperature is read 1.5 seconds later than expected. The return of the crystals to the supplier is not a solution due to the logistics (5 working days at minimum between the pick-up of the actual crystals and the recieve of the correct ones, and for 2 pieces is not worth the time).

Sure, you have to use a programmer to upload as the bootloader will not work.

if you have 20MHz crystal you can soldering this, and change a firmware for this chip.
btw by changing a proper Fuse you can use internal oscillator, this mean without external crystal.

As missdrew said.

The reason for the incompatibility is the oscillator frequency is used by the bootloader code to program the remaining memory. If the frequency is not what the bootloader expects an error will result.

A bootloader program allows you to load the program code via a serial link. Without a bootloader you would need to program the device using a programmer see this link for at least one method to accomplish this. Youtube Programming link

If you have a special bootloader that would work with your 14.3 MHz crystal you would have to program it as in the youtube video so unless you envision having to program it multiple times I wouldn't even look to see if the bootloader can be modified.

Now, what I have planned is to use an UNO R3 and an Nano in order to program the new chip,; the blank Atmega chip will be inserted in the slot of the UNO R3, and the Nano will be used as programmer. After the programming completes, I will solder the previous programmed Atmega on its dedicated board, and from there on his only job will be to keep an tenperature constant and to display some data on an LCD. The final board will not have any Serial comunication at all. But will have those bloddy 14 MHz crystals.

That'll be OK then - assuming the xtals have suitable load capacitance ratings...

In the spec they say that the Crystal is rated at 18 pF. As per the typical schematic I will use 2 22pF capacitors from the Crystal to the GND.

Yup, that's fine. 22/2 = 11pF, plus the few pF stray capacitance of the chip
inputs/pins is close enough to 18pF.

Did you think of designing your PCB to take a Nano to plug into headers.
Most of the work is done for you.
This is a prototype project, even the end product was using the same method.
It allows in field upgrades, or controller swaps.

Tom... :smiley: :+1: :coffee: :australia:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.