Parallax P2-EVAL (P2ES chip) pcb demo code

Cluso99Cluso99 Posts: 15,396
edited 2018-12-24 - 05:23:49 in Propeller 2
I thought I would start a thread just for demo code that runs on the Parallax P2-EVAL board (with the P2-ES chip).

Here is demo code to setup the crystal oscillator to 180MHz and drive the serial port using the ROM Monitor/Debugger. Note the actual P2ASM code is tiny. Setup your serial terminal (via USB) to 115,200 baud - I use PST (Parallax Serial Terminal).

This is the assembler code portion. The remainder is just equates.
DAT
                orgh    0
                org     0
'+-------[ Set Xtal ]----------------------------------------------------------+ 
entry           hubset  #0                              ' set 20MHz+ mode
                hubset  ##_SETFREQ                      ' setup oscillator
                waitx   ##20_000_000/100                ' ~10ms
                hubset  ##_ENAFREQ                      ' enable oscillator
'+-----------------------------------------------------------------------------+
                waitx   ##_clockfreq*5                  ' just a delay to get pc terminal running

''-------[ Start Serial ]------------------------------------------------------ 
                mov     lmm_bufad,        ##_HUBBUF     ' locn of hub buffer for serial routine 
                mov     lmm_x,            ##_bitper     ' sets serial baud
                call    #_SerialInit                    ' initialise serial
''-----------------------------------------------------------------------------

' this code displays a version string (it's not required)
                mov     lmm_p,            ##hubstring   ' must be in hub!
                call    #_HubTxString
.loop           waitx   ##_clockfreq                    ' just a delay before repeating
		mov	lmm_x,            #"Z"
                call    #_HubTx
                jmp     #.loop

''---------------------------------------------------------------------------------------------------


''============[ COG VARIABLES - MONITOR]========================================                                    
                fit     $1E0              ' ensure LMM reserved area cog $1E0-$1EF available                                                                              
''---------------------------------------------------------------------------------------------------

''============[ HUB VARIABLES ]=================================================                                    
DAT		orgh	$
hubstring	byte	"P2ES-EVAL-Demo-002",13,10
		alignl                                                                                                             
''---------------------------------------------------------------------------------------------------
My Prop boards: P8XBlade2, RamBlade, CpuBlade, TriBlade
Prop OS (also see Sphinx, PropDos, PropCmd, Spinix)
Website: www.clusos.com
Prop Tools (Index) , Emulators (Index) , ZiCog (Z80)
«1345

