Designing a simple pulse generator

pulsetimer

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?

Best Answer

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.

Related Topic