Arduiono system clock

Hi, i have Arduiono UNO 3 chip and any idea how to display system clock on the serial port to check does the Default clock Source working properly as 8MHz or not ??

the Mcu is ATMEGA328P-PU

Best Regards

Garbage characters coming out the serial port will result if the clock rate is incorrect, as that leads to the wrong transmit baud rate. Isn’t the the clock rate normally 16 MHz?

5v UNOs run at 16 MHz. If you want to measure the system clock, you will need to compare it to some other “known” clock. An UNO has 2 other, relatively inaccurate clocks, an 8 MHz and a 128 kHz clock. You could use a lower frequency clock to start and stop a counter whose input is the clock to be measured. Then report the number of high frequency clocks per low frequency clock. But the result will have limited accuracy.

What i want is

1- Displaying on the serial port or any other way what’s the current frequency of the ATmega328 chip, does it the same as external clock (crystal 16MHz) or it’s prescaled down, like 8MHz,4MHz…etc . in other words what’s the System Clock Prescaler setting ???

2- How can i scale the frequency down the ATmega328 to be (1MHz) instead of be same as the external clock source (16MHz).

3- If and only if i scaled down the ATmega328 frequency to be (1MHz), then if want make the ADC clock 62.5KHz i must prescale 1MHz /16 to be 62.5KHz ??

Best Regards

Samer

in the ATmel reference book they mention (Default Clock Source

The device is shipped with internal RC oscillator at 8.0MHz and with the fuse CKDIV8 programmed,

resulting in 1.0MHz system clock. The startup time is set to maximum and time-out

period enabled. (CKSEL = “0010”, SUT = “10”, CKDIV8 = “0”). The default setting ensures that

all users can make their desired clock source setting using any available programming interface.)

and that’s mean i can scale the input clock to be as i need in the system, and in this case the clock source was the internal 8MHz , but in our case it’s the crystal 16MHz, so i can scale it down to me 1MHz because i dont need more that 1MHz speed in the project .

IF i want make the ADC clock to be 62.5KHz, then i must follow below steps

1- Make internal system clock be 1MHz by prescaling the clock source /16 -->(16MHz/16 = 1MHz)

2- Make the ADC clock 62.5KHz by prescaling internal system clock /16 → (1MHz/16 =62.5KHz)

please correct me if I’m wrong .

You can chose any clock source and speed you want for the ATmega328P while you are programming the chip (I use AVR Studio and AVR ISP MKII programmer for that). However, the serial port will work correctly ONLY if the baud rate, UART registers and system clock are all chosen consistently. The Arduino environment expects the system clock rate to be 16 MHz, otherwise programming through the UART, using the default boot loader won’t work.

While a program is running, the ATmega328 allows you to change the clock prescaler to reduce or increase the effective clock speed. To do this, the program writes to the CLKPR register (see the data sheet for details–it is a multistep process!). So the scheme you outlined in your most recent post will work, but if you expect the serial port to continue to work correctly, you will have to also change the UART registers accordingly.