Shop OBEX P1 Docs P2 Docs Learn Events
Accessory Boards - Page 2 — Parallax Forums

Accessory Boards

24

Comments

  • Here is the Game of Life in Spin2 using my charlieplexing engine. This brought up an interesting problem -- I am using the Spin1 ? LFSR operator and intializing it from CNT. Is there a way to access the P2's superior GETRND function from Spin2?
  • localroger wrote: »
    Here is the Game of Life in Spin2 using my charlieplexing engine. This brought up an interesting problem -- I am using the Spin1 ? LFSR operator and intializing it from CNT. Is there a way to access the P2's superior GETRND function from Spin2?
    pub random : r
      asm
        getrnd r
      endasm
    
  • Although it's a good question as to whether ? should continue to use the LFSR on P2, or if it should just be changed to use GETRND. I think changing it makes sense, but it might break programs that depend on particular properties of the Spin1 ? operator.
  • Some applications require the ability to reseed the LFSR and repeat the same sequence; it's also bidirectional. GETRND is continuously updated so it's a different animal. I think it should have a Spin keyword though instead of relying on inline asm. Also, I could have probably figured out that trick myself if there was a summary anywhere of what you can and can't do in inline asm.
  • ElectrodudeElectrodude Posts: 1,614
    edited 2019-02-07 21:41
    When used as a unary prefix ?x or suffix x? operator, it should use the LFSR. It should use GETRND if you use it as a nullary operator (i.e. terminal symbol), i.e.
    x := ?  ' GETRND x
    
  • Yes, there's never enough documentation :(. I've tried to update a little bit, so here's the newer version. Please let me know what's unclear or how it could be improved; I'm a little too close to the compiler sometimes to know what's obvious and not obvious.
    fastspin accepts inline assembly in `PUB` and `PRI` sections. Inline assembly starts with `asm` and ends with `endasm`. The inline assembly is still somewhat limited; the only operands permitted are immediate values, registers, local variables (including parameters and result values) of the containing function, or labels of that function. (Spin doesn't support goto and labels, but you can define labels in `asm` blocks and jump to them from other `asm` blocks that are in the same function.)

    Branching inside the function should work, but trying to return from it or to otherwise jump outside the function will almost certainly cause you to come to grief, even if the compiler allows it. Calling subroutines is also not permitted.

    If you need temporary variables inside inline assembly, declare them as locals in the enclosing function.

    All non-branch instructions should work properly in inline assembly, as long as the operands satisfy the constraints above. Conditional execution is allowed.

    Example:
    PUB waitcnt2(newcnt, incr)
      asm
        waitcnt newcnt, incr
      endasm
      return newcnt
    
    waits until CNT reaches "newcnt", and returns "newcnt + incr".

    Note that unlike most Spin blocks, the `asm` block has to end with `endasm`. This is because indentation is not significant inside the assembly code. For example, labels typically start at the leftmost margin.
  • localrogerlocalroger Posts: 3,451
    edited 2019-02-08 00:27
    Thanks ersmith, that helps a LOT. Am I understanding correctly that you can basically use Spin2 function local variables but not VAR declared longs for s and d in inline asm instructions? And what exactly is meant by "registers?"
  • localroger wrote: »
    Am I understanding correctly that you can basically use Spin2 function local variables but not VAR declared longs for s and d in inline asm instructions?
    Yes, that is correct.
    And what exactly is meant by "registers?"

    I should have clarified that to be "hardware registers", such as INA and OUTA.
  • Thanks ersmith that opens up a ton of possibilities. I am really intent on getting up to speed on P2 in anticipation of the respin and actual sellable product, but much of the knowledge is buried in thousand post threads from the FPGA days and those of us who either bowed out after the P2 Hot fiasco or who couldn't even afford FPGA emulation are kind of lost. I've got the two Windows GUI's that use FastSpin as their compiler engine running but there are a lot of other paths; I got the USB test images from the other thread but they don't compile and I have no idea why or how to fix them. I really think that somewhere there is probably a person who could gather all this information together for us n00bs in a few days and at least provide pointers to the most important stuff, but that hasn't been done and it needs to be done badly. Parallax went out on a limb to make this window for those of us (the KSR Mars trilogy First Hundred?) who could blow a few hundred bucks to have real silicon in our hands and figure out what it can do. But while I figured out the charlieplexing thing that's not really figuring out P2. OUTB was news to me and I kind of blew such an obvioius thing as that on my first stab at a demo. Somebody really needs to do a rundown for us P1 users as to what is new, different, better, and deprecated in P2 so we can get to work.
  • ke4pjwke4pjw Posts: 1,065
    edited 2019-02-08 04:15
    iseries wrote: »
    Rather then spend $10 on an expansion board I decided to do the $1 DIY board instead.

    Now if only the P2 had fonts in ROM so I could print some letters on the OLED display.

    Mike

    I have been working on getting this OLED to work for weeks with my P1 code to no avail on the P2 with fastspin. Did you get it working?

    PS: See link below for a font.
  • Yes and no. I just got it working with code I put together on the P1. The library I used was massive and getting some of it to compile on the P2 was not working. I had to build some of the base functions on the P2. It was my first attempt at porting code over from the P1.

    All the code is in C so I don't know what your looking for but I do have this working on the P1. I also just figured out that it does not work well with 3.3v and only works properly with 5V. The docks says it works down to 3.3v but not reliably.

    If you want help start another thread on this and maybe we can get this going. Also I used p2gcc.

    Mike

  • localrogerlocalroger Posts: 3,451
    edited 2019-02-08 16:26
    Improved Spin2 Game of Life!
    --works on any basepin
    --uses P2 PRNG to initialize the board
    --P57 blinks during marquee, on during game
    --game ends immediately on extinction
    --P58 blinks when a snap is taken for oscillator detection
    --P59 comes on if an oscillator detected, and 10 more ticks are displayed
    --Snaps are taken at ever longer intervals in case of a long-period oscillator
    --Two long compares are used for extinction/snap detection. On P1
    this would have required the arrays to be long-aligned.
  • localroger wrote: »
    Improved Spin2 Game of Life!
    --works on any basepin
    --uses P2 PRNG to initialize the board
    --P57 blinks during marquee, on during game
    --game ends immediately on extinction
    --P58 blinks when a snap is taken for oscillator detection
    --P59 comes on if an oscillator detected, and 10 more ticks are displayed
    --Snaps are taken at ever longer intervals in case of a long-period oscillator
    --Two long compares are used for extinction/snap detection. On P1
    this would have required the arrays to be long-aligned.

    Sounds good. Have you posted this revision?
    Thanks
    Tom
  • Huh. Added the file to the post. Somehow it got dropped when I tried to update it.
  • PublisonPublison Posts: 12,366
    edited 2019-02-08 16:56
    Loading Life demo seems to hang at
    clkset(oscmode, freq)
    

    Pnut v33

    "Expected Instruction or Variable"
  • Both of the dev systems I've tried use fastspin. Does Pnut even do spin? I thought it was an assembler.
  • I think that's the issue too. Try spin2gui - that definately recognises the clkset macro.

  • My bad. I was in Pnut for something else and just pasted in there.
  • Thanks for posting. It compiles & runs using spin2gui.

    I added a couple of lines to print the purposes of pins p57, 58, 59 on the terminal.

    Added under CON
    baud    = 230400
    
    Added
    OBJ
        ser: "PrintfSerial"
    

    Added to beginning of pub main
      clkset(OSCMODE, freq)
      ser.start(baud)
    
     ser.printf( "%n P57 blinks during marquee, on during game%n")
     ser.printf( "game ends immediately on extinction%n %n")
     ser.printf( "P58 blinks when a snap is taken for oscillator detection%n %n")
     ser.printf( "P59 comes on if an oscillator detected, and 10 more ticks are displayed%n %n")
     ser.printf( "Snaps are taken at ever longer intervals in case of a long-period oscillator%n %n")
    
    
    Note I'm not sure if OBJ ser: "PrintfSerial" and the ser.printf commands can be added to other spin2 compilers.

    Tom
  • @localroger Vey Nice!
  • @twm47099, couple of noob questions about your adds above.

    Where did the 230400 baud rate come from? If I add your changes, I just get a bunch of spaces on the Prop Output screen?

    Where can I find documentation on PrintfSerial?

    AdThanksVance, tom crawford
  • I use the spin2gui IDE. The terminal baud is set in the configuration, run command. In the old versions of spin2gui the baud was set -b 2000000. But in the latest versions it is set to -b 230400. So I set that in the program. The important thing is to have them both the same.

    PrintfSerial.spin is in the spin2gui\lib folder. An example is in spin2gui\samples\fibo.spin.

    Hope this helps
    Tom
  • Thanks majorly.
  • Was just messing around with the charlieplesxing. Will ad the random number later. Was fun.
  • Can the spin2gui baud rate be changed on the fly??
  • pilot0315 wrote: »
    Can the spin2gui baud rate be changed on the fly??

    Not "on the fly" exactly, but it's specified in the "Run Command" section of the "Command > Configure commands..." menu option. Just change all the "23400" to whatever baud rate you want.
  • ersmithersmith Posts: 5,900
    edited 2019-02-13 01:54
    Based on dgately's and localroger's LED matrix demos above, here are some demos to display scrolling text on the LED matrix.

    The BASIC version is interesting because it shows how to use "open ... as #2" and "print #2,..." to print data to a driver defined in another object (the charlieplex LED matrix object in this case). The heart of it is:
    ' import the Spin2 charlieplex driver
    dim c as class using "charlieplex_text.spin2"
    
    c.start() ' start the driver running in its cog
    
    ' open a handle for talking to the driver
    ' note that we cannot receive on this device, so the receive pointer is nil
    open SendRecvDevice(@c.tx, nil, @c.stop) as #2
    
    print #2, "cycle counter="; getcnt()
    

    Edit: updated the source code to work around a bug noted below.
  • ersmith wrote: »
    Based on dgately's and localroger's LED matrix demos above, here are some demos to display scrolling text on the LED matrix.
    Spin version builds and runs, but getting this error when building demo.bas... I have the latest fastspin, running on macOS, anything I'm missing?
    $ fastspin
    Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
    Version 3.9.20-beta-0b467e0d Compiled on: Feb 12 2019
    
    $ fastspin -2 demo.bas 
    Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
    Version 3.9.20-beta-0b467e0d Compiled on: Feb 12 2019
    demo.bas
    |-charlieplex_text.spin2
    demo.p2asm
    demo.p2asm(117) error: Unknown symbol __system__cogid
    demo.p2asm(117) error: Unknown symbol __system__cogid
    Done.
    

    dgately
  • ersmithersmith Posts: 5,900
    edited 2019-02-12 21:14
    dgately wrote: »
    Spin version builds and runs, but getting this error when building demo.bas... I have the latest fastspin, running on macOS, anything I'm missing?
    demo.p2asm(117) error: Unknown symbol __system__cogid
    demo.p2asm(117) error: Unknown symbol __system__cogid
    Done.
    

    Oh, that's very bizarre! It looks like there's a bug in the optimizer. It turns out I tested that program with optimization turned off in spin2gui (-O0). It works in that case, but complains about the symbol if optimization is on.

    The fix is pretty easy though: just add parentheses after the call to cogid on line 20 of demo.bas, so that it reads:
        cogstop(cogid())
    

    I'll update the original .zip.

    Thanks,
    Eric
  • Eric,

    The "charlieplex_text.spin2" isn't in the zip file.
Sign In or Register to comment.