What Is The Precision Of The Propeller's Internal Clock Frequency
WaffenGeist
Posts: 5
I need a source of true random numbers for my propeller application.
For this, I plan to use the Propeller's internal clock frequency. The frequency cannot be perfect, it has got to have a noise level, a decimal point below which frequency is unreliable. The frequency itself must vary a little bit due to background thermal noise.
I need to know the frequency's precision level, at high frequency, without an external crystal. I did not find this in the propeller manual, it doesn't discuss specifics like that.
I feel I might need to measure the stability myself with a scope but if somebody knows it please let me know.
Thanks.
For this, I plan to use the Propeller's internal clock frequency. The frequency cannot be perfect, it has got to have a noise level, a decimal point below which frequency is unreliable. The frequency itself must vary a little bit due to background thermal noise.
I need to know the frequency's precision level, at high frequency, without an external crystal. I did not find this in the propeller manual, it doesn't discuss specifics like that.
I feel I might need to measure the stability myself with a scope but if somebody knows it please let me know.
Thanks.
Comments
Welcome to the Parallax forum! Take a look in the OBEX for an object called RealRandom. Chip Gracey wrote it to use random fluctuations in the Propeller's internal PLL circuitry for generating true random numbers.
-Phil
Thank you very much my friend, that is exactly what I needed. Chip Gracey is a true genius.
Thank you. Matter Resolved.
Now, how do I modify the Unsolved to Solved in the thread title ?
-Phil
Indeed, welcome to the forum.
I'm sure you now have a good solution to your problem in hand.
But it poses a question in my mind. If there were no such real random object possible on the Prop and if you had found out the accuracy of the propellers clock frequency then how would you have used that to create real random numbers? Surely the clock drifts a bit here and there, all clocks do, but then so does the speed of the processor and hence your code as it is driven by the very same clock.
I would have used a cog to toggle individual pins high and low based on the clock's internal timing and I would have used another cog to read the individual pins based on the clock's timing. Given that there would be a slight drift in the clock's frequency, you could never tell what the value of individual pins would be at the time of reading, hence complete random words to be used for my simulation.
Think of two bus wipers not in synch.
-Phil
Anyway over Christmas I have been researching random number generators, pseudo and real, it's an old fascination of mine. I think it's something to do with wanting to randomize the twinkling of Christmas tree LEDs:) My thinking currently goes like this:
0) Chip's real random is brilliant.
1) BUT it a shame to use a whole 32 bit CPU to do just that and what if you are running out of COGs?
3) So, how about we fire up RealRandom for a short while, get some values out of it for use as seeds for Spins pseudo random number operator? Then shut down Real Random freeing the COG for other uses.
4) BUT Spins random operator is probably not all that good and has a short period.
5) So why not implement a known good pseudo random number generator in a hand full of lines of Spin which we seed from the Real Random values above.
7) The result of all this would be pretty much indistinguishable from using Real Random all the time.
Sadly a lot of those "known good" PRNGs use unsigned arithmetic which Spin does not support, and/or 64 bit arithmetic, again not supported, and/or use multiplies that may be slow.
Luckily over Christmas checking over the PRNG's developed by George Marsaglia I found one that uses signed 32 bit math and no multiplies. It has a period of about 2 ^121 = 2.6 x 10^36. That is it will supply 2 to the power 121 random looking numbers before it starts to repeat itself. Surely good enough for anything we might do on the Prop and saves a COG running RealRandom continuously. Best of both worlds.
If anyone is interested I can post my Spin implementation of this PRNG and a brief demo of how to use it.
P.S. I'm not saying that Spins random operator is faulty and I have not run it through any statistical tests of randomness. However I strongly suspect we can do better in the randomness department and period if not speed by using a know good long period RPNG