Parallax P2-EVAL (P2ES chip) pcb demo code

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.
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
''---------------------------------------------------------------------------------------------------
Comments
Note: You will need to remove the .txt from the filename as the forum will not allow uploads with .BIX
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
@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.
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
But, then I have no idea what I should be doing?
OK, I was able to get p58 blink using "PNut_v32i.exe"
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
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 )
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
I don't why this 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).
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
I not 1 (eye not one)
ADO not AD0 (much ADO about nothing)
Always have at least one whitespace between words and numbers
I reckon you might not have the correct Pnut.exe
It works fine on mine, which is version 32i (click Help to check version)
What version of Pnut are you using?
I am using "PNut_v32i.exe"
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
maybe just type them
dat org
led long 56
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 withentry 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?Same here, Version 32i
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.
' 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.
' 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