Shop OBEX P1 Docs P2 Docs Learn Events
P2 Newbie Discussion - Page 4 — Parallax Forums

P2 Newbie Discussion

124»

Comments

  • ersmith wrote: »
    @ersmith
    I omitted a rather important fact in the "save it" step; if it's a BASIC program, it has to have a .bas extension in the name. It looks like you saved it as Blink.spin; try Blink.bas instead.

    Ok thanks that worked. The strange thing is that compiling it in spin2gui blinks one LED however, the same code in PNut blinkes two LED's LOL

    ???

    I think you must have confused something, because PNut does not support BASIC, or even Spin; all PNut can compile is P2 assembly.

    I can use "PNut (aka Prop2 V32i IDE)", "Spin 2 Gui" and "Spin Edit" to compile and load .spin2 files into my P2Eval Board.
    I can also use "Spin Edit" to compile a .bas file creating a .p2asm file that I can load into my P2Eval Board with "PNut (aka Prop2 V32i IDE)".

    941 x 401 - 63K
    1645 x 614 - 152K
    844 x 722 - 120K
  • zappman wrote: »
    ersmith wrote: »
    Ok thanks that worked. The strange thing is that compiling it in spin2gui blinks one LED however, the same code in PNut blinkes two LED's LOL

    ???

    I think you must have confused something, because PNut does not support BASIC, or even Spin; all PNut can compile is P2 assembly.

    I can use "PNut (aka Prop2 V32i IDE)", "Spin 2 Gui" and "Spin Edit" to compile and load .spin2 files into my P2Eval Board.
    I can also use "Spin Edit" to compile a .bas file creating a .p2asm file that I can load into my P2Eval Board with "PNut (aka Prop2 V32i IDE)".

    Yes, but in that case "Spin Edit" uses fastspin to convert the .bas file to .p2asm which PNut understands.

    PNut itself does not understand BASIC, only P2 assembly. That is, you cannot load the .bas file into PNut and get any sensible result. Which is why I'm a bit puzzled that Bob said that "the same code in PNut blinks two LED's".

  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,720
    edited 2019-01-05 15:10
    PNut itself does not understand BASIC, only P2 assembly. That is, you cannot load the .bas file into PNut and get any sensible result. Which is why I'm a bit puzzled that Bob said that "the same code in PNut blinks two LED's".

    That's exactly what Bob Said LOL and maybe it's not suppose to however, I was following your instructions on how to run the code and I wondered what kind of error a newbi would get if they tried it in PNut not knowing that it doesn't support Basic. I was expecting some sort of meaningful error such as bas files not supported etc.. however it when like this

    1. I copied and pasted your basic code into PNut/

    2. I compilet and loaded it.

    3. It spit out this ASM code
    ================================================================
    ' dat
    orgh 0
    '
    ' seperate initialization of two cogs to blink on the Eval board
    '
    org


    coginit cognum1,#@blink ' init a single cog to use the blink program
    'wait jmp #wait

    coginit cognum2,#@blink2
    wait jmp #wait

    ' ************ The following cog combinations all work fine:


    cognum1 long 4
    cognum2 long 0

    ' cognum1 long 3
    ' cognum2 long 5

    ' cognum1 long 4
    ' cognum2 long 0

    ' cognum1 long 5
    ' cognum2 long 2

    ' cognum1 long 1
    ' cognum2 long 4

    '************* etc. any combo that doesn't have 0 or 2 initialized as cognum1 works


    ' ************* These combinations only blink the cognum1 led :

    ' cognum1 long 0
    ' cognum2 long 4

    ' cognum1 long 2
    ' cognum2 long 5

    ' cognum1 long 2
    ' cognum2 long 6


    ' this following combination only blinks 1 led (p58) on my P2-EV board

    'cognum1 long 2
    'cognum2 long 5


    '
    ' blinkS

    org


    blink cogid x 'which cog am I, 0..7?
    add x,#56 'add 56 to get LED pin
    drvnot x 'output and flip that pin
    shl x,#16 'shift up to make it big
    waitx x 'wait that many clocks
    jmp #blink 'do it again


    blink2 cogid y 'which cog am I, 0..7?
    add y,#56 'add 56 to get LED pin
    drvnot y 'output and flip that pin
    shl y,#16 'shift up to make it big
    waitx y 'wait that many clocks
    jmp #blink2 'do it again


    x res 1
    y res 1'

    =====================================================================

    4. Two LED's started flashing :smile:

    Just try it

  • ersmith wrote: »

    Yes, but in that case "Spin Edit" uses fastspin to convert the .bas file to .p2asm which PNut understands.

    PNut itself does not understand BASIC, only P2 assembly. That is, you cannot load the .bas file into PNut and get any sensible result. Which is why I'm a bit puzzled that Bob said that "the same code in PNut blinks two LED's".
    I agree with you, if he really used "identical code", he should get an "identical result".

  • PNut itself does not understand BASIC, only P2 assembly. That is, you cannot load the .bas file into PNut and get any sensible result. Which is why I'm a bit puzzled that Bob said that "the same code in PNut blinks two LED's".

    That's exactly what Bob Said LOL and maybe it's not suppose to however, I was following your instructions on how to run the code and I wondered what kind of error a newbi would get if they tried it in PNut not knowing that it doesn't support Basic. I was expecting some sort of meaningful error such as bas files not supported etc.. however it when like this

    1. I copied and pasted your basic code into PNut/

    2. I compilet and loaded it.

    3. It spit out this ASM code
    ...
    4. Two LED's started flashing :smile:

    Just try it

    I think you must have had something else in your copy buffer when you pasted it into PNut. The code after "It spit out this ASM code" looks like the P2 assembly code someone else posted elsewhere in this thread.

    When I tried pasting my original BASIC program:
    const _mode = 0x010c3f04
    const _clkfreq = 160_000_000
    const pin = 56
    
    clkset(_mode, _clkfreq)
    direction(pin) = output
    do
      output(pin) = not output(pin)
      pausems 500
    loop
    
    into PNut_V32i.exe, it highlighted the "_mode" and gave an error box saying:
    Expected "=" "[" "," or end of line
    
    which is perfectly reasonable behavior for PNut; I think it saw the "CON" in "const" and tried to parse everything after it as a Spin CON block.
  • OK I agree with you so I will experiment to see what I am doing . Now that I look at it it looks like code I was using in the FPGA a few night ago. It must be loading it as a file even though I started PNut fresh.
  • Ok that was it . If you copy and paste info PNut without saving it , it will run the last code you were running and saved. That's why we should go to bed and not play with this at 3AM + LOL
  • jmgjmg Posts: 15,173
    Ok that was it . If you copy and paste info PNut without saving it , it will run the last code you were running and saved. That's why we should go to bed and not play with this at 3AM + LOL

    Does that mean given identical (P2ASM) code, PNut gives identical results & identical binaries ? (ie the LED difference was different ASMs ?)
  • @jmg

    Yes.
    :the LED difference was different ASMs

    Yes. I was copying and pasting into PNut and compiling it without saving the file . PNut was loading a asm file from the Pnut folder and compiling and running it and not the code I pasted in.
  • Just got my eval board up and running, using Wine to run spin2gui on MacOS, bit of fiddling with
    the serial port naming needed but then it started working (helps to choose a USB cable that's not
    power-only I discovered!). Have flashed some LEDs, looking forward to playing with smart pins...

    With my homemade USB power meter I see 0.23A when running P2 code, 0.05A otherwise. The
    thermal management on the Eval board is great, it seems to spread that watt over the entire PCB
    nicely, the chip temperature only about 5C above the PCB, PCB 3C above ambient or so.

    __Mark
Sign In or Register to comment.