Shop Learn
How do you set Pullup/Pulldown? — Parallax Forums

How do you set Pullup/Pulldown?

I can't make heads or tails out of the documentation. I would think setting this is simple enough.

On STM products there is a separate register just for pullup/pulldown that you set for each GPIO pin. One and done.

It looks like on the P2 I have to find the correct bit position or something or enable smart pin.

Searching the documentation for Pullup reveals nothing.

Think I have to use the WRPIN instruction and figure out what "D/# = %AAAA_BBBB_FFF_PPPPPPPPPPPPP_TT_MMMMM_0" means.

All I can make out is there is a lot of P.

Mike

Comments

  • JonnyMacJonnyMac Posts: 7,389
    edited 2020-12-31 15:43
    I would think setting this is simple enough.
    It is.
    It looks like on the P2 I have to find the correct bit position or something or enable smart pin.
    Thankfully, the compiler has constants to simply that stuff.

    If you want to add a pull-up
      wrpin(pin, P_HIGH_15K)
      pinhigh(pin)
    

    Pull-down:
      wrpin(pin, P_LOW_15K)
      pinlow(pin)
    

    PASM:
                    wrpin     ##P_HIGH_15K, pin
                    drvh      pin
    
                    wrpin     ##P_LOW_15K, pin
                    drvl      pin
    
  • There it is again. Where are all those P_ constants documented?

    I'm writing in C so I need to bit bang it.

    Mike
  • If you're using FlexProp, Eric has most of Chip's constants included. The constant names are in the Spin2 compiler document.

    https://docs.google.com/document/d/16qVkmA6Co5fUNKJHF6pBfGfDupuRwDtf-wyieh_fbqw/edit#heading=h.1h0sz9w9bl25
  • It looks like the value should be if I want to set pin 32 to 1.5k pullup?

    A input selector = 0 (true)
    B input selector = 0 (true)
    AB input logic = 0
    Pin A logic input = 1, C = 0 (live), I = 0 (not inverted), 0 = 0 (not inverted output), H = 1, (1.5k high), L = 7 (float), T = 0, M = 0 (smart pin off).

    0b00000000000000100000111100000000

    Mike
  • JonnyMacJonnyMac Posts: 7,389
    edited 2020-12-31 20:44
    I'm not a C programmer (when it comes to the Propeller). The Spin compiler constant for a 1.5K pullup is %0000_0000_000_0000000001000_00_00000_0. It seems logical to create a constant for that value and then use it with the _wrpin() (in FlexProp) function.

    Edit: Per Ray's comment (below) -- if you're using FlexC -- you can do this:
        _wrpin(32, P_HIGH_15K);                                     // select pull-up
        setpin(32, 1);                                              // activate pull-up
    

    That said, you should probably reach out to your compiler vendor for confirmation.

    Suggestion: Since you're using C which is not the native language of the Propeller, you may want to include the language and compiler you're using in the thread header so that people who do know that product can assist. Not everybody reads every thread, but I know guys like Eric and Ross are very good at supporting the people using their compilers.
  • RaymanRayman Posts: 11,806
    edited 2020-12-31 20:10
    Here's how did pullups in FlexSpin C:
    	//Enable internal pullups
    	_wrpin(pin_rtc_scl, 0b001000 << 8);
    	_wrpin(pin_rtc_sda, 0b001000 << 8);
    

    But, I think FlexSpin now has all the Spin2 constants for these things.
    So, you could probably replace the "0b001000 << 8" with some constant from the Spin2 docs...

    BTW: Pullups and pulldowns are strange on P2... The resistors are sorta between the high or low voltage and the pin. So, in order for the above to work you need to drive the pins high too.
  • I have just tested it and yes, you can use the predefined constants for smart pins in FlexSpin C.
      _wrpin(32, P_HIGH_1K5);
      _pinh (32);
    
    Rayman wrote: »
    BTW: Pullups and pulldowns are strange on P2... The resistors are sorta between the high or low voltage and the pin. So, in order for the above to work you need to drive the pins high too.
    Well, not really "strange" but different. The pullup/down resistors are NOT between the supply voltage or ground and the pin (in parallel to the output) but in SERIES to the output. So by selecting a resistor value you actually select the drive strength of the output driver. You can also select current sources instead of voltage+resistor if you like.

    And if you know this it is also clear that you have to set the pin as output to activate the pullup or pulldown resistor. Of course you can still use the same pin as input.
  • So, what your saying is that you set the pin as a weak output pin so that it can be bent to be high or low by the output device it's connected to.

    That makes a lot of sense.

    I think I'll stick with a resistor to 3.3v. It's simpler.

    Mike
  • The internal pull-ups do work; I've tested them with buttons, I2C devices, and 1-Wire devices. You just need to set the pull-up strength and then apply 3.3v to the top of the pull-up by making the pin high.
  • Rule of thumb: Use external resistors if the state of the pin is critical during boot-up. For example, if an output is driving a relay that controls a motor you definitely don't want to have it floating until your software can drive it to a known state.

    For inputs you can safely use the internal pullups or pulldowns. They don't cost money nor board space and adding a line or two to the code is faster than using the soldering iron. And the state of the pin doesn't matter until you are ready to read it.
  • JonnyMacJonnyMac Posts: 7,389
    Rule of thumb: Use external resistors if the state of the pin is critical during boot-up.
    Absolutely agree. Great point.
  • Peter JakackiPeter Jakacki Posts: 10,024
    edited 2021-01-02 03:03
    I recently used the internal pullups on the I2C bus simply because I wanted to avoid the placement of an external pullup network too close to an optional connector. The good thing is that you can "program" the resistor in software and I like to use a 1k5 pullup for high-speed I2C.
    In TAQOZ to use a 1k5 pullup and CMOS sink on both I2C pins I can specify it like this:
    56 2 PINS   1K5 PULLUP    CMOS SINK    SETPIN
    

    The 56 2 PINS sets the pin range to operate on plus it also clears the pinmode variable then 1K5 PULLUP sets the appropriate bits in that variable as does CMOS SINK and so SETPIN writes that to the selected pins.
  • Hi

    Thought I would try some I2c code on prop2. Jon has indicated that P_HIGH_1K5 and other constants have been defined for doing this and used with wrpin() and indeed work in flexbasic. (nice one Eric)
    BUT- how did you find this information? I have looked at every document I could find on the website, done searches but to no avail. Only by looking at other peoples code do I find examples. I feel like I am pecking around trying to pick up crumbs of information from other peoples code. Its time consuming, irritating and only covers that particular situation- other options are hard to find. Can someone point to easily understood documentation on the subject please.
    WAIT!- Just found about 10 posts earlier in this thread Jon posted-

    OK, that's great! BUT I'm not a spin programmer, nevertheless its very useful.

    I guess its hidden away in Chips P2 google document- but I've crawled painfully through it and couldn't find it and trying to search on the document doesn't work.

    The P2 is great but fathoming it out is not.

    I guess I just have to be patient until someone writes an "idiots guide to the prop2"
    (didn't have this problem with the prop1 but then I was late on the scene- and it is a LOT simpler)

    Dave


  • @tritonium ,

    I guess I'm in the same boat. Came late to the P1 which was great since all the C stuff was well on it's way.

    Now with the P2 it's all about SPIN right now. Thankfully Eric has done a great job at getting C going.

    Google docs are good and I have them bookmarked for easy reference.

    Download the propeller tool just to get more documentation.

    Mike
  • RaymanRayman Posts: 11,806
    tritonium wrote: »
    I guess its hidden away in Chips P2 google document- but I've crawled painfully through it and couldn't find it and trying to search on the document doesn't work.

    The pullups are part of the Smart Pin... The table in the docs (see below) shows how to set them.
    I guess it doesn't help that they are labelled here as M bits for some reason when described earlier as P bits...
    1245 x 915 - 193K
  • @Rayman ,

    Right, I was trying to read that table but it is in blue and very small and confusing. It has a column with Pin A out but then it talks about input? Then there is HHH and LLL which I assume mean Pull High or Pull Low.

    Then there is Fast and Float? Is Fast a dead short?

    Mike
  • Hi

    Well yes- but that's not all there is- this is a snip from the spin document Jon referred me to-
    much more readable.

    Dave
    1052 x 772 - 177K
  • JonnyMacJonnyMac Posts: 7,389
    edited 2021-01-02 18:42
    Right, I was trying to read that table but it is in blue and very small and confusing.
    It is, which is why I refer to the constant names in the Spin2 document. Check the section called Built-in Symbols For Smart Pin Configuration.

    I don't know what documentation you have for the compiler you're using, but it seems that those constants should be listed there, too.
    Then there is Fast and Float? Is Fast a dead short?
    Fast is direct output from the pin driver. Float is the disconnecting the pin driver (e.g., when using an external pull-up/pull-down)
  • @JonnyMac,

    I use FlexProp for my C programming which is working well. No documentation about the P2 other than the basic functions.

    Have to refer to the SPIN documents or Google documents in general.

    Mike
  • JonnyMacJonnyMac Posts: 7,389
    Eric seems very accommodating for those using his compiler. Perhaps you can ask him to list the P2 constants that are defined by Chip for Spin2/PASM2.
  • dgatelydgately Posts: 1,406
    iseries wrote: »
    I use FlexProp for my C programming which is working well. No documentation about the P2 other than the basic functions.
    Have to refer to the SPIN documents or Google documents in general.
    For flexprop, I see "p_high_1k5" defined only in flexprop/spin2cpp/frontends/lexer.c
    { "p_high_1k5", SYM_CONSTANT, 0x800 },
    
    Probably not too difficult to dump the lexer definitions into a doc for C programmers.

    dgately

  • As long as there the same as the ones documented in SPIN2 I can just use that for my documentation. Knowing where to find stuff is the biggest problem right now.

    Based on the instruction set of the P2 it's going to take some time to document them.

    Mike
Sign In or Register to comment.