# oscillator in microcontroller

if we see in arduino we have crystal oscillator in its board.it produce square wave of frequency about 16 mhz or something else.My question is how it would be related to input.explain me basically with some examples.thank you in advance

I'm unsure what you mean.

we use crystal oscillator to generator square waves of specific frequency.say 16MHZ .digitalWrite(1) digitalWrite(0) alternatively is it produce 101010101 using oscillator.am i right.if not whats the purpose of using oscillator arduino board.please help me

this is what i exactly mean if we write a code to off some thing after 5 seconds.it will calculate time from oscillator.it off after16mhz*5 cycles am i right.please someone come forward.i am in little choas

bhuvaneshnick: we use crystal oscillator to generator square waves of specific frequency.say 16MHZ .digitalWrite(1) digitalWrite(0) alternatively is it produce 101010101 using oscillator.am i right.if not whats the purpose of using oscillator arduino board.please help me

The AVR microcontroller chip must have a free running clock to make all it's internal logic and circuitry function. Note that this clock source can be from several different optional modes:

External crystal resonator External ceramic resonator (this is what standard Uno R3 uses these days) External crystal oscillator module (this really means any external TTL level clock source) Internal R/C oscillator.

The settings of the fuse bytes determines what mode the AVR chip is expecting to use.

Lefty

bhuvaneshnick:

I saw it, but could not make sense of what you are saying or asking. Sorry.

Lefty

i beak down this little.we give a code to off led after 5 seconds.how does this calculate time.note oscillator prduce16mhz cycle per second.so after five *16mhz cyle(i.e 80mhz cycle) it knows it 5 seconds.in general how time calculation be done by oscillator that what i meant

bhuvaneshnick: i beak down this little.we give a code to off led after 5 seconds.how does this calculate time.note oscillator prduce16mhz cycle per second.so after five *16mhz cyle(i.e 80mhz cycle) it knows it 5 seconds.in general how time calculation be done by oscillator that what i meant

Well if you can post your code maybe we can explain the relationship between the system clock and your 5 second command action. It usually involves one of the internal programmable hardware timers that are available on the AVR chips.

now i am some what clear could detial.what u mean by “system clock and 5 second command action”.please

On the Uno and similar the timer0 internal timer is set to count at 250kHz (16MHz divided by 64) and it generates an interrupt each time if overflows (every 1.024ms), these overflows are counted and the code in micros() and millis() uses it and the current value of the timer0 TCT0 register to deduce the time in us or ms since last reset (modulo 2^32).

A microcontroller like the AVR in an Arduino is an implementation of "Clocked Digital Logic." Every time the oscillator "ticks", a bunch of things happen - a new AVR instruction is executed, various counters increment, and so on. Some of this operation is documented, and produces results that your sketch can look at. And since it all happens based on the tick of the oscillator, we can tell how long thing take.

So every oscillator clock (62.5ns), the timer prescaler counter increments. After every 64 clocks of the prescaler, the counter for timer0 is incremented. After every 256 clocks of the timer0 clock, an "interrupt" is triggered (this is now every 1.024ms.) The software counts the number of milliseconds since the chip was powered on, in a variable. If your sketch is doing a 5-second delay, than it is checking that variable over and over again to see whether 5000 ms have gone by.

this is what i expected markt and westfw now i am happy .some more things to clarify. 1)why dont we increase prescaler unit that is instead of divide by 64 u dont we divide by 256 or higher so we can also use nano instead of millis() and micros().why particaular that is divided by 64.whats the reason. 2)imarkt post: u have said "the current value of" the timer0 TCT0 register to deduce the time in us or ms since last reset (modulo 2^32)."why reset at 2^32. help me

System lock occurs every 62.5nS.(1/16,000,000 Hz) Every 16 clocks is 1 microsecond. Every 64 clocks is 4 microseconds. See Table 9-17. Clock Prescaler Select for the available settings.

I suspect that if you set the prescaler to lower than 64, the code spends too much time processing time interrupts and impacts performance.

You are free to modify the code to change that.

what is table9-17 refers to.where is that table.

The table is from the datasheet for the '328P.
http://www.atmel.com/devices/ATMEGA328P.aspx