Comments

  • This is the above program compiled with pnut to P2ES-EVAL-Demo-002.obj and renamed "_BOOT_P2.BIX" (case sensitive) and copied to a formatted FAT32 microSD card. The card is then inserted into the P2-EVAL board and plugged in to USB/Power and PST run on the PC. No switches require changing on the hardware. The program will automatically boot/run from the SD card :smiley:

    Note: You will need to remove the .txt from the filename as the forum will not allow uploads with .BIX
    My Prop boards: P8XBlade2, RamBlade, CpuBlade, TriBlade
    Prop OS (also see Sphinx, PropDos, PropCmd, Spinix)
    Website: www.clusos.com
    Prop Tools (Index) , Emulators (Index) , ZiCog (Z80)
  • samuellsamuell Posts: 405
    edited 2018-12-24 - 14:45:59
    This will do as a nice test program. Since many people will test this using the Parallax Serial Terminal, I'll probably use PuTTY (Linux and Windows) and HyperTerminal (Windows).

    However, I want to see TacOS loading without any program loaded first. It is a nice test for half a day. As soon as the board arrives, it will be done.

    Kind regards, Samuel Lourenço
  • Cluso, thank you very much! It's exciting to see some serial output from nonROM routines. The only way so far I've been able to get this to run is using PNut to assemble and load - loadp2 appears to send the .o file but no joy as far as output.
    The difference between theory and practice is that, in theory, there is no difference between theory and practice, but in practice, there is.
  • Cluso99 wrote: »
    This is the above program compiled with pnut to P2ES-EVAL-Demo-002.obj and renamed "_BOOT_P2.BIX" (case sensitive) and copied to a formatted FAT32 microSD card. The card is then inserted into the P2-EVAL board and plugged in to USB/Power and PST run on the PC. No switches require changing on the hardware. The program will automatically boot/run from the SD card :smiley:

    Note: You will need to remove the .txt from the filename as the forum will not allow uploads with .BIX

    @Cluso99, thank you for the file, I put it on my SD card and was able to run the program. I received all the "zzzzzzzzzzz......." in the Parallax Serial Terminal. So that proves my board can run binary files. I still need to figure out how to compile and upload programs to my P2-EVAL board.
  • zappman, I used Pnut_v32i and it was able to assemble and serially load Cluso's test program. I think I'm getting closer to figuring out what I'm obviously missing with the other tools...
    The difference between theory and practice is that, in theory, there is no difference between theory and practice, but in practice, there is.
  • pmrobertpmrobert Posts: 572
    edited 2018-12-24 - 16:37:47
    Just as proof of concept (me not screwing something up!) and hardware attached is the scope cap from P0-P4 after loading Cluso's VGA1080 program via Pnut. Nice!!! Sorry for OT post, felt good to have something living and breathing (in a silicon manner).
    1577 x 592 - 74K
    The difference between theory and practice is that, in theory, there is no difference between theory and practice, but in practice, there is.
  • marsman2020marsman2020 Posts: 69
    edited 2018-12-24 - 21:01:10
    Tubular posted this in another thread. This will make p58 blink. Working in pNut for me.
    dat	org
    	hubset 	#0		'use RCFAST
    blink	waitx	##10_000_000	'delay 0.5 sec (at RCFAST)
    	drvnot	#58		'flip output P58
    	jmp	#blink		'loop
    
  • Pnut is in the P2 downloads for the FPGA. See the first post in the FPGA thread. There is also pnut v32j which has a bigger symbol table needed to compile the rom code.
    My Prop boards: P8XBlade2, RamBlade, CpuBlade, TriBlade
    Prop OS (also see Sphinx, PropDos, PropCmd, Spinix)
    Website: www.clusos.com
    Prop Tools (Index) , Emulators (Index) , ZiCog (Z80)
  • zappmanzappman Posts: 415
    edited 2018-12-24 - 23:38:05
    OK, I have "PNut_v32i.exe" and it can see that my P2ES-EVAL board is on com 4.
    But, then I have no idea what I should be doing?
    OK, I was able to get p58 blink using "PNut_v32i.exe"
  • zappmanzappman Posts: 415
    edited 2018-12-24 - 23:52:00
    OK, this little piece of code, blinks all 8 LEDs on the board, using "PNut_v32i.exe" to compile and download to the board.
    dat	org
    	hubset 	#0		'use RCFAST
    blink	waitx	##10_000_000	'delay 0.5 sec (at RCFAST)
    	drvnot	#56		'flip output P56
    	drvnot	#57		'flip output P57
    	drvnot	#58		'flip output P58
    	drvnot	#59		'flip output P59
    	drvnot	#60		'flip output P60
    	drvnot	#61		'flip output P61
    	drvnot	#62		'flip output P62
    	drvnot	#63		'flip output P63
    	jmp	#blink		'loop
    
  • Peter JakackiPeter Jakacki Posts: 8,641
    edited 2018-12-25 - 00:03:40
    Or in TAQOZ try this for effect:
    56 8 ADO I PIN 4 HZ 20 ms LOOP
    
    I haven't tried it but not only should the leds blink but with the 20ms delay there should be a rippling effect as well.
    The 20ms is actually closer to 80ms due to timing difference between RCFAST and 80MHz FPGA (same with the 20 ms)

    BTW - I haven't got a P2-ES board but I could hook up some leds on my P2D2 and video it.

    Breakdown of that code:
    56 - push 56 onto the stack 
    8 - push 8 onto the stack 
    ADO - take two values from the stack ( start=56 count=8 ) and set loop for effectively 8 times starting with I = 56
    I - leave current index value on stack
    PIN - use value from stack to select a pin
    4
    ms - delay for milliseconds specified
    LOOP - increment index until start+count is reached else continue to loop back to code following ADO  
    ( implicit EXIT or return )
    

    Tachyon Forth - compact, fast, forthwright and interactive
    useforthlogo-s.png
    --->CLICK THE LOGO for more links<---
    P2 +++++ TAQOZ INTRO & LINKS +++++ P2 SHORTFORM DATASHEET
    P1 +++++ Latest Tachyon includes EASYFILE +++++ Tachyon Forth News Blog
    Brisbane, Australia
  • Here's a little demo led chaser using 8 cogs.
    Demonstrates some of P2's instructions too.
    '8 cog led chaser demo
    
    dat	org
    		cogid	cog		'get cog number	
    		or	cog,#0 wz	'test if cog #0
    		add	led,cog		'led pin 56 to 63
    		coginit	#16,#0 		'laucnh another cog
    		incmod	cog,#7		'+1 cog,wrap to 0 on 8
    		decod	cog		'ATN bit for next cog
    	if_z	jmp	#kickstart	'if cog #0 kickstart
    
    loop		waitatn			'wait for trigger from previous cog
    kickstart	drvnot	led		'toggle led
    		waitx	##2_000_000	'wait ~1/10 sec
    		cogatn	cog		'trigger next cog
    		jmp	#loop
    
    cog		long	0
    led		long	56
    
    
    Melbourne, Australia
  • zappmanzappman Posts: 415
    edited 2018-12-25 - 15:43:01
    Or in TAQOZ try this for effect:
    56 8 ADO I PIN 4 HZ 20 ms LOOP
    
    I haven't tried it but not only should the leds blink but with the 20ms delay there should be a rippling effect as well.
    The 20ms is actually closer to 80ms due to timing difference between RCFAST and 80MHz FPGA (same with the 20 ms)

    BTW - I haven't got a P2-ES board but I could hook up some leds on my P2D2 and video it.

    Breakdown of that code:
    56 - push 56 onto the stack 
    8 - push 8 onto the stack 
    ADO - take two values from the stack ( start=56 count=8 ) and set loop for effectively 8 times starting with I = 56
    I - leave current index value on stack
    PIN - use value from stack to select a pin
    4
    ms - delay for milliseconds specified
    LOOP - increment index until start+count is reached else continue to loop back to code following ADO  
    ( implicit EXIT or return )
    

    I don't why this
    56 8 ADO I PIN 4 HZ 20 ms LOOP
    is not working on my P2ES-EVAL board.

    All of these work:
    56 blink
    57 blink
    58 blink
    59 blink
    60 blink
    61 blink
    62 blink
    63 blink

    Note: On December 25, 2018, I tried the above TAQOZ line of code and it blinks the LEDs on my P2ES-EVAL board correctly (I must have been typing in the line wrong before).
  • hmm works fine on mine, i just cut and pasted Peter's one liner then hit enter
  • zappmanzappman Posts: 415
    edited 2018-12-25 - 02:33:56
    ozpropdev wrote: »
    Here's a little demo led chaser using 8 cogs.
    Demonstrates some of P2's instructions too.
    '8 cog led chaser demo
    
    dat	org
    		cogid	cog		'get cog number	
    		or	cog,#0 wz	'test if cog #0
    		add	led,cog		'led pin 56 to 63
    		coginit	#16,#0 		'laucnh another cog
    		incmod	cog,#7		'+1 cog,wrap to 0 on 8
    		decod	cog		'ATN bit for next cog
    	if_z	jmp	#kickstart	'if cog #0 kickstart
    
    loop		waitatn			'wait for trigger from previous cog
    kickstart	drvnot	led		'toggle led
    		waitx	##2_000_000	'wait ~1/10 sec
    		cogatn	cog		'trigger next cog
    		jmp	#loop
    
    cog		long	0
    led		long	56
    
    

    The above does not compile.
    On this line "led" gets highlighted and I get the error "Undefined symbol."
    [code]add led,cog 'led pin 56 to 63[/code]

    Code works fine was a cut and paste problem
  • Peter JakackiPeter Jakacki Posts: 8,641
    edited 2018-12-25 - 00:24:29
    Maybe it's a typo. Copy and paste if you aren't sure.
    I not 1 (eye not one)
    ADO not AD0 (much ADO about nothing)

    Always have at least one whitespace between words and numbers

    Tachyon Forth - compact, fast, forthwright and interactive
    useforthlogo-s.png
    --->CLICK THE LOGO for more links<---
    P2 +++++ TAQOZ INTRO & LINKS +++++ P2 SHORTFORM DATASHEET
    P1 +++++ Latest Tachyon includes EASYFILE +++++ Tachyon Forth News Blog
    Brisbane, Australia
  • Is cog reserved?
    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>
  • I use Pnut, works fine here.
    Melbourne, Australia
  • zappman wrote: »
    The above does not compile.
    On this line "led" gets highlighted and I get the error "Undefined symbol."
    add	led,cog		'led pin 56 to 63
    

    I reckon you might not have the correct Pnut.exe
    It works fine on mine, which is version 32i (click Help to check version)
  • ozpropdev wrote: »
    I use Pnut, works fine here.

    What version of Pnut are you using?
    I am using "PNut_v32i.exe"
  • This "brute force 8 led chaser demo" works
    dat	org
    	hubset 	#0		'use RCFAST
    blink	waitx	##1_250_000	'delay (0.5 / 8) sec (at RCFAST)
    	drvnot	#56		'flip output P56
    	waitx	##1_250_000	'delay (0.5 / 8) sec (at RCFAST)	
    	drvnot	#57		'flip output P57
    	waitx	##1_250_000	'delay (0.5 / 8) sec (at RCFAST)
    	drvnot	#58		'flip output P58
    	waitx	##1_250_000	'delay (0.5 / 8) sec (at RCFAST)
    	drvnot	#59		'flip output P59
    	waitx	##1_250_000	'delay (0.5 / 8) sec (at RCFAST)
    	drvnot	#60		'flip output P60
    	waitx	##1_250_000	'delay (0.5 / 8) sec (at RCFAST)
    	drvnot	#61		'flip output P61
    	waitx	##1_250_000	'delay (0.5 / 8) sec (at RCFAST)
    	drvnot	#62		'flip output P62
    	waitx	##1_250_000	'delay (0.5 / 8) sec (at RCFAST)
    	drvnot	#63		'flip output P63
    	jmp	#blink		'loop
    
  • I reckon there's something wrong with either your first or very last line, Zappman . Maybe some nonprinting character got copied, or something

    maybe just type them
    dat org
    led long 56

  • Cluso, I'm trying to figure out how to set a specific frequency on the P2 Eval board. In your code you have
    CON
      _XTALFREQ     = 20_000_000                                    ' crystal frequency
      _XDIV         = 4             '\                              '\ crystal divider                      to give 5.0MHz
      _XMUL         = 72            '| 180MHz                       '| crystal / div * mul                  to give 360MHz
      _XDIVP        = 2             '/                              '/ crystal / div * mul /divp            to give 180MHz
      _XOSC         = %01                                   'OSC    ' %00=OFF, %01=OSC, %10=15pF, %11=30pF
      _XSEL         = %11                                   'XI+PLL ' %00=rcfast(20+MHz), %01=rcslow(~20KHz), %10=XI(5ms), %11=XI+PLL(10ms)
      _XPPPP        = ((_XDIVP>>1) + 15) & $F                       ' 1->15, 2->0, 4->1, 6->2...30->14
      _CLOCKFREQ    = _XTALFREQ / _XDIV * _XMUL / _XDIVP            ' internal clock frequency                
      _SETFREQ      = 1<<24 + (_XDIV-1)<<18 + (_XMUL-1)<<8 + _XPPPP<<4 + _XOSC<<2  ' %0000_000e_dddddd_mmmmmmmmmm_pppp_cc_00  ' setup  oscillator
      _ENAFREQ      = _SETFREQ + _XSEL                                             ' %0000_000e_dddddd_mmmmmmmmmm_pppp_cc_ss  ' enable oscillator
    
    And then you set the hub mode with
    entry           hubset  #0                              ' set 20MHz+ mode
                    hubset  ##_SETFREQ                      ' setup oscillator
                    waitx   ##20_000_000/100                ' ~10ms
                    hubset  ##_ENAFREQ                      ' enable oscillator
    
    So if I want some other frequency I would just adjust _XMUL proportionately, correct? So if I want 80MHz I would use a value of 72*80/180 = 32. Are the the hubset instructions necessary, or could I just do "hubset ##_ENAFREQ", and skip the other two hubsets?
  • zappman wrote: »
    ozpropdev wrote: »
    I use Pnut, works fine here.

    What version of Pnut are you using?
    I am using "PNut_v32i.exe"

    Same here, Version 32i
    Melbourne, Australia
  • jmgjmg Posts: 13,902
    Dave Hein wrote: »
    Cluso, I'm trying to figure out how to set a specific frequency on the P2 Eval board. In your code you have
    entry           hubset  #0                              ' set 20MHz+ mode
                    hubset  ##_SETFREQ                      ' setup oscillator
                    waitx   ##20_000_000/100                ' ~10ms
                    hubset  ##_ENAFREQ                      ' enable oscillator
    
    So if I want some other frequency I would just adjust _XMUL proportionately, correct? So if I want 80MHz I would use a value of 72*80/180 = 32. Are the the hubset instructions necessary, or could I just do "hubset ##_ENAFREQ", and skip the other two hubsets?

    I think the idea is to start on RCFAST which is the reset default, and the first hubset is likely there to cover paths other than reset.
    Then, you enable the Xtal oscillator, but do not yet enable the PLL output drive to SysCLK, then pause to allow Xtal to start, and pll to settle/lock.
    Finally, enable PLL VCO/divp to drive SysCLK.

    It's likely you could skip some hubsets and waits, but then you expose the P2 clock tree to an unlocked PLL (ie could be any MHz)

    Lacking in P2 is any clock present or pll locked check, so the delay and hope is how it is coded.
  • JonnyMacJonnyMac Posts: 6,230
    edited 2018-12-25 - 01:52:22
    I just got my eval board up and running. I modified the random program to run on the 8 LEDs of the P2 Eval board.
    ' This program displays the upper 8 bits of the PRNG to
    ' pins 63..56, which are LEDs on the P2 Eval board.
    
    dat	org
    
    	bmask	dirb, #7		' create 8-bit mask
    	shl	dirb, #(56-32)		' shift to leds
    
    loop	getrnd	outb			' get xoroshiro128+ onto p63..p56
    	waitx	##20_000_000/10		' wait 1/10 second
    	jmp	#loop
    
    Jon McPhalen
    Hollywood, CA
    It's Jon or JonnyMac -- please do not call me Jonny.
  • zappmanzappman Posts: 415
    edited 2018-12-25 - 02:13:30
    JonnyMac wrote: »
    I just got my eval board up and running. I modified the random program to run on the 8 LEDs of the P2 Eval board.
    ' This program displays the upper 8 bits of the PRNG to
    ' pins 63..56, which are LEDs on the P2 Eval board.
    
    dat	org
    
    	bmask	dirb, #7		' create 8-bit mask
    	shl	dirb, #(56-32)		' shift to leds
    
    loop	getrnd	outb			' get xoroshiro128+ onto p63..p56
    	waitx	##20_000_000/10		' wait 1/10 second
    	jmp	#loop
    

    @JonnyMac , your program runs great.
  • Since I live and work in Hollywood, I had to do this:
    ' This program creates an 8-LED Larson scanner on the P2 Eval board
    
    dat		org
    
    ls_fwd		mov	ledpin, #56		' start with p56
    		mov	cycles, #7		' light 7 going up
    .loop		drvl	ledpin			' led on
    		waitx	##20_000_000/8		' wait 1/8 second
    		drvh	ledpin			' led off
    		add	ledpin, #1		' next pin
    		djnz	cycles, #.loop		' done? 
    
    ls_rev		mov	ledpin, #63		' start with p63
    		mov	cycles, #7		' light 7 going down
    .loop		drvl	ledpin
    		waitx	##20_000_000/8
    		drvh	ledpin
    		sub	ledpin, #1
    		djnz	cycles, #.loop
    
    		jmp	#ls_fwd
    
    
    ledpin	res	1
    cycles	res	1
    
    Jon McPhalen
    Hollywood, CA
    It's Jon or JonnyMac -- please do not call me Jonny.
Sign In or Register to comment.