Is it possible to automatically detect 6Mhz crystal as well as 5/10?

Peter JakackiPeter Jakacki Posts: 9,204
edited 2017-07-30 - 02:26:10 in Propeller 1
Many years ago our famous Phil Pilgrim wrote a very tricky and useful routine to detect whether a Prop was running a 5Mhz or 10Mhz crystal. Well, it couldn't really tell if it were 5Mhz exactly but it could tell the whether it was in that range. rather than double.

Now perhaps this question is more for Phil but I throw it open for anyone to be able to comment but is it possible to detect 5/6/10 Mhz crystals automatically? I think the difference between 5 and 6 and the variations in silicon would preclude being able to detect this just as it would be almost impossible to detect 6.5Mhz too so I will say that this is IMPOSSIBLE! :)

Any takers?

I may however use baud-rate detection from ANSI terminal responses to reset and lock in the exact crystal frequency as a workaround and make sure all code references this for timing.

Phil's code that I use in Tachyon:
{
CLKSET
?(c) Copyright 2009 Philip C. Pilgrim (propeller@phipi.com)
see end of file for terms of use.

This object determines whether a 5MHz or 10MHz crystal is
being used and sets the PLL accordingly for 80MHz operation.
The main program should use the following settings:
  _clkmode      = xtal1 + pll8x
  _xinfreq      = 10_000_000
}
              org       _RUNMOD

_setpll       movi      ctra,#%0_00001_011      'Set ctra for pll on no pin at x1.
              movi      frqa,#%0100_0000_0      'Set frqa for clk / 4 (= 20MHz w/ 10MHz crystal, i.e. too high).
              add       pllx,cnt                'Give PLL time to lock (if it can) and stabilize.
              waitcnt   pllx,#0
              movi      vcfg,#$40               'Configure video for discrete pins, but no pins enabled.
              mov       vscl,#$10               'Set for 16 clocks per frame.
              waitvid   0,0                     'Wait once to clear time.
              neg       pllx,cnt                'Read -cnt.
              waitvid   0,0                     'Wait 16 pll clocks = 64 processor clks.
              add       pllx,cnt                'Compute elapsed time.
              cmp       pllx,#$40 wz            'Is it really 64 clocks?
        if_z  mov       pllx,#$6f               '  Yes: Crystal is 5MHz. Set clock mode to XTAL1 and PLL16X.
        if_z  clkset    pllx
        if_z  wrbyte    $-2, #4                 'update clkmode location
            jmp       unext

pllx          long      $1_0000                 '65536 clks for pll to stabilize.

Comments

  • How automatically do you mean? Can I use two passives on a single I/O pin to determine the clock frequency?
  • How automatically do you mean? Can I use two passives on a single I/O pin to determine the clock frequency?

    This would have to be without external components so that just like Phil's original code it could simply just work on any Prop system.

    I have thought about using characteristics of the EEPROM perhaps but that is not precise enough but I suppose a small cap on the SCL line in conjunction with the pullup might provide some kind of information assuming that normal I2C activity uses push-pull SCL so that a small cap shouldn't be a problem. Or maybe a series resistor with the cap is worthwhile exploring so that it doesn't interfere with passive clocking.

    However this would always require a hardware mod in which case it is just as easy to specify a clock frequency.

  • I did this Peter. There is a thread here somewhere. I was able to also detect 6.5MHz too plus the doubles. However I wasn't totally confident so I asked for some extra help to verify but didn't get many takers so I never included the code in my OS.

    I am out ATM so cannot search for the thread. You gave me Phil's code for the pllx88 versions.
  • Thanks rosco.
Sign In or Register to comment.