Shop OBEX P1 Docs P2 Docs Learn Events
Spin & PropellerForth observations — Parallax Forums

Spin & PropellerForth observations

Peter JakackiPeter Jakacki Posts: 10,193
edited 2006-12-01 02:01 in Propeller 1
I have just gotten back into playing with the Propeller and PropellerForth and would like to share some observations I have made.
Working with Spin is very easy but not very interactive but I also found that the Spin interpreter is very slow especially when accessing port pins in a bit-bashing fashion. This is what led me to consider writing a Forth for the Propeller but as a binary was available from Cliff I have been doing some tests with it.

For the purposes of ascertaining whether I could write a driver in high-level code I must know how well the code performs at the bit-bashing level. A simple way to test this is to toggle a port pin and see how fast it runs. If I toggle a pin at maximum rate from Spin the best that I get is a dismal 7.375kHz signal. Here is the code:-

{{Output.spin

Toggles Pin without delay}}

CON
  Pin   = 0                 { I/O pin to toggle on/off }

PUB Toggle
''Toggle Pin forever - output freq is 7.375kHz

  dira[noparse][[/noparse]Pin]~~                'Set I/O pin to output direction
  repeat                     'Repeat following endlessly
    !outa[noparse][[/noparse]Pin]               '  Toggle I/O Pin




From Cliff's PropellerForth I have written three different routines with interesting results as the one that I thought would be most efficient is not.

HEX

: TOGGLE1 \ 75.76kHz
 DIRA L@ 1 OR DIRA L!
 OUTA L@ DUP 1 OR SWAP 1 INVERTAND OUTA
 BEGIN 2DUP L! ROT SWAP AGAIN ;


: TOGGLE2 \ 86.2kHz
 DIRA L@ 1 OR DIRA L!
 BEGIN
    OUTA L@ 1 OR OUTA L!
    OUTA L@ 1 INVERTAND OUTA L!
 AGAIN ;

: TOGGLE3 \ 172.4kHz
 DIRA L@ 1 OR DIRA L!
 OUTA L@ DUP 1 OR SWAP 1 INVERTAND
 BEGIN OVER OUTA L! DUP OUTA L! AGAIN ;





As you can see the TOGGLE3 routine achieves 172.4kHz which is certainly a lot faster than the Spin implementation but still has a lot of room for improvement. This however shows that it can be more efficient to write a bit-bashing driver in Forth than in Spin although of course assembler wins hands-down.

To achieve higher-speed I may write my own version of Forth anyway but I think even so that when Cliff gets his Forth a little more workable that it is something that is worth looking at.

Cliff, thanks for the play with Forth, however the serial driver is woeful, it doesn't matter how many zillion tasks could be run, it has to be loaded with code in the first place, something that requires very long delays between characters and does not always work reliably. Can you update this as a priority? TIA.


*Peter*

Comments

  • Cliff L. BiffleCliff L. Biffle Posts: 206
    edited 2006-11-24 04:26
    Peter,

    Glad to see someone's actually working with PropellerForth!

    Version 3 may be the fastest because it sticks almost entirely to primitive ops (no colon definitions called). In the current PropellerForth, 2DUP is a colon definition, implemented as OVER OVER, because I'm awfully short on Cog RAM.

    Colon definitions aren't that much slower, but the overall number of words executed is lower in versions 2 and 3, with 3 the lowest.

    As I've mentioned in some other threads, I'm working on the serial driver now. I have a prototype of the Forth driver working, but my day job's been dampening my hacking speed. The current driver hasn't been holding me back, because I have the sources and can just cross-compile. smile.gif (The sources will be available soon, and then perhaps you can optimize this code instead of writing your own. Though I certainly understand the desire to write your own...it's why I'm doing this.)

    Edit: It may seem strange that I worked on (and released) the multi-tasking code before the serial driver. There's a good reason for it: without UART interrupts, the only reliable way to do full-duplex buffered serial communications is to spin it off into a separate Cog. The tasking code had to be stable to support this.

    Post Edited (Cliff L. Biffle) : 11/24/2006 4:32:04 AM GMT
  • OzStampOzStamp Posts: 377
    edited 2006-11-24 05:17
    run the thing at 80 mhz peter please spin executes alot faster than what your quoting.

    you have it running at the default 12mhz use xtal1 pll16 freq 5mhz setting

    cheers
    Ronald Nollet
  • OzStampOzStamp Posts: 377
    edited 2006-11-24 05:24
    Try these settings Peter.
    CON
    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000

    You should get much better results

    Ronald Nollet Australia
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2006-11-24 05:55
    You're right Ron, I hadn't set the pll up and it does run a lot faster. By a lot faster I mean it runs at 45.48kHz which is still very shy of what this early beta version of PropellerForth does.

    See, I need to play with this chip a bit more. (There is no such thing as work when it comes to processors, they do the work, we just poke them and prod them)

    *Peter*
  • Cliff L. BiffleCliff L. Biffle Posts: 206
    edited 2006-11-24 06:48
    I didn't think SPIN was that slow; I just logged back onto the board to question your numbers, and someone's taken care of it. smile.gif

    PropellerForth currently fixes the clock speed at 80MHz, assuming a 5MHz clock. This is a limitation in the assembler.
  • mike101videomike101video Posts: 43
    edited 2006-11-30 19:21
    Cliff,
    Has the "day job" stopped your work on FORTH? smile.gif

    I'm really looking forward to getting my hands on the source - so I build an application, with out streaming the text.

    Really appreciate the job you are doing here.

    Mike
  • Cliff L. BiffleCliff L. Biffle Posts: 206
    edited 2006-11-30 20:22
    mike101video said...
    Cliff,
    Has the "day job" stopped your work on FORTH?

    Very nearly. Well, and there was a holiday in there too, in the states.

    I've been trying to get better support for the Hydra, which uses a different crystal and has required changes to my assembler. I hope to get the sources up soon, but I'm short on time.
  • EdKirkEdKirk Posts: 27
    edited 2006-11-30 22:51
    Hi,

    I have downloaded Cliff Biffle's PropellerForth and received a .binary file.

    How do I get the propeller .spin loader to accept it?

    EdKirkh
    EdK@wi.rr.com
  • Gerry KeelyGerry Keely Posts: 75
    edited 2006-11-30 23:03
    Double click on the binary file.Object Info window opens.Hit "Load EEPROM".

    Gerry
  • EdKirkEdKirk Posts: 27
    edited 2006-12-01 00:48
    Hi,

    And if I do succeed in loading the PropellerForth.binary, how do I interact with it?

    In other words do I use the Spin Editor or must I go to one of the VGA thingies?

    If so do I need another monitor program?

    EdKirk
  • SSteveSSteve Posts: 808
    edited 2006-12-01 00:53
    You communicate with it through a terminal emulator program. It communicates at 19200 8N1. There's some discussion of terminal software in one of the the other PropellerForth threads.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows

    links:
    My band's website
    Our album on the iTunes Music Store
  • EdKirkEdKirk Posts: 27
    edited 2006-12-01 02:01
    Gerry Keely said...

    Double click on the binary file.Object Info window opens.Hit "Load EEPROM".

    Gerry

    Thanks Gerry,

    That seems to load my PropStick!
    Good.
    Now, How do I interact with it?

    EdKirk
Sign In or Register to comment.