Microcontroller phase locked loop, ping Tim Wescott et. al.

Has anyone successfully implemented a phase locked loop on a microcontroller?

The frequency of interest would be somewhere in the 200kHz range, and the objective of the PLL would be FM demodulation. So I'd have an input for the FM modulated frequency, and an external VCO in that range that the uC would hopefully control via filtered PWM. Other than that, this is mostly hypothetical for now.

Does this seem possible? I have the following reference:

formatting link

I'd be hoping to use something like an ATTiny. All code would be adjusted to use fixed-point math, I'd imagine.

Reply to
bitrex
Loading thread data ...

For a given resolution, you might as well just use a counter input.

It's not going to be a very good demodulator...what modulation frequency and modulation index are you looking to accommodate?

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs 
Principal Consultant 
ElectroOptical Innovations LLC 
Optics, Electro-optics, Photonics, Analog Electronics 

160 North State Road #203 
Briarcliff Manor NY 10510 

hobbs at electrooptical dot net 
http://electrooptical.net
Reply to
Phil Hobbs

Ah, wait a second, I got confused. I don't actually need this PLL to do FM demodulation, haha. Rather embarrassing. What I have is maybe an external sine VCO whose "base frequency" I would like to lock to a reference. So we have a varactor diode or something for CV input on the oscillator, and over long time scales the PLL keeps the VCO synced to some kind of reference (generated by the uC?) or something like this.

Maybe there's a better way to do this.

Reply to
bitrex

Awwwh, shucks, Phil, Don't you know that the solution for all analog problems is a uP ?>:-} ...Jim Thompson

--
| James E.Thompson                                 |    mens     | 
| Analog Innovations                               |     et      | 
| Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    | 
| San Tan Valley, AZ 85142     Skype: skypeanalog  |             | 
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  | 
| E-mail Icon at http://www.analog-innovations.com |    1962     | 
              
                    Age gets better with wine!
Reply to
Jim Thompson

On Thu, 06 Aug 2015 11:19:55 -0700, Jim Thompson Gave us:

Envelope tracking. (not a post office term)

Reply to
DecadentLinuxUserNumeroUno

How about a 4046? Guaranteed to lock up anywhere in the VCO's range.

Do you want to lock it at 1:1 or some other ratio?

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs 
Principal Consultant 
ElectroOptical Innovations LLC 
Optics, Electro-optics, Photonics, Analog Electronics 

160 North State Road #203 
Briarcliff Manor NY 10510 

hobbs at electrooptical dot net 
http://electrooptical.net
Reply to
Phil Hobbs

Just like the solution for all optical problems is a webcam and a crapload of software.

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs 
Principal Consultant 
ElectroOptical Innovations LLC 
Optics, Electro-optics, Photonics, Analog Electronics 

160 North State Road #203 
Briarcliff Manor NY 10510 

hobbs at electrooptical dot net 
http://electrooptical.net
Reply to
Phil Hobbs

Tim who?

Uhh your answers are: yes, yes, my how interesting, and maybe not with that processor. Would you like me to unpack?

Yes:

Yes, I have successfully implemented a PLL on a microcontroller. Your choice of wording was very appropriate -- one doesn't so much implement a PLL _in software_ as one implements it on a (particular) microcontroller.

Yes:

Yes, this seems possible. I'm not sure how practical, but it's in the realm of the possible.

my how interesting:

I only skimmed the link, but don't dive into the DSP literature and implement a direct-form-anything filter for your loop filter. Read this page:

formatting link
and implement a real PLL controller.

Maybe not that processor:

I'd have to do lots of analysis and math. If your goal is to mix the output of an FM IF strip down to 200kHz or whatever, run it into a pin on a microprocessor, and extract broadcast-quality stereo from that, I'm not sure that you'll get there from here with an ATTiny, or for that matter, an AT-anything. I'm pretty sure that it can be done digitally, but whether it can be done with anything short of an FPGA -- I dunno.

You'll have a huge tradeoff between the inherent accuracy of measuring the edge time (which means you need a high clock rate) and the processor's ability to keep up (which I think is what will rule out an ATTiny).

