Shop OBEX P1 Docs P2 Docs Learn Events
Spin - shortest duraition for pause — Parallax Forums

Spin - shortest duraition for pause

g3cwig3cwi Posts: 262
edited 2012-02-11 10:56 in Propeller 1
Hi all

Making good progress now with my little project. I have yet to receive the DDS but am hopeful that it might work first time.

I have been experimenting with delays to run my data clock. Using the code:
Duration   := 200
 Duration   := clkfreq/5_000_000*Duration   'Duration in 200ns steps

Using this expression I hit a minimum of about 40us below which the code locks up.

1) Is this due to the 381 cycle delay for reading cnt?

2) Is PASM the only way to go faster? (I have to send data so it's not just a clock that I need)

Must say that I am finding my Propellor programming very interesting. It's nearly as absorbing as my network analyser!

Cheers

Richard

Comments

  • JonnyMacJonnyMac Posts: 9,197
    edited 2012-02-05 07:46
    You have an inline calculation that is also consuming valuable procesor cycles. Some time back I snagged a clever bit of code that was posted here that is useful when you're not going to be changing clock frequency.
    con
    
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000                                          ' use 5MHz crystal
    ' _xinfreq = 6_250_000                                          ' use 6.25MHz crystal
    
      CLK_FREQ = ((_clkmode - xtal1) >> 6) * _xinfreq
      MS_001   = CLK_FREQ / 1_000
      US_001   = CLK_FREQ / 1_000_000
    


    I use the CLK_FREQ constant (and other calculated constants) in my programs -- this might help you speed things up a bit. Ultimately, though, for sheer speed PASM is going to be the way to go.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2012-02-05 08:42
    JonnyMac wrote: »
    ... Some time back I snagged a clever bit of code that was posted here that is useful when you're not going to be changing clock frequency.....

    That's very clever. Jon, do you have any idea about how much time using these constants saves vs. having an in-line calculation?

    Thanks.
  • g3cwig3cwi Posts: 262
    edited 2012-02-05 09:36
    Thanks Jon:

    Do I use these constants in the form:
    Repeat
      Dosomething
      Waitcnt (us_001 + cnt)        'Wait 1us
      Dosomethingelse
    
  • JonnyMacJonnyMac Posts: 9,197
    edited 2012-02-11 10:56
    You can't wait 1us in Spin as each instruction takes about 5us. Figure the shortest duration you're going to get is about 10us and you'll be safe, but you'll never be precise at that resolution using and interpreted language like Spin. If you port your code to PASM, though, then you can easily achieve sub-microsecond precision.
Sign In or Register to comment.