I saw someone on another forum ask for advice on how to implement a real PLL using Max/MSP. It seemed like a great task for gen~, so I put this patch together. The gen~ object creates a square wave internally and tries to lock onto the signal from a cycle~ object.
PLLs can be a tricky subject, but playing with the patch doesn't require understanding the math. I tried to add comments about how tuning controls affect the behavior.
This implementation uses a "bang-bang" phase detector and a PI control loop.
For the interested, wikipedia has a lot of information on PID control loops:
I removed the "D" term to simplify things.