P2 Newbie Discussion

13

Comments

  • Even a 2-pin jumper footprint with a trace across it that can be easily cut and have the jumper soldered in would be fine.
  • The P2 reset and boot process is not particularly critical of timing so you can easily do without a DTR reset as long as you hit the reset button just before you download.

    The other solution is to make the jumper a simple pushbutton that you have to hold in for the DTR to pass through but then you may as well hit the reset. In some of my old P1 systems I didn't have DTR reset so I would simply hit the reset button and F11 in the right sequence but timing was critical.

    Tachyon Forth - compact, fast, forthwright and interactive
    useforthlogo-s.png
    --->CLICK THE LOGO for more links<---
    P2CHIP-1.jpg
    P2 +++++ TAQOZ INTRO & LINKS +++++ P2 SHORTFORM DATASHEET
    P1 +++++ Latest binary V5.4 includes EASYFILE +++++ Tachyon Forth News Blog
    Brisbane, Australia
  • thejthej Posts: 190
    edited 2018-12-30 - 08:59:51
    @Peter Jakacki
    Some questions on using the PWM Triangle mode to run servos.
    I want to do this from TAQOZ which has it's PWM word set to use the triangle mode.

    I've been playing with PWM in TAQOS by blinking the LED on pin 56 and that has been working well.
    Where I'm getting confused is when I want to control a servo.

    In TAQOS I have been using the following to blink the LED:
    56 PIN
    190 200 20000 PWM (I'm using 190 instead of 10 as the LED is active LOW)

    A servo wants the FRAME to be sent 50 times per second (every 20ms).
    How do I reliably get the frame sent to the servo every 20ms ?

    j
  • PWM was corrected in EXTEND to use the SAWTOOTH waveform otherwise the triangle waveform is half the frequency.

    If you want a 20ms repetition rate then essentially that means a divider of (clock rate/frame)/50. But you can just create a servo word that looks after this for you a bit like this:
    pub SERVO ( duty frame pin -- ) PIN CLKHZ OVER / 50 / PWM ;
    
    But if you wanted it inverted:
    pub ISERVO ( duty frame pin -- ) PIN DUP ROT - SWAP  CLKHZ OVER / 50 / PWM ;
    

    Sure, you could combine that into one function if you want to.

    Now all I type is:
    20 200 56 SERVO
    

    and I get a 10% duty on P56 every 20ms, nice and neat. Of course the word SERVO may require a signed value that represents degrees perhaps and so you can easily adapt this for a 360' servo too etc.


    BTW, If after you type P2-ES ETC you can also backup all your code and settings with BACKUP into Flash. Just use a ^R to restore it all again next time you boot back into TAQOZ.

    Tachyon Forth - compact, fast, forthwright and interactive
    useforthlogo-s.png
    --->CLICK THE LOGO for more links<---
    P2CHIP-1.jpg
    P2 +++++ TAQOZ INTRO & LINKS +++++ P2 SHORTFORM DATASHEET
    P1 +++++ Latest binary V5.4 includes EASYFILE +++++ Tachyon Forth News Blog
    Brisbane, Australia
  • Super !! I almost had it figured out ;-)

    I had missed the change to Sawtooth, thanks !

    I knew there had to be a word to show the current speed (CLKHZ). Thanks!

    j
  • thejthej Posts: 190
    edited 2018-12-30 - 11:41:51
    I'm examining this closer as I'm experimenting...
    Here's my thinking. Correct me where I'm wrong.

    Since the servo requires a frame of 50Hz (20ms), it only needs to be calculated once. The same would go for the PIN and the Div. So I'm going to make a word to setup all three. Since I will need the Frame and the Div values later, I will save them to variables as well.

    : SRVO_INIT ( pin — ) PIN CLKHZ 50 / dup var SRVOFRM SRVOFRM ! CLKHZ swap - var SRVODIV SRVODIV !

    With that set, all I will need is a duty cycle %. It's the only value that will need to change when programming the servo. I'm assuming that the Div value should be the CLKHZ - Frame so that the Div and the Frame together = one full second's worth of cpu cycles.

    : SRVO ( duty% -- ) SRVOFRM @ SRVODIV @ PWM

    I'm about to give these more testing (by actually connecting my servo :-) but I'm sure you could point me to better ways of using variables, etc.

    J

  • I'm trying out my first code changes with PNUT on my P2 eval board.

    I started off with Chips original blink program. Instead of initializing a group of cogs with a loop ( which works fine) I changed the code to initialize a single cog with the blink function, then initialize a second cog with another blink routine. These functions work fine UNLESS the first cog initialized is either cog 0 or cog 2. In this case, only the first cog seems to be functioning.

    ( Change cognum1 to 0 or 2 to verify in the attached code )

    Is this something I don't understand about the P2, the Eval board or something odd about the compiler itself?

    Any ideas?
  • What is the difference between the P1 loader and P2. Can the old version be easily updated or is it totally different.
  • Hey, another eval board alive and checking in. I just got setup and am currently playing with TAQOS.
    Do not taunt Happy Fun Ball! @opengeekorg ---> Be Excellent To One Another SKYPE = acuity_doug
    Parallax colors simplified: https://forums.parallax.com/discussion/123709/commented-graphics-demo-spin<br>
  • T Chap wrote: »
    What is the difference between the P1 loader and P2. Can the old version be easily updated or is it totally different.

    P2 Loading is quite different to P1, T Chap. It uses base 64 (makes it easy to dump with terminal programs etc) and is described in the google doc linked in first post of "FPGA Files!!!" thread.
  • David Betz wrote: »
    Eric may be away for the holidays or waiting for his P2-Eval board to be delivered. I suspect he'll update spin2gui when he gets back.

    Just very very busy with family obligations, I'm afraid. But I have updated spin2gui for the P2-Eval board. After you start spin2gui.exemake sure you go to Commands > Configure Commands... and select "P2 Defaults" then "OK". There are some sample programs included with spin2gui that do some basic things (serial I/O and LED blinking).
  • kbash wrote: »
    I'm trying out my first code changes with PNUT on my P2 eval board.

    I started off with Chips original blink program. Instead of initializing a group of cogs with a loop ( which works fine) I changed the code to initialize a single cog with the blink function, then initialize a second cog with another blink routine. These functions work fine UNLESS the first cog initialized is either cog 0 or cog 2. In this case, only the first cog seems to be functioning.

    ( Change cognum1 to 0 or 2 to verify in the attached code )

    Is this something I don't understand about the P2, the Eval board or something odd about the compiler itself?

    Any ideas?

    I see a few potential problems with the code:

    (1) The original COG never stops (unless either cognum1 or cognum2 is 0). After the two coginits you should probably add a "cogstop #0".

    (2) The second block of code (blink2) doesn't have its own origin; I'm not sure what's likely to happen as a result, but it probably isn't good. I would add an "org" directive just before the blink2 label.

    (3) The declaration of "x" should go in the "blink" block (the declaration of "y" should stay with the "blink2" block).
  • Cluso99 wrote: »
    Guys,
    To start with the P2 now, you will pretty much need to learn/use P2 assembler, or learn/run TAQOZ.
    fastspin is working on the P2 Eval board now, so BASIC and Spin are available now, and even have a (very primitive) IDE in the form of spin2gui. A blinking LED program for P2Eval:
    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
    

    To run it in spin2gui:

    * Download spin2gui.zip (version 1.3.0) from https://github.com/totalspectrum/spin2gui/releases
    * Unzip in a folder that has no spaces in its name (sorry, there's a bug there)
    * Run spin2gui.exe
    * Go to the menu Commands > Configure Commands... and select "P2 Default" then "OK"
    * Enter the program above
    * Save it via File > Save As...
    * Press the "Compile & Run" button

  • jmgjmg Posts: 12,884
    ersmith wrote: »
    fastspin is working on the P2 Eval board now, so BASIC and Spin are available now, and even have a (very primitive) IDE in the form of spin2gui. A blinking LED program for P2Eval:
    Great news.
    ersmith wrote: »
    const _mode = 0x010c3f04
    const _clkfreq = 160_000_000
    const pin = 56
    
    clkset(_mode, _clkfreq)
    ..
    

    Curious here, that mode value seems to set 0pF Xtal (Should be 15pF as better Xtal match?), and VCO/2 for a 320MHz VCO and 160MHz SysClk, 5MHz PFD

    Why does clkset() also need _clkfreq as a param, as all PLL dividers setup seems to be in const _mode = 0x010c3f04 ?


  • jmg wrote: »
    Curious here, that mode value seems to set 0pF Xtal (Should be 15pF as better Xtal match?), and VCO/2 for a 320MHz VCO and 160MHz SysClk, 5MHz PFD
    I based it on some of Cluso's work, but perhaps it's out of date? In any event it's completely up to the programmer and (obviously) very easy to change. Note that the mode value is the raw oscillator setup, the actual enable is done automatically by adding %11 to the mode.
    Why does clkset() also need _clkfreq as a param, as all PLL dividers setup seems to be in const _mode = 0x010c3f04 ?
    Different boards might have different crystal frequencies. It's the same situation as the P1 clkset() function (which also takes those two parameters, although the meaning of the "mode" parameter is quite different.
  • jmgjmg Posts: 12,884
    ersmith wrote: »
    jmg wrote: »
    Why does clkset() also need _clkfreq as a param, as all PLL dividers setup seems to be in const _mode = 0x010c3f04 ?
    Different boards might have different crystal frequencies. It's the same situation as the P1 clkset() function (which also takes those two parameters, although the meaning of the "mode" parameter is quite different.

    Is _clkfreq actually used to set the PLL/VCO, or is it stored for future use so other code can know the SysCLK ?
  • jmg wrote: »
    ersmith wrote: »
    jmg wrote: »
    Why does clkset() also need _clkfreq as a param, as all PLL dividers setup seems to be in const _mode = 0x010c3f04 ?
    Different boards might have different crystal frequencies. It's the same situation as the P1 clkset() function (which also takes those two parameters, although the meaning of the "mode" parameter is quite different.

    Is _clkfreq actually used to set the PLL/VCO, or is it stored for future use so other code can know the SysCLK ?

    _clkfreq is only stored for use by library functions. It has no effect on the PLL/VCO, only the _clkmode affects that.
  • How do you change the baud rate in spin2gui??
  • Dumb question. I just unboxed my ES board. I can access tacoz and use the blink command. However I cannot get all_cogs_blink.spin2 to work when programming it from Pnut. Does it require a sd card? Am I missing something? PNut identifies the P2, so I must be doing something wrong.
    Feel the need for speed between your PC's com port and Prop?
    Try the FTDI 245 and the FullDuplexParallel Object.

    Check out my spin driver for the Parallax "96 x 64 Color OLED Display Module" Product ID: 28087
  • What com port is your P2? Pnut only works on port 9 or less.
    Do not taunt Happy Fun Ball! @opengeekorg ---> Be Excellent To One Another SKYPE = acuity_doug
    Parallax colors simplified: https://forums.parallax.com/discussion/123709/commented-graphics-demo-spin<br>
  • its outputting to the wrong leds (32..39).

    change the line

    add x,#32
    to

    add x,#56

    to move the blinking leds up to P56..63
  • Tubular wrote: »
    its outputting to the wrong leds (32..39).

    change the line

    add x,#32
    to

    add x,#56

    to move the blinking leds up to P56..63

    Bingo! Thank you!

    I now bring you this embarrassing video where I forgot what fourth was and can couldn't get the P2 to blink :)

    https://www.facebook.com/terrytrapp/videos/10219100499770344/

    Feel the need for speed between your PC's com port and Prop?
    Try the FTDI 245 and the FullDuplexParallel Object.

    Check out my spin driver for the Parallax "96 x 64 Color OLED Display Module" Product ID: 28087
  • Feel the need for speed between your PC's com port and Prop?
    Try the FTDI 245 and the FullDuplexParallel Object.

    Check out my spin driver for the Parallax "96 x 64 Color OLED Display Module" Product ID: 28087
  • Another dumb question. Looking through the various examples for VGA, there are no comments regarding pin assignments for video. I must admit that I am out of my depth currently looking through the source for how those pins get assigned in the VGA drivers. I was able to easily identify vSync in the source of several examples.

    I found this in P2 Invaders (which has a configurable base pin) and was wondering: Is the usual pin sequence for VGA?

    PIN SIGNAL
    basepin Hsync
    +1 Blue
    +2 Green
    +3 Red
    +4 Vsync

    Thanks in advance!

    --Terry
    Feel the need for speed between your PC's com port and Prop?
    Try the FTDI 245 and the FullDuplexParallel Object.

    Check out my spin driver for the Parallax "96 x 64 Color OLED Display Module" Product ID: 28087
  • ersmith wrote: »
    ....
    fastspin is working on the P2 Eval board now, so BASIC and Spin are available now, and even have a (very primitive) IDE in the form of spin2gui. A blinking LED program for P2Eval:
    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
    

    To run it in spin2gui:

    * Download spin2gui.zip (version 1.3.0) from https://github.com/totalspectrum/spin2gui/releases
    * Unzip in a folder that has no spaces in its name (sorry, there's a bug there)
    * Run spin2gui.exe
    * Go to the menu Commands > Configure Commands... and select "P2 Default" then "OK"
    * Enter the program above
    * Save it via File > Save As...
    * Press the "Compile & Run" button

    Thanks, I have spin2gui (version 1.3.2) working with my P2-ES board. :cool:
  • @ersmith
    To run it in spin2gui:

    * Download spin2gui.zip (version 1.3.0) from https://github.com/totalspectrum/spin2gui/releases
    * Unzip in a folder that has no spaces in its name (sorry, there's a bug there)
    * Run spin2gui.exe
    * Go to the menu Commands > Configure Commands... and select "P2 Default" then "OK"
    * Enter the program above
    * Save it via File > Save As...
    * Press the "Compile & Run" button

    I tried it for the first time and got the following error:

    I copied and pasted the code
    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


    C:/Users/Cosmicbob/Documents/P2Projects/Blink.spin(1) error: syntax error, unexpected identifier `_mode', expecting end of line or ','
    C:/Users/Cosmicbob/Documents/P2Projects/Blink.spin(5) error: syntax error, unexpected '(', expecting end of line or ','
    C:/Users/Cosmicbob/Documents/P2Projects/Blink.spin(8) error: syntax error, unexpected '(', expecting end of line or ','
    C:/Users/Cosmicbob/Documents/P2Projects/Blink.spin(11) error: syntax error, unexpected $end
    child process exited abnormally
    ====================================================
  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,523
    edited 2019-01-05 - 02:14:17
    I copied the code into PNut and it compiled and the 2 outside LED's are blinking and got 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
  • ersmithersmith Posts: 2,582
    edited 2019-01-05 - 03:34:58

    * Download spin2gui.zip (version 1.3.0) from https://github.com/totalspectrum/spin2gui/releases
    * Unzip in a folder that has no spaces in its name (sorry, there's a bug there)
    * Run spin2gui.exe
    * Go to the menu Commands > Configure Commands... and select "P2 Default" then "OK"
    * Enter the program above
    * Save it via File > Save As...
    * Press the "Compile & Run" button

    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.

    (fastspin uses the file extension to determine what language to parse; .bas and .bi for BASIC, .c or .h for C, and
    anything else for Spin).

  • @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
  • @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.
Sign In or Register to comment.