Shop OBEX P1 Docs P2 Docs Learn Events
Help with basic pin toggling via smart pins — Parallax Forums

Help with basic pin toggling via smart pins

DavidZemonDavidZemon Posts: 2,973
edited 2019-01-13 02:03 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!

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
    
  • 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.
  • AribaAriba Posts: 2,690
    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
  • RaymanRayman Posts: 14,646
    You're right, gives an error with FastSpin.
  • DavidZemonDavidZemon Posts: 2,973
    edited 2019-01-13 17:37
    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.
  • 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 :)
  • RaymanRayman Posts: 14,646
    edited 2019-01-13 23:13
    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.

  • 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



  • RaymanRayman Posts: 14,646
    ok, fixed...
  • evanhevanh Posts: 15,916
    edited 2019-01-14 01:44
    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)
    
  • @Rayman

    Question please:

    mov x,##$0001_0000 'Toggle every 16 base period

    How did you figure this part out.

    Thanks
  • evanhevanh Posts: 15,916
    Looking at Rayman's ToggleSmartpin.spin2, the source comment "16 base period" looks to be at odds with the set parameter. I'm guessing the source comment is an out of date remnant. That set parameter will produce a toggle every 32768 periods I think, so 64k periods for output cycle.
  • cheezuscheezus Posts: 298
    edited 2019-08-10 22:03
    For generating clocks using smartpins, I've been doing this.. If you wanted the pin to toggle continuously you would just WYPIN #0 and comment out the last 2 lines.
        '%AAAA_BBBB_FFF_PPPPPPPPPPPPP_TT_MMMMM_0
                     ''PPPP_PPP_PPP_PPP
        'ppp        =''xxxx_CIO_HHH_LLL 
        sp_inv_pin  = %0000_001_000_000 << 8
        sp_clk      =   %01_00101_0 '+ sp_inv_pin ' inv clock right way
        byteclks    =   (2*8)  
    
    
    PRI GetBitTime(max_clkfreq) : bt
        bt :=((clkfreq / max_clkfreq) /2 )+1   ' SPI bit time
        if bt < 2                              ' make sure at least sysclock /2
            bt := 2
       
    ..
                dirl    c
                wrpin   #sp_clk,    c
                wxpin   bt,         c       'set base period (*2)  
                dirh    c    
                
    
                wypin   #byteclks,  c       'start clock
                rdpin   pa,         c                                     
        .busy   testp   c               wc
        if_nc   jmp     #.busy
    
    …
    
  • @evanh
    That confused me as I was using an adc calculator to try to figure it out. But where does the: ##$0001_0000 come from. I moved the one around and it changed the freq. I have been looking in docs don't immediatly see anything.
    Thanks.
    @cheezus
    Thanks I will use it and see what it does.
  • evanhevanh Posts: 15,916
    edited 2019-08-11 01:07
    The meaning of the parameter depends on the mode of the smartpin. Cheezus's chosen mode Chip has called transition. It is good for a stepping action, and it only has a base period and number of steps as its parameters.

    The mode Rayman chose Chip has called NCO frequency. This mode has base period, phase and cycle portion. It's a small brain twist to picture how the portion adding function (NCO) functions. You can think of the portion parameter as a fractional accumulate per base period, where a whole one is a Z accumulation of 2**32 to cycle the output ON then OFF again.

    So if X = $8000_0000, the half fraction, then every base period would toggle the output. And two base periods give a whole output cycle in this case.
Sign In or Register to comment.