0
\$\begingroup\$

I read in many tutorials that the inner clock in a micro controller are less accurate (%10) than the external crystal clock. When I generate variable frequency pulses by using a micro controller does that mean I am suing the inner clock and the pulses are not accurate enough? Some tutorials play with the registers and obtain any pulse frequency.

My question is, for example if I use AVR such like in Arduino Uno board and play with the registers does that mean I will use the inner clock? Is there a way to obtain more accurate pulses?

\$\endgroup\$
1
\$\begingroup\$

By "inner" clock, you mean the internal RC oscillator that comes with the device from the factory. It is inside the chip, and is not very accurate over temperature range, which means it will not actually be the frequency that you assume it is, and indeed it may have a lot of "jitter" which means the clock generated from the internal oscillator will not have very "precise" timing, one clock pulse might be +-10->15% different to the one before it, and the one after it. This is bad for cycle-by-cycle timing.

The use of external crystals allows you to have faster clock speeds than that possible with the internal source available in your given example (Atmel ATMEGA328P which is on the Arduino Uno), and these provide (usually! Quality and material are relevant here) very good accuracy and cycle-by-cycle precision of the clock signal.

The system clock is generated from these different possible sources, so if you use a bad accuracy/quality source and expect high speed and timing, you will have problems. Use a good crystal, and you can very nicely time things, such as a very precise/accurate digital signal at a set frequency (given the limitations of timers mentioned below).

The registers that you mention are the perhaps those which allow you to change the CLKDIV options, which allows you to divide an input clock source frequency and make the system clock slower which uses less power, and may give better timing characteristics. The output of the system clock signal may sometimes be selected for one of the microcontroller pins, to clock external devices with a nice clean digital clock - for example, a Camera IC, or a reference clock input for synchronous devices.

The timers inside the microcontrollers use the main clock source, and often have dividers you can set for them separately. From the resulting timer speed, you can then set "output compare" registers, which allows you to choose (based on the resolution!) a certain point where the timer will reset - you may have this essentially act as a digital pulse generator, of reasonably good control of the frequency up to a certain point. 8 Bit timers will allow you to choose an output in steps of 1-255, and 16 bit timers allow you to set a step size of 1->65536. Using a 16 bit timer and a very good quality clock source input would yield the "best" output.

The Atmega328P on the Arduino Uno has multiple timers, so you could make the output compare channels produce more than one custom/adjustable frequency pulse signal.

\$\endgroup\$
0
\$\begingroup\$

If you use a device that can use an external crystal or oscillator and then use an external crystal or oscillator then it will be as accurate as that external crystal or oscillator. There is nothing preventing you from hooking up e.g. a rubidium precision oscillator in place of something more primitive.

\$\endgroup\$
0
\$\begingroup\$

The "inner clock" is the on-board oscillator supplied with many MCU's, and its frequency may not be accurate or stable enough to produce a trusty pulse generator.

In order to do that, an external timing source (crystal, crystal oscillator, atomic frequency standard, etc.) with the required accuracy and stability can be used, and the desired pulse period and frequency/repetition rate obtained through the manipulation of the MCU via software.

For example, assume that you want to use an MCU which can support a 10MHz external clock, sports single-clock instruction execution cycles, that you're working in assembler, and that you want to generate a pulse 1 microsecond wide with a 100kHz rep rate.

In order to do that, you'd load one register with a numerical value corresponding to the output pulse width you wanted, another with the delay required between the falling edge of the pulse and the leading edge of the next pulse, and then you'd count them both down, sequentially, using the external clock source, until they were both empty.

That would give you one cycle of the desired output, and when both counters decremented to zero you'd load them both up again and start over.

A caveat here is that the load, decrement, compare, jump, and I/O instructions (in fact, all of the instructions) take time to execute, so these times must all be accounted for when loading the counters with the pulse width and rep-rate values in order to have the pulses come out right.

The possibility also exists that you may be able to use the MCU's internal hardware timers to do the job; YMMV.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.