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.
|
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 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. |
|||||||||||||||||
|
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. |
|||||||||||||
|