Shop OBEX P1 Docs P2 Docs Learn Events
Prop2 ES Eval Board. Trying to blink P56 LED using PNUT v33L. Not working... — Parallax Forums

Prop2 ES Eval Board. Trying to blink P56 LED using PNUT v33L. Not working...

BeanBean Posts: 8,129
edited 2019-11-18 15:44 in Propeller 2
I am trying to simply blink the LED on P56.
I press F11 and it downloads the code and P60 and P61 LEDs come on briefly, but then nothing.
CON
  basepin=32
  oscmode = $010c3f04
  freq = 160_000_000


PUB Main
  dirb[56] := 1
  repeat
    outb[56] := 1
    waitcnt 80_000_000 + cnt
    outb[56] := 0
    waitcnt 80_000_000 + cnt

Is there a jumper I must install ?

Thanks for any help,
Bean

Comments

  • evanhevanh Posts: 15,192
    Pnut knows nothing about Spin language. I'm surprised it doesn't produce an error.

    FlexGUI/fastspin is the direction to look in - https://forums.parallax.com/discussion/170730/flexgui-4-0-3-a-complete-programming-system-for-p2-and-p1/p1

  • PNut doesn't have any Spin support yet, as far as I know.

    You can compile and run your example using FlexGUI, except that you'll have to put brackets around the parameter to the waitcnt() call. Also, it'll be running at RCFAST speed (around 20 MHz) since there's no explicit clkset() call.

    You could also do something similar in BASIC as:
    clkset(0x010c3f04, 160_000_000)
    direction(56) = 1
    do
      output(56) = 1
      pausems 500
      output(56) = 0
      pausems 500
    loop
    
  • rjo__rjo__ Posts: 2,114
    in PNUT this works:
    dat 
    org
    
    	dirh #24
    	outh #24
    myend
    	jmp #myend
    

    if you plug your "Control" addon board at #24

    but this doesn't:
    dat 
    org
    
    	dirh #56
    	outh #56
    myend
    	jmp #myend
    
  • cgraceycgracey Posts: 14,133
    Bean wrote: »
    I am trying to simply blink the LED on P56.
    I press F11 and it downloads the code and P60 and P61 LEDs come on briefly, but then nothing.
    CON
      basepin=32
      oscmode = $010c3f04
      freq = 160_000_000
    
    
    PUB Main
      dirb[56] := 1
      repeat
        outb[56] := 1
        waitcnt 80_000_000 + cnt
        outb[56] := 0
        waitcnt 80_000_000 + cnt
    

    Is there a jumper I must install ?

    Thanks for any help,
    Bean

    PNut_v33L doesn't do Spin2, yet, but the compiler is able to process some Spin2 source. It's a work-in-progress that is not functional, yet, so I haven't said anything about it. It's kind of funny they it gave the appearance that it might be working.
  • BeanBean Posts: 8,129
    edited 2019-11-18 16:55
    Okay, well I want to use PASM anyway.
    I'll try doing it in PASM with PNut.

    I don't have the "CONTROL" board, I'm just trying it with the LEDs on the Eval board.

    Thanks for the quick replies...

    Bean
  • RaymanRayman Posts: 13,900
    edited 2019-11-18 17:09
    FlexGui comes with a blink example... It probably will work with PNut too:
    https://github.com/totalspectrum/flexgui/blob/master/samples/blink_pasm.spin2
  • BeanBean Posts: 8,129
    Okay, I got this working with PNut.
    DAT org
    
      dirh #56
    
    main
      outl #56
    
      mov temp,second
    delay1
      djnz temp,#delay1
    
      outh #56
      mov temp,second
    delay2
      djnz temp,#delay2
    
      jmp #main
    
    temp   LONG 0
    second LONG 800_000
    

    Bean
  • Cluso99Cluso99 Posts: 18,069
    edited 2019-11-18 21:39
    For your delay loop you can use
    WAITX ##$20_000_000

    If you set the crystal then change 20_ to your clock frequency to give 1 second

    There is a clock setting rxample in the P2 Tricks and Traps thread

    Postedit: fix waitx
  • BeanBean Posts: 8,129
    Cluso99 wrote: »
    For your delay loop you can use
    WAIT ##$20_000_000

    Okay, what does the double # mean ? That is a new one on me...

    Bean

  • Bean wrote: »
    Cluso99 wrote: »
    For your delay loop you can use
    WAIT ##$20_000_000

    Okay, what does the double # mean ? That is a new one on me...

    Bean

    Double # means add an AUGS (or AUGD) prefix to allow for a longer immediate value. So:
       WAITX ##20_000_000
    
    is translated automatically by the assembler into something like
       AUGS #(20_000_000)>>9  ' put these high bits into the source field of the next instruction
       WAITX #(20_000_000)&$1ff ' immediate bits are augmented by previous instruction
    

    This two instruction sequence will wait for 20 million cycles.

    (Note there was a typo in Cluso's original post, the instruction is "WAITX" and not "WAIT")

    Double # is pretty handy, particularly in hubexec code, but one does have to be aware that it takes an extra instruction.
  • rjo__ wrote: »
    in PNUT this works:
    dat 
    org
    
    	dirh #24
    	outh #24
    myend
    	jmp #myend
    

    if you plug your "Control" addon board at #24

    but this doesn't:
    dat 
    org
    
    	dirh #56
    	outh #56
    myend
    	jmp #myend
    

    The leds on the Eval boards are active low. Use OUTL #56 instead.
  • rjo__rjo__ Posts: 2,114
    LMAO:)
  • BeanBean Posts: 8,129
    Thanks for the help guys.
    Here is what I ended up with...
    ' Blink LED on P2 EVAL Board (64000-ES)
    ' NOTE: LEDs on Eval board are inverted. (LOW=on, HIGH=off)
    
    CON 
    blinkpin = 56            ' Pin to blink (56 to 63)
    
    DAT org
      ' Setup
      hubset  clkinit1       ' Setup for 250MHz clock
      waitx   delay5msec     ' Allow to stabilize
      hubset  clkinit2       ' Switch to 250MHz clock
    
      dirh #blinkpin         ' Make pin an output
    
      ' Main Loop
    main
      outl #blinkpin         ' Make pin low (LED on)
      waitx delay1sec        ' Delay
    
      outh #blinkpin         ' Make pin high (LED off)
      waitx delay1sec        ' Delay
    
      jmp #main              ' Loop forever
    
    clkinit1   LONG %1_000001_0000011000_1111_10_00  '20MHz/2*25*1 = 250MHz (setup)
    clkinit2   LONG %1_000001_0000011000_1111_10_11  '20MHz/2*25*1 = 250MHz (active)
    delay5msec LONG 20_000_000 / 200                 ' 5mSec @ 20MHz
    delay1sec  LONG 250_000_000                      ' 1 second @ 250MHz
    

    Bean
  • Cluso99Cluso99 Posts: 18,069
    edited 2019-11-19 16:40
    Bean,
    Why don’t you let the compiler do the work, and its easier to see too?

    clkinit1 long 25_000_000 / 2 * 25 * 1 ‘250MHz???
    clkinit1 long 20_000_000 / 2 * 25 * 1 ‘=250MHz

    And BTW thats not 250MHz, its 312.5
  • evanhevanh Posts: 15,192
    Go easy there Cluso. Bean is only just starting. He'll pick up the tricks as he reads more.

    You haven't exactly got it right yourself! I don't see any reference to 25 MHz in Bean's code.

  • Cluso99Cluso99 Posts: 18,069
    @evanh
    Thats what I get from using an iPhone where I cannot see everything on a big screen :(
    It was 20MHz here
    clkinit1 LONG %1_000001_0000011000_1111_10_00 '20MHz/2*25*1 = 250MHz (setup)
    which is of course 250MHz

    However, now I can see the whole thing better...

    @Bean,
    Take a look at the P2 Tricks and Traps thread for a better way to setup the P2 clock.
Sign In or Register to comment.