Author Topic: Why use an external oscillator in a uC?  (Read 5830 times)

0 Members and 1 Guest are viewing this topic.

Offline mstachoTopic starter

  • Supreme Robot
  • *****
  • Posts: 376
  • Helpful? 10
Why use an external oscillator in a uC?
« on: February 21, 2012, 08:43:50 AM »
Let's say I have a uC with an internal clock running at 8MHz.  I'm aware that external crystals can have higher frequencies than internal clocks, so that's one obvious reason to use them.  But I've heard strange things about not being able to use PWM with external oscillators because you can't ensure that the frequency is exactly as specified, or something?  This could be entirely wrong, so I guess I'm just looking for clarification: is the only difference between using an external oscillator and the internal clock the frequency?

MIKE
Current project: tactile sensing systems for multifingered robot hands

Offline newInRobotics

  • Supreme Robot
  • *****
  • Posts: 1,015
  • Helpful? 48
  • N.I.R.
Re: Why use an external oscillator in a uC?
« Reply #1 on: February 21, 2012, 09:23:15 AM »
You can buy very precise external oscillators if high precision is required. Internal oscillators are good for general use, however when it comes to rocket science - You need to have an oscillator that can stay stable (keep same frequency) while operated in different temperatures; internal oscillators tend to change frequency when temperature changes.

Another reason for external oscillator is different frequencies (not necessarily higher), say You want to get specific baud rate with 0 error (which is not available with internal oscillator).

Regarding PWM, I've never heard that external oscillators cannot be used as a clock for that. When You think of it, recently, uCs did not have internal oscillators at all, but there was PWM. Don't know, probably depends on uC and oscillator itself.
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian W

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Why use an external oscillator in a uC?
« Reply #2 on: February 23, 2012, 06:39:25 PM »
Hi,

Let's say I have a uC with an internal clock running at 8MHz.  I'm aware that external crystals can have higher frequencies than internal clocks, so that's one obvious reason to use them.  But I've heard strange things about not being able to use PWM with external oscillators because you can't ensure that the frequency is exactly as specified, or something?  This could be entirely wrong, so I guess I'm just looking for clarification: is the only difference between using an external oscillator and the internal clock the frequency?
The main reason for using an internal oscillator is lower price, less board space needed and the 2 extra free pins.
The main reason for not using an internal oscillator is their tolerance.

Internal oscillators are usually not better than around 1%, which for an 8MHz oscillator equated to 80kHz.
A (correctly selected and driven) crystal can be eg. 20 ppm, which for the same 8MHz equated to 160 Hz.
Ceramic resonators are something in between (closer to the internal oscillator though).

 Many circuits can work just as well with the internal oscillator - it's a matter of which precision you need.

Any oscillator is temperature dependent to some extent, which is why you use a temp. regulated crystal "oven" for the most precise oscillators.

On some controllers, you can tweak the internal oscillator by adding a resistor and/or a cap and then there's the external RC oscillators, where you control the frequency by selecting the two R's and C for it.

Read through the datasheet of your controller and look up something on oscillators at either Atmel or Microchip, for a more in depth explanation of oscillators for microcontrollers.

The PWM and other peripherals of a controller don't care about what makes the vibes, as long as they're tickled an appropriate amount.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline mstachoTopic starter

  • Supreme Robot
  • *****
  • Posts: 376
  • Helpful? 10
Re: Why use an external oscillator in a uC?
« Reply #3 on: February 24, 2012, 08:56:11 AM »
Hm, neat.  Thanks for the replies. 

Is it possible, then, to use a single oscillator for multiple uCs?  I'm going to be setting up connected network of them to control a robot (mainly because my sensors require 16 pins each and I have 16 sensors...).  I have no worries about using more than one oscillator, I'm just thinking of simplifying things a bit.

Also, out of curiosity, if someone were to implement a real-time controller on a uC, I'm going to guess they'd need a very accurate clock as well, right?  Or is it correct to say that you're only as accurate as your clock, but you can be guaranteed that the code will execute everything within that accuracy?


MIKE
Current project: tactile sensing systems for multifingered robot hands

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Why use an external oscillator in a uC?
« Reply #4 on: February 24, 2012, 10:43:03 AM »
Hi,

Is it possible, then, to use a single oscillator for multiple uCs?  I'm going to be setting up connected network of them to control a robot (mainly because my sensors require 16 pins each and I have 16 sensors...).  I have no worries about using more than one oscillator, I'm just thinking of simplifying things a bit.
Absolutely yes.
The way to go about it depends on what oscillator you'll be using.
For something like this I'd use one of the integrated metal can crystal oscillators. They typically have a fan-out of 10, which roughly equates to around 16mA, so will be able to control any reasonable number of controllers. They need to be grouped together as closely as possible though and if you need the clock to go some distance, screening and/or a low impedance output buffer is needed.

You can daisy chain the oscillator signal as well. Say with a crystal on the "first" controller, with its oscillator output pin coupled to the next ones input, the second ones output to the third ones input and so forth.
On a very long daisy chain you'll probably get a huge lag from first to last, but if it isn't a synchronized clock you need, this won't matter (if it does, use the metal can osc. and a star distribution).


Also, out of curiosity, if someone were to implement a real-time controller on a uC, I'm going to guess they'd need a very accurate clock as well, right?  Or is it correct to say that you're only as accurate as your clock, but you can be guaranteed that the code will execute everything within that accuracy?
What's your definition of a real-time controller?
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

 


Get Your Ad Here