user11250: Is it possible to create a system like a PLL using an Arduino?
I ask this because there are some parts in the PLL system, such as: phase detector, VCO, divider, and I don't know how to make for each part in Arduino board.

user11086: There are two types of PLLs, hardware PLLs and software PLLs. Majenko has already addressed hardware PLLs so I will leave you to his answer for that.
Software PLLs perform the same function as regular hardware PLLs, but with code, and as a result are constrained by the clock speed and sample rate of the controller they are running on. Usually this means you are limited to sub MHz frequencies. The math and computation necessary to perform this is quite complicated, and I do not expect you would get particularly good performance out of your standard Arduino controller, as all of them lack a floating point unit to perform these types of computations.
If you were to still try and attempt this you would have to do it using integer math only. The faster the CPU, the higher the frequency it will be able to lock on to. The fastest Arduino available today is the Arduino Due. Aside from being fast, the Due can perform 32-bit arithmetic in a single cycle, which should be handy. The frequency limit will be dictated by how many cycles all of your calculations take.

user13526: You can absolutely make a PLL using an ATMega microcontroller, and I have made one myself using a ATTiny45. The way I did it is by setting the clock source to the internal RC oscillator, and using that as my VCO (or in this case, Numerically Controlled Oscillator). The internal oscillator can be tuned between 50% and 200% of its nominal frequency by adjusting the OSCCAL register, which can safely be done without stopping the processor. I used the ADC to read the input signal. For the phase detector I programmed the MCU to alternatively add, then subtract the ADC registers from an accumulator register. This is mathematically equivalent to multiplying the incoming signal by a square wave from the local oscillator, and integrating the result. After a fixed number of cycles, I checked to see if the accumulator was negative or positive. If its negative, I set OSCCAL to a "high frequency" which is definitely higher than the input signal. If its positive, I set it to a "low frequency", which is definitely too low. Of course this is a form of Bang–bang control, so its never stable per se, but I found works perfectly. Its much better than my attempts at a PID controller. Looking on my oscilloscope, the is almost no jitter visible between the input system and the internal RC clock, which I outputted on the CLKO pin by setting the appropriate fuse bits.
Although I used GCC and USBTinyISP, I see no reason why my system can't be implemented on Arduino. Setting the fuse bits will require a bit of work though, you can read more here:
http://forum.arduino.cc/index.php?topic=124879.0
If there is enough interest, I can add more detailed information to my answer.

user4143: A PLL is a very complex device which is not something that can easily be created purely in code.
Many microcontrollers include a PLL as part of their oscillator systemm which allows them to run internally at a higher speed than their external crystal.  This is not a programmable peripheral that you can use for your own things, but an integral part of the workings of the microcontroller.
While it may be possible to write one in software the results would be very somewhat limited. The best you could hope for is to use timers to measure an incoming frequency and use the results to output another frequency through some means, maybe PWM.
To create a real PLL you would be best off using either a dedicated PLL chip (which you can buy off the shelf) or use some form of programmable logic like a CPLD that has a built in PLL block.
Some microcontrollers, most notably the Cypress PSoC range, have programmable logic blocks built in that may be more suited to your task than an Arduino.
A typical digital PLL looks something like this:

Implementing all that in code would be both tricky and somewhat slow on a little 8-bit MCU with no floating point support.  However, the basic principal of what a PLL can be summarised in one simple sentence:

The frequency coming in determines the frequency going out.

The PLL, or Phase Locked Loop is just one method of achieving that desired result.
Another method, which is not using any form of PLL, is purely algorithmic and consists of just three things:

Three simple blocks, all of which the Arduino is, to a certain extent, capable of performing.
The first block, the Frequency Detector, works out what the frequency of the incoming signal is.  That could either be by counting the number of pulses that arrive over a certain time frame, or measuring the time between successive pulses.  Which method you use (Frequency Counting or Frequency Measuring) is really down to what frequency ranges you are using.  Frequency Counting is better for higher frequencies, whereas Frequency Measuring is better for low frequencies.  There are many examples on the web of how to do both of those using timers on the Arduino.
The Decision Making is basically working out what your output frequency wants to be according to your input frequency.  This could be as simple as "Output = input * 2", for instance, or something more complex like "Between these frequencies I want to output this frequency, between these frequencies this other frequency, etc".  It's entirely up to you.
The third block just takes the decided-upon output frequency and generates it.  That could be done using the hardware PWM generation of the Arduino.
All this, though, will be limited to relatively low frequencies (tens of kHz maximum really) though with clever coding you could push it up slightly higher.
One thing that really makes this method differ from a PLL is that you don't get the "PL" portion of it - that is, the phase of the incoming frequency is lost, and the output frequency is running entirely with its own phase.  There is little or nothing you can do to synchronise the phases of the input and output like you get with a full PLL.

11250: <p>Is it possible to create a system like a PLL using an Arduino?
I ask this because there are some parts in the PLL system, such as: phase detector, VCO, divider, and I don't know how to make for each part in Arduino board.</p>
 11086: <p>There are two types of PLLs, hardware PLLs and <a href="https://en.wikipedia.org/wiki/Phase-locked_loop#Implementing_a_digital_phase-locked_loop_in_software" rel="nofollow">software PLLs</a>. Majenko has already addressed hardware PLLs so I will leave you to his answer for that.</p>

