P2 PLL/Clock considerations
Surac
Posts: 176
in Propeller 2
The little picture above shows how I have understood the PLL/Clock generation in P2.
As one can see there are 2 Dividers and a PLL multiplier. This makes reaching the
desired clock possible using many combinations of the factors available.
- Which limits apply to fa and fb?
- Are there any constrains regarding divider and mulitplier factors?
- Is it better to divide the clock down and multiply then again or is it better to not divide in the first place?
- Are there any parts of the P2 that use fa or fb?
- What is the intention of the final divider that makes fb to fcpu? It seems redundant to me
Thanks for your time
Comments
The main constraint is: Fb (PLL output) 100Mhz to 350MHz. A PLL synchronizes a variable frequency oscillator to a reference frequency. These oscillators have certain operating frequency range.
The post divider is necessary if you want to run below 100MHz.
Phase noise is reduced by keeping Fa (divider output) as high as possible. This is mostly a concern for radio transmitters. So don't divide down unnecessarily. The PLL was improved with rev B so it works well with lower reference frequency. With 20MHz input, any divider value should be ok for most applications.
Here is a frequency table I generated some time ago to make setting the frequency/knowing the real frequency set: https://forums.parallax.com/discussion/173054/a-frequency-table-for-20-mhz-quartz-attached
As these are frequencies from the upper range, divider B is considered 1.
This begs another question: is there any way to bypass the PLL/multiplier/divider and just let the P2 be driven at whatever freq appears on the XIN pin?
It has to be noted that PNut / Propeller Tool (and I think flexspin uses the same algorithm?) are very good at calculating the clock settings for you. The algorithm used is described here: https://forums.parallax.com/discussion/comment/1486815/#Comment_1486815
Thank you all very much!
This information will help me
Most Xtal oscilators work like in the above diagram. So perhaps you can use a external clock on one of the xtal input pins.
Yep, there is a couple of options. Both supported in Spin2 and documented near end of the manual under the heading of "Clock Setup":
Both involve not defining the _clkfreq constant.
PS: The HUBSET mode bits of each mode are also provided in the same table.
PPS: And I see the two shared hubRAM variables are still located way off at $40 and $44 rather than the agreed $10 through $1f. Chip, you might want to get that fixed.
yes i also found the mode and frequency in hubstart+$40 and $44.
Yes, but I (1) wanted to set the frequency on the fly while changing video modes and (2) know what I already set. So I made this table. Or rather a program which generated it for me.
https://forums.parallax.com/discussion/comment/1486815/#Comment_1486815
viewing the pseudocode provided here the considerations seem to be:
The code needs some tweaking to exit the loops if it found a good value combination or found.
Best would be to run all loops and keep track of the best result
And to add a warning for anyone reading this, when changing frequencies, there are constraints on how to do this. Evan worked out the method to do it reliably so I’ll let him point you to the reference.
If you're using a high level language like Spin then it's handled for you. EDIT2: Spin2 provides the clkset() function.
If you are hitting the metal and want to use Pasm code to adjust the clock frequency then have a read here - https://forums.parallax.com/discussion/comment/1466528/#Comment_1466528
and related handover discussions - https://forums.parallax.com/discussion/comment/1466702/#Comment_1466702
Also, the hardware doc details it as well. Chip originally recommended and documented only using the "reuse prior mode" method. Others have since added the $F0 mode as an alternative, myself included. Chip hasn't said don't do this as yet, but he's also never given it a blessing. The existence of $F0 in the hardware doc is likely due to others adding it.
EDIT: Here is Chip's only comment on $F0 to date - https://forums.parallax.com/discussion/comment/1466494/#Comment_1466494
BTW: I don't use $F0 in my wrapper code, nor does Chip with Spin2. I do use it for quick hacks without the wrapper.
Here is the code in the compiler that determines the PLL setting for a requested frequency. You can read the comments to get an idea of its decision making:
For people who need some SPIN2 code to determine the clock mode for a given desired P2 operating frequency using the PLL here is the algorithm I use in my video driver to scan through and determine the clock mode setting to be used with HUBSET for minimizing the frequency error. You can customize the error tolerance, and if it can't meet the error tolerance a zero is returned so you know this requested frequency is outside the range of possible values:
Here is a small Python 3.7 program that will construct the neccersary pasm code to initialy set the clock
It will show up to 3 combinations and prefersts low preDivider and low Error values. Feel free to comment
and change
please change the upper most lines in the file to meet your needs! You need to input the desired
values in the program file. The ist no gui.
Edit python file extension is not allowed in forum so i post the .py file as a .txt file. please rename the file to *.py
befor using it