Shop OBEX P1 Docs P2 Docs Learn Events
What Is The Precision Of The Propeller's Internal Clock Frequency — Parallax Forums

What Is The Precision Of The Propeller's Internal Clock Frequency

WaffenGeistWaffenGeist Posts: 5
edited 2011-12-30 21:02 in Propeller 1
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.

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-12-29 16:59
    WaffenGeist,

    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
  • WaffenGeistWaffenGeist Posts: 5
    edited 2011-12-29 19:06
    WaffenGeist,

    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 Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-12-29 23:04
    Now, how do I modify the Unsolved to Solved in the thread title ?
    Edit your original post, click Go Advanced, and select SOLVED from the drop-down box next to the title.

    -Phil
  • Cluso99Cluso99 Posts: 18,069
    edited 2011-12-30 01:55
    WaffenGeist: Welcome to the fabulous world of the Prop. We all agree, Chip is a true genious to create such a great chip (pun intended).
  • Heater.Heater. Posts: 21,230
    edited 2011-12-30 04:24
    WaffenGeist,

    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.
  • WaffenGeistWaffenGeist Posts: 5
    edited 2011-12-30 09:25
    a
    Heater. wrote: »
    WaffenGeist,

    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 Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-12-30 09:37
    The catch to that method is that both cogs use the same clock. Any errors in the sending cog would be offset exactly by the same errors in the receiving cog, and the results would be completely deterministic.

    -Phil
  • Heater.Heater. Posts: 21,230
    edited 2011-12-30 11:47
    Exactly. Unless you have yet another hardware oscillator out there that runs independently you won't get any randomness that way. But then there are better ways to get real random numbers in hardware than that, like making use of the noise from a zenner diodes or transistors in avalanche mode.

    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
  • JLockeJLocke Posts: 354
    edited 2011-12-30 21:02
    Yes, please post it. Never know when I'll want to go random.
Sign In or Register to comment.