Shop OBEX P1 Docs P2 Docs Learn Events
pins question — Parallax Forums

pins question

DAT
entry   
                    org         0
base             rdlong    base, ptra++
reg1             rdlong    reg1, ptra++
buts             rdlong    buts, ptra++
led1             rdlong    led1, ptra++
                    dirh        led1
                    drvl        led1
                    setq        #3
                    wrpin      ##%010_00_00000_0,#12 '15k pulldown
                    setq        #3
                    drvl         #12
                           
loop             testp       #12   wc
        if_c      drvh        #led1
                    jmp        #loop

                    ret
Can anyone see where this code is failing?

Comments

  • evanhevanh Posts: 15,192
    edited 2020-12-09 16:15
    Ignoring any potential wrong values for PTRA and what it loads, if you've got the WRPIN as a pull-down according to the comment then the DRVH needs to be DRVL. Err, sorry I got that wrong.

    There's no clear answer as there's too many unknowns about the inputs, your intent and wiring of the LEDs. There's lots of undefined values there. What appears to be failing for you?

  • The hardware is the Accessory pushbutton board attached to pins 8-15.
    The push button does not work. Based on what I've read it should.
  • The smartpin does not work as it should.
    The led does, if directly driven. But detection of the button(to drive the led) is not recognized.
  • In spin it works fine, so its not hardwire!
  • RaymanRayman Posts: 13,897
    I don't think there should be a "#" in this line:
    if_c      drvh        #led1
    
  • Ok, tried that, Your right no # before the var. but the led lit immediately, without button being pushed,
  • now this is weird. ran it again(no changes) it does not light
  • RaymanRayman Posts: 13,897
    What are those setq instructions for?
  • If I power cycle and flash the led comes on immediatly. Reflash and it goes out, stays out till I power cycle or press reset.
    This lights every time with no button pushed
    if_nc       drvh      led1
    
  • Supposedly setq lets the wrpin use pin#12 as a basepin and also set the next 3 pins

  • if_z        drvh      led1
    
    This finally worked.
    I need to find the instruction that clears the smart pin. It seems to keep its setting thru a reset
  • RaymanRayman Posts: 13,897
    edited 2020-12-09 23:40
    There is no clear, you can only set it.
    But, you can disable it with "DRVL". by setting DIR low on that pin
  • RaymanRayman Posts: 13,897
    bambino69 wrote: »
    Supposedly setq lets the wrpin use pin#12 as a basepin and also set the next 3 pins

    Interesting... That usage is not in the instruction spreadsheet, but it is mentioned in the "Design Status" section of the Docs (but nowhere else).

    I think it is really not needed though, because you can include it into the next instruction and thereby save an instruction. Think you would just add a "3<<6" to the source terms...
  • JonnyMacJonnyMac Posts: 8,927
    edited 2020-12-09 18:19
    You could create a pin group to handle this. In my Spin driver for the control board, I set it up like this:
    pub start(basepin)
    
    '' Initialize IO for P2-ES Control PCB
    '' -- basepin in is low pin of group used
    
      base := basepin                                               ' save base
    
      ledpins := base addpins 3                                     ' leds are base..base+3
      pinclear(ledpins)                                             ' clear smart pins
      pinlow(ledpins)                                               ' set leds low (off)
    
      btnpins := base+4 addpins 3                                   ' buttons are base+4..base+7
      wrpin(btnpins, P_LOW_15K)                                     ' select 15K pull-downs
      pinlow(btnpins)                                               ' activate pull-downs
    

    If I was going to move this to a PASM2 cog, I would pass the base pin (so that I could move the board) and then do this:
                    mov     ledpins, basepin                        ' create leds group
                    or      ledpins, #(3 << 6)
                    fltl    ledpins                                 ' clear smart modes
                    wrpin   ledpins, #0
                    drvl    ledpins                                 ' start off
    
                    mov     btnpins, basepin                        ' create buttons group
                    add     btnpins, #4
                    or      btnpins, #(3 << 6)
                    fltl    btnpins
                    wrpin   ##P_LOW_15K, btnpins                    ' set to pull-down mode
                    drvl    btnpins                                 ' enable pull-downs
    
  • bambino69bambino69 Posts: 126
    edited 2020-12-09 21:17
    Thanks Rayman. No it's not in the spreadsheet, I got it from trips and traps. And it does work now. I was testing for the c flag and testp was setting the z flag.

    @JonnyMac Hopefully I can look over this during the live event tonight. I may have to use pinclear() as I don't see a pasm equivalent.
    I was using explicit pin #12 while debugging, It actually uses a basepin "buts". I took it out for the sake of the post.
  • bambino69bambino69 Posts: 126
    edited 2020-12-09 21:14
    @JonnyMac So the fltl clears the pins. Will try that after dinner
  • FLTL writes 0 to the DIRx bit(s) which will disable the smart pin modes, too. If you want to clear pins of possible smart pin configurations, use FLTL followed by WRPIN #0 to clear the modes. At this point, the pin is a standard, tristate IO pin.
  • Thanks Jon, Without it this is some really weird behavior
  • evanhevanh Posts: 15,192
    Yep, that WRPIN #0,pin clears out all the mode config bits and has to be explicitly done. Doing a COGINIT will reset OUT and DIR for that cog, but it won't impact the WRPIN mode configs as those live outside the cogs.
  • You can see that demonstrated in my version of FullDuplexSerial for the P2. The Spin interpreter cog sets up the RX and TX pins, then a background PASM cog simply shuttles bytes between the pins and the user buffers.
Sign In or Register to comment.