Shop OBEX P1 Docs P2 Docs Learn Events
How to enable a Pullup — Parallax Forums

How to enable a Pullup

John AbshierJohn Abshier Posts: 1,116
edited 2019-03-07 20:20 in Propeller 2
With help of the forum I have a pulldown working but have hit the wall on pullups. The magic line for pulldowns was
                  'LLL
        wrpin   ##%010_00_00000_0,pin '15k pulldown

I tried the following not so magical line
                     'HHH LLL
           wrpin   ##%010_000_00_00000_0,pin '15k pullup
[
That didn't work. I always got a low reading from the pin. If I didn't try to set the pullup, I got serveral lows, then several highs ...
Here is my test code
CON
            
    oscmode = $010c3f04               'standard stuff
    freq    = 160_000_000
    baud = 230400                     'must configure RUN command to match this
    thepin = 40

OBJ
    ser: "PrintfSerial"     'access to Propellor output (output only)
    pins: "Pins2.spin2"
var

pub main | pinInput
    clkset(oscmode, freq)
    ser.start(baud)                  'start up serial terminal
    waitcnt(freq * 2 + cnt)
    ser.str(string("Pullup Pulldown Input test"))
    ser.nl
    pinInput := In(thepin)
    ser.str(string("Nothing Set pin = "))
    ser.dec(pinInput)
    ser.nl
    SetPullup(thepin)         ' if not called varies high and low if called always low
    repeat 
        waitcnt(clkfreq / 10 + cnt)
        pinInput := In(thepin)
        ser.str(string("Pullup Set pin = "))
        ser.dec(pinInput)
        ser.nl
    repeat
            
PUB In(pin) : state

   asm
      testp     pin            WC
if_c  addx      state, #0 
   endasm    
PUB SetPullup(pin)   '************* not working
    asm              'HHH LLL
           wrpin   ##%010_000_00_00000_0,pin '15k pullup
           dirh    pin
    endasm
    
PUB SetPulldown(pin) 'tested with Control Board and worked
    asm           'LLL
        wrpin   ##%010_00_00000_0,pin '15k pulldown
        dirh    pin
    endasm

Comments

  • Mark_TMark_T Posts: 1,981
    edited 2019-03-07 20:38
    outh pin? Not used the modes yet, but I'm guessing they are implemented as alternate driver fets of
    higher channel resistance? If so you'd need to enable the output high side to get pullup
  • I think, in addition to setting dirh high, you also need to set outa (or outb) high for that pin. I think that will do it

    For the pulldown, you were setting dirh high correctly to enable the driver and resistor, but benefiting from Outa defaulting to low. For pullup you'll actually need to set outa.

    I can't check right now though
  • evanhevanh Posts: 15,915
    Yes, when OUT is high then HHH is in effect, when OUT is low then LLL is in effect.
  • I am confused here by OUTx high - you can not set up pins for input and select a pullup or pull down?

    Mike
  • evanhevanh Posts: 15,915
    IN independantly provides the digital input state. If OUT is set high but the pin is electrically held low then reading IN will tell you so.
  • P'raps we could have some synonyms for DIR and OUT for the cases when using internal pullups and downs. I sure feel funny saying DIRH to enable an input.
  • evanhevanh Posts: 15,915
    Input sense is never disabled. IN is updated every clock cycle whether you want it or not. It's another example of parallel functions provided by hardware.
  • evanhevanh Posts: 15,915
    edited 2019-03-08 18:44
    The Prop1 works the same way. EDIT: Here's a mock-up of pin#0 for Prop1 pin control:
    Screenshot_20190309_074248.png
    943 x 437 - 28K
  • The confusion arises on P2 because when the smart pin is enabled, DIR and OUT no longer directly affect what is happening at the actual pin, as they do on P1. Thus the weirdness of setting DIRH to make the pin an input -- the smart pin logic is preventing the OUT signal from actually reaching the pin, but it does provide bias voltage for the pullups and pulldowns.
  • outh    pin
    
    makes it work. I thought I understood (at least for P1) DIR, OUT, IN. I would pay good, hard earned money for the following book: "Propeller 2 Smart Pins Explained with Examples"

    My project is to write an object to provide BS2/Arduino functionality/simplicity. So far I have Hi, Low, Toggle, In, Set Pullup, and Set Pulldown. I need to rewrite Hi, Low, Toggle using fastspin's builtin's to save a clock over by inline assembly.

    John Abshier
  • evanhevanh Posts: 15,915
    Yep, smartpins are another area again. Both the pin config and smartpin mode setting are done with the same config word, so I can see the two getting lumped together. In this case, the smartpin is not involved.

    To tell if a smartpin is on or off then check the %MMMMM bits. If all zero then no smartpin, anything else and you have a smartpin active.
  • evanhevanh Posts: 15,915
    Of the full config word, %AAAA_BBBB_FFF_PPPPPPPPPPPPP_TT_MMMMM_0, only %MMMMM is specifically for smartpins.
    - A, B and F are general digital input config. These stand independent.
    - T is digital output config although it interacts with both P and M.
    - M is smartpin mode. Lots to learn here ... but learn it for one pin and you know them all. :)
    - P is all about the custom pin controls. Configuring sense types and drive strengths, pin feedback and other little details, DAC and ADC have their own setup here too. The details of each bit can change depending on T and M.
Sign In or Register to comment.