Shop OBEX P1 Docs P2 Docs Learn Events
Why my 5Mhz crystal is slightly faster than 5Mhz? — Parallax Forums

Why my 5Mhz crystal is slightly faster than 5Mhz?

william chanwilliam chan Posts: 1,326
edited 2008-09-02 07:03 in Propeller 1
I saw in the Info Dialog (see attached) that my frequency is 5,000,064 Hz.
Did the Propeller sample this frequency and relay this info to the IDE?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
335 x 511 - 33K

Comments

  • Ron SutcliffeRon Sutcliffe Posts: 420
    edited 2008-08-31 14:09
    William

    Just check you source code again.

    CON

    · _CLKMODE = XTAL1 + PLL16X
    · _XINFREQ = 5_000_000

    You sure its not 5_000_064

    Ron
  • Ron SutcliffeRon Sutcliffe Posts: 420
    edited 2008-08-31 14:40
    I should have added that you don't even need to have the Prop connected to your PC to compile >--info

    Regards

    Ron
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-08-31 16:28
    William,

    I'll bet the first few lines of your program look like this:

    CON
    
      _clkmode      = xtal1
      _xinfreq      = 5_000_000  + pll1x
    
    
    


    Am I right? I think you know how to fix it! smile.gif

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
  • william chanwilliam chan Posts: 1,326
    edited 2008-08-31 16:29
    Here's my code

    CON

    _clkmode = xtal1
    _xinfreq = 5_000_000 + pll1x


    but the View Info window still shows 5,000,064 Hz.
    What gives?

    I need the clock frequency to be as accurate as possible because I plan to run a RTC on it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.fd.com.my
    www.mercedes.com.my
  • ColeyColey Posts: 1,110
    edited 2008-08-31 16:32
    william, look again at what Phil is saying.....

    _xinfreq = 5_000_000

    Regards,

    Coley

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    PropGFX Forums - The home of the Hybrid Development System and PropGFX Lite
  • Mike GreenMike Green Posts: 23,101
    edited 2008-08-31 16:33
    The "pll1x" has a value of 64 and you're adding it to your crystal frequency.
    It should be added to "_clkmode" instead as in: "_clkmode = xtal1 + pll1x"
  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-08-31 16:34
    William... your xinfreq has pll1x added... This should be added to clkmode instead like phil said. Otherwise, you are adding the literal value of pll1x(64) to your xinfreq.
  • william chanwilliam chan Posts: 1,326
    edited 2008-08-31 16:40
    Ok.

    I get it now.
    Sorry for the trouble.

    If we set the xinfreq slightly more than 5Mhz, will it force the crystal to oscillate faster?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.fd.com.my
    www.mercedes.com.my

    Post Edited (william chan) : 9/1/2008 1:59:57 AM GMT
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-08-31 16:42
    No, XINFREQ is a mnemonic to assist with calculating time values, it has no physical effect on the functionality of the Propeller.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.

    Post Edited (Paul Baker (Parallax)) : 8/31/2008 5:45:09 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2008-08-31 17:01
    The Propeller has no way to actually know the crystal frequency.
    The _XINFREQ and _CLKMODE definitions allow you to tell it what the crystal frequency is supposed to be
    so software like I/O drivers can adjust for different clock frequencies. The bootstrap loader uses the CLKMODE
    information to set the PLL multiplier and the system clock mode after loading and before the Spin interpreter
    starts up.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-08-31 19:47
    William,

    In regards to your intended use as an RTC, I measured the actual frequency of the crystal on my Demo board via the following program:

    CON
    
      _clkmode      = xtal1 + pll1x
      _xinfreq      = 5_000_000 
    
    PUB Start
    
      ctra := %00100 << 26
      frqa := $1000_0000
      dira := 1
      repeat  
    
    
    


    With an exact 5.0000000 Mhz oscillation, the output should be exactly 312.5000Khz. In fact, it was 312.4994 KHz:

    attachment.php?attachmentid=55450

    This corresponds to an actual crystal frequency of 4.9999904 Mhz, an error of about -2ppm; in other words, a loss of one second every 5½ days. This may vary with temperature. (Digital watches can hold to one second a month, because they are worn on the arm, which forms a steady 98.6°F heatsink.)

    -Phil

    Addendum: The above figures are from a cold start. Now that the unit has been running for awhile, I see the output has drifted to 312.4992 KHz (4.9999872 MHz crystal). I'll leave it on for a few hours and report back...

    Update: It's about 4½ hours later now, and my shop temperature is up to 80°F. The frequency meter says 312.4981 KHz (4.9999696 MHz crystal) That's -5.76 ppm or a loss of ½ second a day.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!

    Post Edited (Phil Pilgrim (PhiPi)) : 9/1/2008 12:16:50 AM GMT
    600 x 270 - 40K
  • jazzedjazzed Posts: 11,803
    edited 2008-08-31 20:20
    Generally speaking all oscillators and crystals are rated by frequency +/- X PPM. Phil's example is within 25PPM.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve
  • BradCBradC Posts: 2,601
    edited 2008-08-31 21:49
    I have a software based RTC in my A/C thermostat. It's been up now for 65 days and I tend to see about 1/4 to 1/2 a second per day drift on average.
    This is a stock Proto board.

    I've got a board with a DS1307 on it, but I've not accurately checked that yet. (The thermostat RTC is calibrated against my NTP daemon)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Pull my finger!
  • Ken PetersonKen Peterson Posts: 806
    edited 2008-08-31 21:52
    You can put an ethernet interface on the Prop and use RFC-1305 (Internet time protocol) to set the time every day.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"I have always wished that my computer would be as easy to use as my telephone.· My wish has come true.· I no longer know how to use my telephone."

    - Bjarne Stroustrup
  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-08-31 22:19
    Wow, what crystal are you using, Phil? I've tried using the prop as a RTC and with the crystal supplied with the education kit, I was losing about 1 second every 4 hours... Not too good.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-08-31 23:39
    Permanent RTC installations should be done on PCB, not left in breadboard. The breadbard has significant capacitance which can effect the performance of the crystal. Typically not enough to keep it from running, but enough to slightly skew the frequency.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-09-01 00:21
    Philldapill,

    It's the crystal that came with the Demo Board. The timing continues to drift, BTW. See my update above.

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
  • william chanwilliam chan Posts: 1,326
    edited 2008-09-01 01:54
    I guess once you have checked that the crystal is a bit slow, you can adjust by setting

    _xinfreq = 4_999_997

    or something lower to compensate for the slowness, right?


    On my crystal the marking is 5.00ECSR
    Does that mean that if we look for a crystal with more zeroes after the 5.00 the accuracy will increase?
    How many PPM accuracy is the demo board crystal?
    Can a crystal with 18pF capacitance be used?

    Phil,

    Maybe the accuracy of the scope is also drifting.... smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.fd.com.my
    www.mercedes.com.my

    Post Edited (william chan) : 9/1/2008 2:04:59 AM GMT
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-09-01 02:28
    william chan said...
    Maybe the accuracy of the scope is also drifting....
    That's certainly possible!

    What you're suggesting for adjusting the _xinfreq is not at all unreasonable. I actually did that with a race timer I built years ago that used a PIC. What you need to do is observe the accuracy over several days, assuming the nominal 5.000000 MHz. Then you can adjust for the gain or loss in time accordingly. Be aware, though, that frequency is still temperature-dependent. If temperature is expected to vary a lot, you may need to add a temperature sensor for on-the-fly corrections. Another option is to use an external TCXO (temperature-compensated crystal oscillator) or crystal oven, if absolute accuracy is paramount.

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
  • Sleazy - GSleazy - G Posts: 79
    edited 2008-09-01 05:22
    ·· You were saying you waited days to calibrate the crystal after a long control run. I wonder if somehow the crystal could be "tweaked" in-code, where the prop can stay on for a few days, and fix itself.· This is pretty doable.
    That way you'd get a super-calibrated prop which operates according to its unique·extended dynamic response of·CNT.

    I guess you could consider this calibrating the calibrator
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-09-01 05:47
    A much quicker way to do the calibration — and do it automatically — would be with the use of a GPS that provides pulse-per-second output. I didn't have that luxury when I did it for the race timer, so I had to use a more extended time period to reduce the effects of uncertainty in start and stop times.

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
  • hippyhippy Posts: 1,981
    edited 2008-09-02 00:46
    Phil Pilgrim (PhiPi) said...
    A much quicker way to do the calibration — and do it automatically — would be with the use of a GPS that provides pulse-per-second output. I didn't have that luxury when I did it for the race timer, so I had to use a more extended time period to reduce the effects of uncertainty in start and stop times.

    Or use mains frequency as a timebase to compare to if mains powered. I don't know how it is in the rest of the world but the UK grid reportedly keeps very good time over a medium and long period even though it ( deliberately ) changes in the short term.

    You can watch UK mains frequency vary in real time here ...

    www.dynamicdemand.co.uk/grid.htm

    If frequency drops they run it a bit faster later, and vice-versa if it gains. That way mains-synched clocks should be fairly accurate. Conspiracy theorists would say they run the frequency down to get a longer working day then run it fast overnight smile.gif
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-09-02 02:06
    hippy said...
    Conspiracy theorists would say they run the frequency down to get a longer working day then run it fast overnight
    LOL! I actually built a clock once, as a gag gift for a friend, that works like that. I called it the "Flex-O-Clock". I took a battery-powered crystal-controlled clock movement and replaced the 32.768 KHz oscillator that drove the clockworks through a divider, with a PIC that used the same crystal. One could program it with a PC to speed up and slow down during certain periods, but still maintain the correct number of "ticks" over a 24-hour day. I had even thought about marketing it to unions and/or management types for employee lunchrooms (playing both sides of the fence, of course, like any good capitalist).

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!

    Post Edited (Phil Pilgrim (PhiPi)) : 9/2/2008 7:13:38 AM GMT
  • william chanwilliam chan Posts: 1,326
    edited 2008-09-02 07:03
    Is the scope crystal more accurate than our 5Mhz crystal?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.fd.com.my
    www.mercedes.com.my
Sign In or Register to comment.