Connect with us

Microcontrollers use a Crystal Why?

Discussion in 'Microcontrollers, Programming and IoT' started by willwatts, Nov 24, 2014.

Thread Status:
Not open for further replies.
Scroll to continue with content
  1. willwatts

    willwatts

    106
    1
    Nov 15, 2014
    Why do microcontrollers need to use a crystal? what does the crystal do for a microcontroller? is the crystal the master clock for the microcontroller?
     
  2. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,497
    2,839
    Jan 21, 2010
    They don't. oscillator. When it is used.
     
  3. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,271
    Nov 28, 2011
    All activity in a microcontroller needs to be controlled from a master clock source. This is provided by a crystal, or sometimes a separate oscillator module that contains a crystal, or sometimes a ceramic resonator, which is a cheaper and less accurate type of crystal.

    Often, a microcontroller will have one or more other crystals, for functions such as timekeeping.

    Crystals are used when a very accurate frequency is needed. A typical crystal is accurate to about ±100 ppm (parts per million), which is ±0.01%. So for example an 8 MHz crystal will have a frequency between 7999200 Hz and 8000800 Hz. This allows the microcontroller to generate accurate frequences, measure time durations accurately, communicate on serial connections at an accurate data rate, etc.
     
  4. willwatts

    willwatts

    106
    1
    Nov 15, 2014
    The microprocessor data sheets tell what the external oscillator and crystals frequency should be?

    if you change the crystals frequency up or down what will happen?

    The Oscillator or crystals waveshape waveform is triangled shaped, why does a microprocessor want a triangle waveform for a master clock?

    Why does it need to be controlled by a master clock source? why not just use code or instructions instead?
     
  5. Frenoy Osburn

    Frenoy Osburn

    64
    24
    Nov 20, 2014
    1. Yes the micro-controller data sheets does usually mention the clocking mechanisms, along with the types of clock sources. Why don't you check it out. Check page 24 of the datasheet for a very popular MCU below:

    http://www.atmel.com/Images/Atmel-8154-8-bit-AVR-ATmega16A_Datasheet.pdf

    2. It is recommend you also stay within the upper and lower limits mentioned in the datasheet. If you use a faster clock source, your code will be executed faster, since your MCU is now running faster than before.

    3.Don't quartz crystal oscillators produce square waves??:confused:

    4. A MCU contains a lot of digital logic. And most digital logic does need a clock source, and are commonly referred to as synchronous circuits (read flip-flops etc)
     
  6. willwatts

    willwatts

    106
    1
    Nov 15, 2014
    Yes but u can just use Code instructions to make a master clock source, you don't need an external clock source

    There is Resistors and capacitors surrounding the crystal mostly, so when i put my Oscope probe on the crystal, it's a triangle waveform not a squarewaveform

    The MCU crystal input is an RC input or what? or an A/D input?

    Why doesn't it want a triangle or squarewaveform source?

    yes under clocking the MCU or over clocking the MCU just changes the execution time? running the code faster or slow does what?
     
  7. Frenoy Osburn

    Frenoy Osburn

    64
    24
    Nov 20, 2014
    Reading the message from moderators, I'd refrain from wasting my time.

    But should this be a genuine query, I'd first like you to respond to these questions:

    1. Whats is your background with electronics?

    2. You seem to want to dive deeper into MCUs, which is usually what people do after having worked with them. So please send us links to your projects and any other material which will help us think that you are serious about it all.

    3. If you can write code to control the MCU speed without using a clock source at all (internal or external), then please go ahead and try it.


    If you can use code instead of a clock source, then by all means go ahead, design a chip and let me know the price. I'd like to give it a shot.

    Read the datasheet

    Take an MCU and feed it a wave of your choice, watch how it behaves and then scratch your head trying to figure out why.

    If you are asking me what does running the code faster/slower do, then it just makes me think I've wasted more of my time on you. So just answer the questions and if it makes me feel that you are not trolling, I'll get back to you.

    Your present occupation also seems to be "serial troll", doesn't add credit to being part of an electronics forum. Does it?
     
    Harald Kapp likes this.
  8. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,271
    Nov 28, 2011
    The data sheet specifies the range of frequencies over which the device is guaranteed to operate.

    Here are some sections from the data sheet for the Microchip PIC12F629/675 which is available at http://www.microchip.com/mymicrochip/filehandler.aspx?ddocname=en011653.

    pic oscillator.png
    This diagram shows how to connect a crystal to this microcontroller to control its operating frequency. The microcontroller contains circuitry to make a crystal oscillate, and the frequency at which it oscillates is then used to coordinate all of the internal circuitry in the microcontroller.

    pic timing.png

    Here's part of that microcontroller's specification table. It specifies that the maximum allowable frequency for the master clock is 20 MHz.

    The master clock controls the step-by-step action of almost every part of the microcontroller. It ensures that the time intervals between processing steps inside the microcontroller are:
    • Equal and regular in duration
    • At a fairly exact rate
    • Not too fast for the microcontroller's internal circuitry to keep up!
    If you use a lower frequency crystal, the microcontroller will just run slower. Everything it does - executing instructions, scanning I/O pins, generating frequencies, producing data - will just run slower.

    If you try to run the micro at too high a frequency, it will not work reliably. It may crash immediately, or randomly. It's like trying to run too fast - eventually you will trip up and fall.

    Running processors at higher than their rated frequency is called overclocking and people sometimes do it with their PCs, to get a slightly higher frame rate on their action games. It voids the warranty on the processor, it requires extra heatsinking (because the processor generates more heat - just the way a runner generates more heat if he runs faster) and it can cause crashes, and even permanent damage to the processor and other parts of the system.

    It doesn't want a triangle shape - it would prefer a nice clean square wave - but a crystal oscillates at a single pure frequency, and a square wave contains a series of lots of harmonics - frequencies higher than the actual base frequency. The signals on both sides of the crystal should actually be sinewaes. If you see a triangle wave, it is just a slightly modified sinewave, because the circuit is not operating perfectly linearly.

    The microcontroller has circuitry inside it to accept the sinewave (or triangle wave) and clean it up into a tidy square wave for the rest of the microcontroller's circuitry to use.
    The execution of the code (instructions) is controlled by the crystal. The crystal frequency drives the circuitry that controls the timing of the instruction execution.

    A typical microcontroller might execute one instruction for every eight crystal oscillator cycles. So if you use an 8 MHz crystal, that's 8,000,000 crystal clock cycles per second, and each instruction takes eight crystal clock cycles, so the microcontroller will execute 1,000,000 instructions per second.

    Some microcontrollers have an internal oscillator, which is not as accurate as a crystal oscillator (typically the accuracy is a few percent either way). With these devices, it is possible for program logic to adjust the frequency slightly, once the program has started up. But the microcontroller needs a clock source of some kind in order to execute any instructions in the first place.
     
  9. willwatts

    willwatts

    106
    1
    Nov 15, 2014
    Ok thanks Krisblue for your time and information , you can close this thread because I have a new one to start that is about loading a hex file in MCU's
     
  10. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,271
    Nov 28, 2011
    OK, done. Go ahead.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Thread Status:
Not open for further replies.
Electronics Point Logo
Continue to site
Quote of the day

-