Shop OBEX P1 Docs P2 Docs Learn Events
My first Spin2 Program Fails — Parallax Forums

My first Spin2 Program Fails

I thought that this program would toggle pin 57 at approximately 5 Hz. But the toggle rate is .712Hz.
CON
  freq = 160_000_000
  osmode = $010c3f04

OBJ  
  pins: "Pins.spin2"    

PUB Main
    pins.Low(56) ' Set LED 56 on (visual indicator that code is running)
    dirb[57] := 1
    repeat
        waitcnt(cnt + 16_000_000)
        !outb[57]

I am using SpinEdit 1.0 and fastspin 3.9.14 In SpinEdit I am using single stage loader with load crystal setting of $010c3f04. I stole the freq an osmode values from the test_CONTROL.spin2 program from Parallax.

John Abshier

Comments

  • Hi John,

    I think you may just need a:
    clkset(oscmode, freq)
    
    in your Main method before any other code. The constants freq, osmode you've set don't actually do anything on their own.

    Cheers,
    Jesse
  • CON 'Constants section 
        OSCMODE = $01000EF8
        FREQ = 300_000_000
    
    and
    PUB main
        clkset(OSCMODE, FREQ)
    
    work as expected for me. Of course, my oscmode and freq values are different.

    Mike R.
  • RaymanRayman Posts: 14,646
    edited 2019-01-30 01:50
    yes, without the clkset(), it's stuck at RC 20 MHz...
    Thanks for trying SpinEdit btw...

    Kinda surprised dirb[57] and outb[57] work...
    Maybe it's rigged so anything over 31 goes to the actual pin #...

    Not sure I knew about pins.spin2 either. That looks interesting. Guess it comes with fastspin...
  • Thanks avsa242 and pmrobert. I now remember seeing that line in the gadzillion posts about the P2 I have read.

    Pins.spin2 came with a set of programs for the accessory boards. I thought I got them from the Accessory Set product page https://parallax.com/product/64006-es But I don't see them there. Other programs included the control board, AV board and LED Matrix board. I guess Parallax withdrew them. outa is used for pin < 32 and outb with pin number for pins > 31.

    John Abshier
  • Rayman wrote: »
    yes, without the clkset(), it's stuck at RC 20 MHz...
    Thanks for trying SpinEdit btw...

    Kinda surprised dirb[57] and outb[57] work...
    Maybe it's rigged so anything over 31 goes to the actual pin #...
    No, simpler than that -- just the low 5 bits of the pin number are used, so outb[57] -> outb[(57 & 0x1f)] -> outb[25]. Note that outa[32] will actually access pin 0, and outb[0] will access pin 32, so you do have to be careful when using outa and outb.


  • Thanks avsa242 and pmrobert. I now remember seeing that line in the gadzillion posts about the P2 I have read.

    Pins.spin2 came with a set of programs for the accessory boards. I thought I got them from the Accessory Set product page https://parallax.com/product/64006-es But I don't see them there. Other programs included the control board, AV board and LED Matrix board. I guess Parallax withdrew them. outa is used for pin < 32 and outb with pin number for pins > 31.

    John Abshier

    John
    I believe the examples are at this link.
    https://forums.parallax.com/discussion/comment/1462664/#Comment_1462664

    Tom

  • I'm hoping for spin2 intrinsics which use the DRVL / DRVH and DIRL / DIRH family of asm instructions.
    These are able to directly control one of the 64 pins.

    I realize it isn't too hard to use inline asm for this, but it'd be nice to be part of the language.
  • whicker wrote: »
    I'm hoping for spin2 intrinsics which use the DRVL / DRVH and DIRL / DIRH family of asm instructions.
    These are able to directly control one of the 64 pins.

    I realize it isn't too hard to use inline asm for this, but it'd be nice to be part of the language.

    Actually I am not so sure about this. Currently FastSpin uses some 'system' library for functions like this containing basically methods calling PASM with ASM...ENDASM.

    This makes sense for some PASM instructions, but not for all of them. Having inline PASM is the shortest way using, intrinsics adds call and parameter overhead to it.

    IMHO libraries like pins.spin2 make more sense, you as a programmer can, write, change and use them, and they are not hidden in the compiler, unable for you to change without your program not compiling with somebody elses fastspin.

    So basically I like @ersmith's idea of the system object, being referenced for if some method is called without prefix of ser.xxx tv.xxx and xxx is nowhere else to be found.

    But that system library has to be consistent between fastspin installations, so just eric can add and change there.

    I think rather then hiding intrinsics in a invisible system library it would be better to include visible objects/classes in your source code.

    That does not mean there should be no standard object providing intrinsics, but it should be used sparely.

    anyways,

    Mike
  • ersmithersmith Posts: 6,053
    edited 2019-01-31 02:50
    msrobots wrote: »
    whicker wrote: »
    I'm hoping for spin2 intrinsics which use the DRVL / DRVH and DIRL / DIRH family of asm instructions.
    These are able to directly control one of the 64 pins.

    I realize it isn't too hard to use inline asm for this, but it'd be nice to be part of the language.

    Actually I am not so sure about this. Currently FastSpin uses some 'system' library for functions like this containing basically methods calling PASM with ASM...ENDASM.

    This makes sense for some PASM instructions, but not for all of them. Having inline PASM is the shortest way using, intrinsics adds call and parameter overhead to it.

    Well, fastspin will generally inline small functions, so there's little to no overhead for the intrinsics. But by the same token there's also little to no overhead for user libraries either, if the functions are not too complicated. I think you're right that having a set of standard objects that people can see and modify would be more useful to programmers than having intrinsics built in to the compiler.

    Pins.spin2 seems like a reasonable start. It could easily use the DRVH, DRVL, etc. instructions, e.g.:
    PUB High(pin)
      ASM
        drvh pin
      ENDASM
    
    PUB Low(pin)
      ASM
        drvl pin
      ENDASM
    
    and so on.

  • Pins.spin2 came with a set of programs for the accessory boards. I thought I got them from the Accessory Set product page https://parallax.com/product/64006-es But I don't see them there. Other programs included the control board, AV board and LED Matrix board. I guess Parallax withdrew them. outa is used for pin < 32 and outb with pin number for pins > 31.

    John Abshier

    Not withdrawn, but moved to github: https://github.com/parallaxinc/propeller/tree/master/examples/Accessory Test Code
Sign In or Register to comment.