How to confirm which clock source the AVR is using?

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Freaks,

I programmed my M48 with an external crystal setting in AVRStudio and I am using an 8MHz crystal on my breadboard. What is a good and easy way to verify if it is using the external 8MHz crystal and not the internal RC oscillator? Will measuring clkout be a good idea? I don't have a O-scope so is there any other way to confirm what clock source the M48 is using? Also as my "test" circuit I am driving a simple LED from portB.

Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

Quote:
easy way to verify if it is using the external 8MHz crystal and not the internal RC oscillator?

Create a simple program (blinking led).
Then put a capacitor (0.1 uF) parallel to crystal.
If led keeps blinking, internal osc. is in use.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
8MHz crystal on my breadboard

As Visovian said, a simle timer flashing the LED at a known rate, e.g. once per second, is a good start. This would easily distinguish between an 8 MHz external Xtal and the Internal RC Osc at say, 1 MHz.

Since the Xtal is on a breadboard you can also just remove it. No external Xtal, no clock, no flashing LED. If the LED still flashes, then the Int RC Osc is in use.

Turn the power off before you remove or insert the Xtal.

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, Jay and Viso.

Does it have to be a blinking LED?
What if I have an LED that is on and then I pull the crystal?

Since my program is in a eternal for loop, the execution from flash memory would still depend on the clock right?

So if I see the LED on even after the crystal is removed, that means it is using the internal RC, if not then it is using external crystal for the oscillator.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

What if I have an LED that is on and then I pull the crystal?

Why do you think there'd be a noticeable difference in the LED state in that case? The fact that it was flashing shows that it was being turned on and off by the running processor. It's hardly difficult to make an LED flash:

#define F_CPU 8000000UL;
#include 
#include 

int main(void) {
 DDRB = 0xFF;
 while(1) {
  _delay_ms(500);
  PORTB ^= 0xFF;
 }
}

(put LED on any PORTB pin or change the 'B's in the above)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok thanks, guys. I was able to confirm that it is using the crystal. Also made sure External crystal was selected in my AVRStudio options.