2

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.

  • The ATTinys have a build in PLL. – Gerben Jul 16 '15 at 14:02
  • thanks gerben, so if i use aduino uno all i have to do to make a PLL is just to coding it right?? – Elfridus Jul 16 '15 at 14:16
  • 1
    An Uno does not use an ATtiny, so no. You may be able to build a frequency locked loop in software, but right now the major problem with your question is that you don't specify the details of your goal – Chris Stratton Jul 16 '15 at 15:45
  • Uno uses an ATMega328. You can e.g. use a bare ATTiny85 chip, or a board based on that same chip, like a Trinket, or Digispark. (There are other ATTinys beside the 85, but that one is the most popular). – Gerben Jul 16 '15 at 18:09
  • thanks again greben, i forget that one point, this is for my final project my goal is to create a signal (pll output) from the reference signal that come from function generator. my lecturer said the reference signal i have to give is following the working frekuency and amplitude of arduino uno. so it's doesn't need special req. right? – Elfridus Jul 17 '15 at 0:13
1

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:

enter image description here

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:

enter image description here

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.

  • thanks majenko, sadly i already propose this title for my final project so i have to build this system using arduino. and i think what i aiming is that complex. do you have any idea? – Elfridus Jul 17 '15 at 0:17
  • thanks @majenko, i'll consider it by using arduino due just like jack said. and i'll be concern about the output that arduino gives.. – Elfridus Jul 22 '15 at 15:26
  • Addendum: Use an output oscillator with reset function. Detect the "reset point" of the input waveform. (The Arduino supports interrupts, for example) – MickLH Jul 22 '15 at 16:14
  • thanks for that @MickLH.. i've already considered by using arduino, despite it might be expensive but i has already propose it.. – Elfridus Jul 23 '15 at 3:17
0

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.

  • thanks jake, that's all i need. i only need a low frequencies in range of KHz, and the amplitudes is follow the maximum input voltage of arduino right? and which arduino can you suggest? – Elfridus Jul 17 '15 at 0:30
  • I've added to my answer a few extra notes on attempting this. All I can say is: Good Luck! Software PLLs are tricky; there are a lot of resources out there about how to do it theoretically, but very few on real world implementations of them. – Jake C Jul 17 '15 at 1:21
  • thanks a lot jake, well i have a lot of work right.. maybe i'll ask you more about it while i'm working on it could i? – Elfridus Jul 22 '15 at 15:15
0

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.

  • Thanks for your answer @Misha and ya, i'm little bit interest with your detail. And first at all to implement pll using arduino, how can i used adc to read the input signal if it come from function generator for example? – Elfridus Oct 2 '15 at 15:49

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.