<p>Software PLLs perform the same function as regular hardware PLLs, but with code, and as a result are constrained by the clock speed and sample rate of the controller they are running on. Usually this means you are limited to sub MHz frequencies. The math and computation necessary to perform this <a href="http://liquidsdr.org/blog/pll-howto/" rel="nofollow">is quite complicated</a>, and I do not expect you would get particularly good performance out of your standard Arduino controller, as all of them lack a floating point unit to perform these types of computations.</p>

<p>If you were to still try and attempt this you would have to do it using integer math only. The faster the CPU, the higher the frequency it will be able to lock on to. The fastest Arduino available today is the Arduino Due. Aside from being fast, the Due can perform 32-bit arithmetic in a single cycle, which should be handy. The frequency limit will be dictated by how many cycles all of your calculations take.</p>
 13526: <p>You can absolutely make a PLL using an ATMega microcontroller, and I have made one myself using a ATTiny45. The way I did it is by setting the clock source to the internal RC oscillator, and using that as my VCO (or in this case, Numerically Controlled Oscillator). The internal oscillator can be tuned between 50% and 200% of its nominal frequency by adjusting the OSCCAL register, which can safely be done without stopping the processor. I used the ADC to read the input signal. For the phase detector I programmed the MCU to alternatively add, then subtract the ADC registers from an accumulator register. This is mathematically equivalent to multiplying the incoming signal by a square wave from the local oscillator, and integrating the result. After a fixed number of cycles, I checked to see if the accumulator was negative or positive. If its negative, I set OSCCAL to a "high frequency" which is definitely higher than the input signal. If its positive, I set it to a "low frequency", which is definitely too low. Of course this is a form of Bang–bang control, so its never stable per se, but I found works perfectly. Its much better than my attempts at a PID controller. Looking on my oscilloscope, the is almost no jitter visible between the input system and the internal RC clock, which I outputted on the CLKO pin by setting the appropriate fuse bits.</p>

<p>Although I used GCC and USBTinyISP, I see no reason why my system can't be implemented on Arduino. Setting the fuse bits will require a bit of work though, you can read more here:</p>

<p><a href="http://forum.arduino.cc/index.php?topic=124879.0" rel="nofollow">http://forum.arduino.cc/index.php?topic=124879.0</a></p>

<p>If there is enough interest, I can add more detailed information to my answer.</p>
 4143: <p>A PLL is a very complex device which is not something that can easily be created purely in code.</p>

<p>Many microcontrollers include a PLL as part of their oscillator systemm which allows them to run internally at a higher speed than their external crystal.  This is not a programmable peripheral that you can use for your own things, but an integral part of the workings of the microcontroller.</p>

<p>While it may be possible to write one in software the results would be very somewhat limited. The best you could hope for is to use timers to measure an incoming frequency and use the results to output another frequency through some means, maybe PWM.</p>

<p>To create a real PLL you would be best off using either a dedicated PLL chip (which you can buy off the shelf) or use some form of programmable logic like a CPLD that has a built in PLL block.</p>

<p>Some microcontrollers, most notably the Cypress PSoC range, have programmable logic blocks built in that may be more suited to your task than an Arduino.</p>

<p>A typical digital PLL looks something like this:</p>

<p><img src="https://i.stack.imgur.com/eAzru.png" alt="enter image description here"></p>

<p>Implementing all that in code would be both tricky and somewhat slow on a little 8-bit MCU with no floating point support.  However, the basic principal of what a PLL can be summarised in one simple sentence:</p>

<blockquote>
  <p>The frequency coming in determines the frequency going out.</p>
</blockquote>

<p>The PLL, or <em>Phase Locked Loop</em> is just one method of achieving that desired result.</p>

<p>Another method, which is <em>not</em> using any form of PLL, is purely algorithmic and consists of just three things:</p>

<p><img src="https://i.stack.imgur.com/I47sg.png" alt="enter image description here"></p>

<p>Three simple blocks, all of which the Arduino is, to a certain extent, capable of performing.</p>

<p>The first block, the <em>Frequency Detector</em>, works out what the frequency of the incoming signal is.  That could either be by counting the number of pulses that arrive over a certain time frame, or measuring the time between successive pulses.  Which method you use (<em>Frequency Counting</em> or <em>Frequency Measuring</em>) is really down to what frequency ranges you are using.  Frequency Counting is better for higher frequencies, whereas Frequency Measuring is better for low frequencies.  There are many examples on the web of how to do both of those using timers on the Arduino.</p>

<p>The <em>Decision Making</em> is basically working out what your output frequency wants to be according to your input frequency.  This could be as simple as "Output = input * 2", for instance, or something more complex like "Between these frequencies I want to output this frequency, between these frequencies this other frequency, etc".  It's entirely up to you.</p>

<p>The third block just takes the decided-upon output frequency and generates it.  That could be done using the hardware PWM generation of the Arduino.</p>

<p>All this, though, will be limited to relatively low frequencies (tens of kHz maximum really) though with clever coding you could push it up slightly higher.</p>

<p>One thing that really makes this method differ from a PLL is that you don't get the "PL" portion of it - that is, the phase of the incoming frequency is lost, and the output frequency is running entirely with its own phase.  There is little or nothing you can do to synchronise the phases of the input and output like you get with a full PLL.</p>
