Help with basic pin toggling via smart pins

DavidZemonDavidZemon Posts: 2,700
edited 2019-01-13 - 02:03:08 in Propeller 2
My first foray into the smart pins is attempting to flash an LED. It seems mode 10 should be simplest, but I can't get it to work with the following code.

I'm trying to blink four different LEDs here: 56 via basic software loop, 57 slower via basic software loop, 58 via manually triggered interrupt and (the problem pin) 59 via smart pin. 56, 57, and 58 are all working great, but no light from 59.
CON
    LOOP_COUNT = 10
    PERIOD = 65535
    UINT_MAX = 4294967295
    MODE = $2A ' tt=01 and mmmmm = 00101

dat	org
    hubset  #0

init
    mov ijmp1, #my_fancy_isr

    dirl #59
    wrpin mode, #59
    wxpin period, #59
    wypin uintMax, #59
    dirh #59

blink
    waitx   ##1_000_000
    drvnot  #58
    djnz index, #blink

    trgint1
    drvnot #57
    mov index, #LOOP_COUNT
    jmp #blink

my_fancy_isr
    drvnot #56
    reti1

index   long    LOOP_COUNT
period  long    PERIOD
uintMax long    UINT_MAX
mode    long    MODE

If my math is right, this should yield 300ish Hz LED. Well... not ideal for an LED, but I have my scope hooked up and have been double checking it there.

These smartpins are very cool in how powerful they are, but yowzer are they complicated! What an amazing number of configuration options!
David
PropWare: C++ HAL (Hardware Abstraction Layer) for PropGCC; Robust build system using CMake; Integrated Simple Library, libpropeller, and libPropelleruino (Arduino port); Instructions for Eclipse and JetBrain's CLion; Example projects; Doxygen documentation
CI Server: http://david.zemon.name:8111/?guest=1

Comments

  • Mode value appears to be incorrect
        MODE = %01_00101_0 '=$4A
    

    and try moving the WYPIN instruction to after the DIRH instruction.
        dirh #59
        wypin uintMax, #59
    
    Melbourne, Australia
  • ozpropdev wrote: »
    Mode value appears to be incorrect
        MODE = %01_00101_0 '=$4A
    

    and try moving the WYPIN instruction to after the DIRH instruction.
        dirh #59
        wypin uintMax, #59
    

    Thanks! I tried wypin after dirh at some point in my testing, and I found the incorrect TT bits after posting.... but I didn't go back and try swapping the dirh after fixing TT.
    David
    PropWare: C++ HAL (Hardware Abstraction Layer) for PropGCC; Robust build system using CMake; Integrated Simple Library, libpropeller, and libPropelleruino (Arduino port); Instructions for Eclipse and JetBrain's CLion; Example projects; Doxygen documentation
    CI Server: http://david.zemon.name:8111/?guest=1
  • period  long    PERIOD
    mode    long    MODE
    

    IMHO the labels in PNUT are case insensitive, so you should get an error if the constant and the register have the same name.

    Andy
  • You're right, gives an error with FastSpin.
    Prop Info and Apps: http://www.rayslogic.com/
  • DavidZemonDavidZemon Posts: 2,700
    edited 2019-01-13 - 17:37:21
    Ariba wrote: »
    period  long    PERIOD
    mode    long    MODE
    

    IMHO the labels in PNUT are case insensitive, so you should get an error if the constant and the register have the same name.

    Andy

    Thanks for the heads up. I'll keep that in mind for future programs.

    @Dave Hein, I don't know if you want to care to implement that "feature" or not, but there appears to be a language discrepancy since the p2gcc package compiled this program quite happily.
    David
    PropWare: C++ HAL (Hardware Abstraction Layer) for PropGCC; Robust build system using CMake; Integrated Simple Library, libpropeller, and libPropelleruino (Arduino port); Instructions for Eclipse and JetBrain's CLion; Example projects; Doxygen documentation
    CI Server: http://david.zemon.name:8111/?guest=1
  • By default, p2asm works like PNut, and is case insensitive. However, p2asm has a -c option that tells it to be case sensitive. This mode is used with p2gcc since C programs are case sensitive.
  • Dave Hein wrote: »
    By default, p2asm works like PNut, and is case insensitive. However, p2asm has a -c option that tells it to be case sensitive. This mode is used with p2gcc since C programs are case sensitive.

    Ohhh, quite clever. And I am, indeed, using the -c option in my Makefile for building .spin2 files. Now I know why :)
    David
    PropWare: C++ HAL (Hardware Abstraction Layer) for PropGCC; Robust build system using CMake; Integrated Simple Library, libpropeller, and libPropelleruino (Arduino port); Instructions for Eclipse and JetBrain's CLion; Example projects; Doxygen documentation
    CI Server: http://david.zemon.name:8111/?guest=1
  • RaymanRayman Posts: 9,457
    edited 2019-01-13 - 23:13:42
    I just need to figure this out too, in order to generate a pixel clock for LCD...

    Here's a little test program that uses smartpin to blink P56.
    Used scope to measure frequency with different settings, see comments.

    Prop Info and Apps: http://www.rayslogic.com/
  • Hi @Rayman

    IMHO, there is a small typo at your SPIN2 code, as follows:
    _XTALFREQ     = 20_000_000                        ' crystal frequency
    _XDIV         = 10                              rystal divider to give 1MHz
    _XMUL         = 125                                       ' crystal / div * mul
    

    Won't the comment should say:
    _XDIV         = 10                           ' crystal divider to give 2 MHz
    

    Henrique



  • ok, fixed...
    Prop Info and Apps: http://www.rayslogic.com/
  • evanhevanh Posts: 6,964
    edited 2019-01-14 - 01:44:03
    I had the same copy of comments. I've now edited mine to just be descriptive:
    	_XTALFREQ     = 20_000_000                              'PLL stage 0: crystal frequency
    	_XDIV         = 2                                       'PLL stage 1: crystal divider
    	_XMUL         = 25                                      'PLL stage 2: crystal / div * mul
    	_XDIVP        = 1                                       'PLL stage 3: crystal / div * mul / divp (1,2,4..30)
    
    "There's no huge amount of massive material
    hidden in the rings that we can't see,
    the rings are almost pure ice."
Sign In or Register to comment.