You MAY be able to mix your IF down to baseband using an I/Q demodulator, filter, and ADC it into the processor -- but at that point you have sufficient information to do you demodulation without needing any external PLL hardware, and you're still burdened with needing a high sampling rate. I'm guessing, but I think you'd need to sample at 100kHz at a minimum, and 500kHz sounds more likely -- you just can't do much arithmetic on an AT core in 2us.

--

Tim Wescott 
Wescott Design Services 
http://www.wescottdesign.com
Reply to
Tim Wescott

What? Are you saying you have a pure tone at 200kHz that you want to lock onto with a PLL? And you want to do the loop filter with a microcontroller?

Could you please go back and restate your question? Please let us know what you're using for a reference signal, what you're using for a VCO, why you can't use the reference signal, why the VCO is going to be making things better, etc.

--

Tim Wescott 
Wescott Design Services 
http://www.wescottdesign.com
Reply to
Tim Wescott

'struth. It's just that for some of them, the uP that'll do the job hasn't been invented yet.

Just you wait -- before you die, Linear Technologies will have high-end op-amps with ARM cores.

--

Tim Wescott 
Wescott Design Services 
http://www.wescottdesign.com
Reply to
Tim Wescott

I'm not sure that it would work in the application I'm thinking of. What I want is basically a "tuning" feature where I can have apply a CV to a bunch of RF VCOs that will sync them up to a crystal controlled reference, then allow the VCOs frequency to vary about that reference frequency.

Reply to
bitrex

I'm sorry to change requirements on you, but I'm going to change requirements on you, haha. For the project I'm thinking about, I believe I'm going to do the FM demodulation with a legit hardware PLL.

I was thinking about using the uC based PLL to sync a bunch of VCOs in that range to a crystal controlled reference frequency, and then allow them to vary about that base frequency.

Reply to
bitrex

I guess that is essentially what I'm asking. Using a uC as the loop filter in a PLL to keep a bunch of say, Colpitts oscillators with varactor diodes or something as the tuning elements locked to a reference over long time scales.

Reply to
bitrex

Try reading up some articles on "huff and puff frequency stabilisers" - may inspire or help you hit your goal.

piglet

Reply to
piglet

Are you perhaps talking about an offset loop ? Otherwise, your description doesn't make a lot sense.

Reply to
upsidedown

Get away with the VCOs and do it with NCOs and you can do FM, PM and AM quite easily. No need for PLLs or phase detectors. Of course the uP must handle about 500 kHz interrupt rate :-).

Reply to
upsidedown

Thank you! This seems to be very much like what I'm looking for.

Reply to
bitrex

Yes you can do this. It's the sort of things that's mostly worthwhile if your reference has short-term noise that you want to clean up with the oscillators (which means you need to build low phase-noise oscillators).

Assuming the reference comes to you as a square wave, I would square up the VCO output. Then I would capture both the reference and the VCO signal with a capture/compare input on a timer on the microcontroller. The difference in arrival time is what you use as your "phase error".

You probably need to implement some sort of cycle counting to aid in acquisition, and be very careful about not introducing phase noise into your oscillators with your correction signal: filtered PWM may not cut it, you may need to use a DAC (and you should take care about noise on your DAC reference voltage, or on your PWM rails).

You may even be able to do this with an AT-Tiny, but you won't be doing much else. I've done something similar to gen-lock digital video to an external source, but in our case it made sense because our video timing was in digital-land: had it all been analog I would have been the first one to question why we weren't doing the PLL entirely in the analog (in fact, IIRC, I made sure that we blocked out an analog solution before we decided that digital was better).

--
www.wescottdesign.com
Reply to
Tim Wescott

formatting link

Awesome.

Reply to
bitrex

Nice of you to wish us another 100 years or so. ;)

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs 
Principal Consultant 
ElectroOptical Innovations LLC 
Optics, Electro-optics, Photonics, Analog Electronics 

160 North State Road #203 
Briarcliff Manor NY 10510 

hobbs at electrooptical dot net 
http://electrooptical.net
Reply to
Phil Hobbs

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.