I have a project (based on ATMega1284p) that runs just fine with a 14.74 Mhz crystal on about 50 boards. I want to upgrade the crystal on new boards to 20.00 Mhz and, over time, replace the crystals on the old boards. I have tested the firmware on a board with a 20.00Mhz crystal (after changing F_CPU) and it works fine.
I would like to have one copy of the firmware for both boards so, at startup, the board needs to be able to detect if the crystal is running at 14.74 or 20.00 Mhz. I do not need to be able to detect the exact frequency, just the ability to differentiate between 14.74 and 20.00 Mhz. I want to be able to do this on the existing boards, i.e.: not modify the old boards by adding RTC, etc.
At first I thought I could use the conversion speed of the ADC but then realized that that is also based on a divided clock. Another thought was perhaps trying to run the ADC "Too" fast and maybe being able to detect conversion errors, etc. In use, all 8 ADC pins "normally" (but one or two might have 0) have 3 to 8 volts on them at startup but they are not normally changing in a manner that would allow me to measure slopes, etc.
Other chips on the board:
MCP2515 CAN Bus Controller (SPI bus)
TLC59116 LED Driver (I2C bus)
Something that would work "sometimes" would be to initialize assuming 14.74 Mhz and attempt to communicate (listen for valid traffic) on the bus but that won't work when the boards are stand-alone, or the first board that powers up on the bus.
I tried searching the forum for like conversations but found none. My apologies if I missed one ...