Shop OBEX P1 Docs P2 Docs Learn Events
P2 Edge Rev D at 19.2 — Parallax Forums

P2 Edge Rev D at 19.2

I use Flexprop for all my compiles and I don't set the clock frequency in my code. I expect that is set ahead of time in the compiler.

So the default clock for Flexprop is 160Mhz which I tweak to 200Mhz.

With a clock of 19.2 instead of 20Mhz it's not possible to run at either of those clocks speeds. The closest would be 163.2 or 201.6.

So how would I tell flexprop that I have a 19.2 instead of a 20Mhz crystal so that I can get one of those frequencies otherwise my compile will run at 192Mhz instead of 200Mhz or 153.6Mhz instead of 160Mhz.

I could build a custom version with that number set but then I would need to fix that every time I switch boards and then I need to have the boards labeled otherwise It's not going to work.

Mike

«1

Comments

  • In your code you can define a constant _xtlfreq which gives the crystal frequency:

    enum { _xtlfreq = 19'200'000 };  // do this for C
    const _xtlfreq = 19_200_000  ' do this for BASIC
    CON _xtlfreq = 19_200_000 ' and this for Spin
    

    There isn't any way to change it in the GUI or from the command line (yet), I guess it would be useful to have board selection menu that let you define the clock frequency?

  • The P2 clock circuit is actually able to fairly precisely approximate many frequencies that are not direct multiples of the crystal input.

    The crystal frequency can be specified with the _xtlfreq constant. The computed clock mode is adjusted to that.

    Also, I must say that building a custom compiler with a different default clock setup instead of specifying it in the code that it applies to is a really horrible idea.

  • 19.2 MHz * 125 / 12 = 200.0 MHz
    19.2 MHz * 100 / 12 = 160.0 MHz
    19.2 MHz * 50 / 6 = 160.0 MHz
    19.2 MHz * 25 / 3 = 160.0 MHz

  • RaymanRayman Posts: 14,162

    @ersmith said:
    enum { _xtlfreq = 19'200'000 }; // do this for C

    Never heard of this digit seperator as being legal in C.
    Glad you added it. Looked it up and guess part of C++ 14.

  • @Rayman said:

    @ersmith said:
    enum { _xtlfreq = 19'200'000 }; // do this for C

    Never heard of this digit seperator as being legal in C.
    Glad you added it. Looked it up and guess part of C++ 14.

    It's also in C23 now.

  • STM uses cube software where you pick the chip and it generates assembly code that configures all the clocks for that chip.

    Maybe we could have that?

    Mike

  • We have that. You just set _clkfreq and _xtlfreq and it magically does it.

  • evanhevanh Posts: 15,423

    Here's what my typical first few lines of C code always looks like for the Eval Boards. Note the commented _xinfreq. It is there for the Edge Cards since they have an external crystal oscillator rather than a raw crystal. It's not a biggie but _xinfreq turns off the capacitive pin loading via the %CC bits in the HUBSET config word.

    #include <stdint.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <sys/time.h>
    
    enum {
        // _xinfreq = 20_000_000,
        _xtlfreq = 20_000_000,
        _clkfreq = 4_000_000,
    
        MOSI = 16,
        CLK = 17,
        CS = 18,
        MISO = 19,
    
        CPOL = 0,   // 0 or 1 only, used in binary equation
        CPHA = 0,   // 0 or 1 only, used in binary equation
    };
    
  • evanhevanh Posts: 15,423
    edited 2023-04-13 01:44

    So, for an Edge Card, I'd use:

    enum {
        _xinfreq = 20_000_000,
        // _xtlfreq = 20_000_000,
        _clkfreq = 4_000_000,
        ...
    

    or, for these Rev D's,

    enum {
        _xinfreq = 19_200_000,
        // _xtlfreq = 20_000_000,
        _clkfreq = 4_000_000,
        ...
    
  • Ok, now I have to edge cards that look exactly a like how can the program determine what speed it should run at?

    Using the wrong frequency is no biggy until you need to talk serial to some device.

    Mike

  • You can't, there's no way to figure out the oscillator speed in software. You need to know in advance. Which is why 20 MHz is the standard and the 19.2 MHz weirdo Edges are sold off so cheap.

  • VonSzarvasVonSzarvas Posts: 3,339
    edited 2023-04-13 09:47

    more ideas...

    With good eyes or magnifier googles the markings on the oscillator indicate the speed.

    Otherwise... maybe software could do it by talking to something at a known baud ? .... perhaps a little script running at 2Mbaud ping/pongs P2-EC to PC (or visa-versa) for a few bytes to see if it fails ? Wouldn't take many bytes for the comms to go out of sync at a high baud rate.

    OR have a pin input toggling at a known rate (perhaps 1 Hz if you have a GPS device in the system), then count the P2 system clocks between toggles? That should be simpler if you have a know toggle available.

  • How about getting the correct part and replacing it on the board?

    Mike

  • How about getting the correct part and replacing it on the board?

    Might be trivial if we're talking singular quantity of boards fixed in house but might absolutely be a no go when you need to send them somewhere else and then run the tests on these boards to verify the quality of the job.

  • The cost would also be more than the sale price, and the risk to the sensitive part fairly high.

    Instead there was an opportunity to get some low price modules out to users - something many have asked for.

  • evanhevanh Posts: 15,423

    Mike,
    You've now joined the growing community of non-default users. :)

    In reality all the post-revA Edge Cards are non-default given they use oscillator modules. Just this fact doesn't impact the frequency, only the oscillator's power draw goes up when using defaults.

  • evanhevanh Posts: 15,423
    edited 2023-04-13 12:04

    Regarding it being identical looking to a Rev C board - Just hand label it as Rev D so you won't get the two boards confused later.
    EDIT: Err, these are labelled Rev D already. That's a lot of revisions! Okay, hand label it as 19.2 MHz then.

  • VonSzarvasVonSzarvas Posts: 3,339
    edited 2023-04-13 12:33

    @evanh said:
    Regarding it being identical looking to a Rev C board - Just hand label it as Rev D so you won't get the two boards confused later.
    EDIT: Err, these are labelled Rev D already. That's a lot of revisions! Okay, hand label it as 19.2 MHz then.

    RevC only lasted one build as the new power supply IC went from gazillions in stock to 60 week lead overnight ! I believe the purchasing office obtained a couple reels of the new-new part to ensure continuity for RevD :)

    Hand label -- That's what I did too - a cheerful yellow sticker-dot on the P2 chip !

  • Hi
    went to shop to purchase but unable to get a price that includes overseas postage to uk and taxes.
    How do I find that information.
    Dave

  • rosco_pcrosco_pc Posts: 457
    edited 2023-04-13 17:38

    @tritonium said:
    Hi
    went to shop to purchase but unable to get a price that includes overseas postage to uk and taxes.
    How do I find that information.
    Dave

    put it in the cart and do a checkout. As soon as you've provided shipping address the shipping options will be shown. Taxes you will have to pay in the UK when the packages arrives (if it is similar to Sweden you'll pay 25% on total cost including shipping)

    PS I found that the KISS boards from @ManAtWork are a much better value proposition for us in Europe then anything shipped from the States (even this priced down edge board) . Although since you're in the UK that might be different for you.

  • @VonSzarvas said:
    The cost would also be more than the sale price, and the risk to the sensitive part fairly high.

    Instead there was an opportunity to get some low price modules out to users - something many have asked for.

    Is there a source and part number for the device? Should be doable with the right rework station.

  • @"frank freedman" said:
    Is there a source and part number for the device? Should be doable with the right rework station.

    EPSON TG2520SMN 20.0000M-ECGNNM3

  • That was fast, THX!!

  • jmgjmg Posts: 15,156
    edited 2023-04-13 23:28

    @VonSzarvas said:

    Otherwise... maybe software could do it by talking to something at a known baud ? .... perhaps a little script running at 2Mbaud ping/pongs P2-EC to PC (or visa-versa) for a few bytes to see if it fails ? Wouldn't take many bytes for the comms to go out of sync at a high baud rate.

    It would be a good idea to check and report the XTAL freq

    Autobaud can already do that, as in the boot ROM, but that's a little complex.

    Simpler checks are possible by sending 0xff to the P2, and it can report the actual bit duration encoded in the first bit slot, with extended stop bit counts.
    eg I'd reply single bits per character like 1,0,c,a,p,t,u,r,e,v,a,l,u,e - the known leading bits allow the PC side to confirm the info is in-range.

    That single-bit encode is highly tolerant of skews in baud, and would be broad enough to calibrate the RCFAST oscillator.
    Add a two try scheme and it could also calibrate the RCSLOW.

    The limit to calibration here would be UART precision - the cheap FS-USB parts all use USB SOF locking, so they are 0.2% ballpark
    The HS-USB UART parts use crystals, so they are good to ~50ppm ballparks.

    1pps, if you can find it, can calibrate the P2 clock to small fractions of 1 ppm.

    I had a quick look at ROM TAQOZ but my Forth is not great.
    TAQOZ may be able to report XTAL freq, given a download minimal smart-pin-capture-pulse FORTH stub, followed by some dummy stimulus characters ?
    Smart pin mode %10010: Time A-input, X-counts of highs, rises, or edges, set for rises, should capture ~ 10ppm LSB Xtal Freq over > 6 single-rise RX characters at 115200 or ~ 1ppm over > 60 characters (appx 5ms)

    The various P2 loaders have autobaud, and they could report the crystal frequency

  • I'm confused, the order page shows 19.2 with a clock frequency of 180Mhz.

    My clock table shows that's not possible. No multiplier or divider comes up to that value.

    I can get 192Mhz, 182.4Mhz.

    Mike

  • VonSzarvasVonSzarvas Posts: 3,339
    edited 2023-04-17 15:41

    What about...

    19.2 MHz * 150 / 16 = 180.0 MHz

    Edit... or:

    19.2 MHz * 75 / 8 = 180.0 MHz

  • Oops, didn't look at the number of bits. divider is 1 - 64 and multiplier is 1 - 1024.

    My table only did a small set.

    Mike

  • evanhevanh Posts: 15,423

    Mike,
    You might find this pllset() routine handy on occasion for runtime use as well - https://forums.parallax.com/discussion/comment/1546568/#Comment_1546568

  • frank freedmanfrank freedman Posts: 1,982
    edited 2023-04-17 18:37

    This may become a bit of a problem. Parallax, who supplies these for you? The usual suspects are showing > 12 weeks lead time for these oscillators. Need to find a source for a few. Digi-Key, October 10 this year. Mouser September

  • Just got a couple of these bad boys in and decided to put it to the test.

    Test code:

    #include <stdio.h>
    #include <propeller.h>
    #include <smartpins.h>
    
    
    #define PIN 30
    
    int freq;
    
    
    int main(int argc, char** argv)
    {
        freq = (_clkfreq / 1000000) | (20000 << 16);
        _pinstart(PIN, P_OE | P_PWM_SAWTOOTH, freq, 2000);
    
        while (1)
        {
            _pinh(56);
            _waitms(1000);
            _pinl(56);
            _waitms(1000);
        }
    }
    

    This smartpin code generates a pulse ever 20ms to drive some servos.

    Next I took out my handy dandy PropScope to see what it looked like:
    Bad Boy One
    As you can see the pulse drifts off as the pulse repeats because the crystal is a little slow.
    Bad Boy Two
    Now I compiled the program with the correct frequency and everything is right on.

    I guess it's not a pain to switch frequencies.

    Mike

Sign In or Register to comment.