Menu

internal pull up resistors

Help
viscomjim
2015-01-31
2023-06-03
  • viscomjim

    viscomjim - 2015-01-31

    Is there a way to configure the internal pull up resistors on the pic?

    Thanks!!!!

     
  • kent_twt4

    kent_twt4 - 2015-02-01

    Yes of course. GCB does a lot of things, but if you don't see a particular function in the help file, it is likely not addressed. Take a stroll to the GPIO/Additional Pin Functions section of your device data sheet, to get info on the WPU register.

    So this comes under the heading of manual settings. On more complicated projects, this can happen a lot. And, familiarity with data sheet and the device.dat file becomes necessary. Set the pin direction to input, and then enable by setting the weak pullup bit, WPU1=1, WPU2=1, or?

     
  • viscomjim

    viscomjim - 2015-02-02

    I checked the data sheet for the pic12f1840 and there is the WPUA: WEAK PULL-UP PORTA REGISTER for the 6 i/o pins A0-A5. So bits 0-5 can be a 1 or a 0 (1 being enable weak pull up).

    So are you saying the syntax for this would be...

    #CHIP 12f1840, 32
    
    DIR PORTA.0 IN
    DIR PORTA.1 IN
    DIR PORTA.2 IN
    DIR PORTA.3 IN
    DIR PORTA.4 IN
    DIR PORTA.5 IN
    
    WPU0=0
    WPU1=1
    WPU2=1
    WPU3=0
    WPU4=0
    WPU5=1
    
    REST OF PROGRAM...
    
    END
    
     
  • kent_twt4

    kent_twt4 - 2015-02-02

    Syntax looks good, except you would use your specific 12f1840 pull up register bits (my example was for a 12f683). When addressing the register bits individually, you only need to initialize those pins in the register that are used. Say you had input buttons on PortA, and wanted just pins 1,2,5 to be pulled up then:

    Dir PortA.1 In
    Dir PortA.2 In
    Dir PortA.5 In
    
    WPUA1 = 1
    WPUA2 = 1
    WPUA5 = 1
    

    But sometimes it is easier to visualize, and as a shorthand way to code, when setting the whole register :

    TRISA = b'00100110'    'pins 1,2,5 as inputs
    WPUA =  b'00100110'    'pins 1,2,5 pullups enabled
    
     
  • viscomjim

    viscomjim - 2015-02-03

    Excellent!!! Thanks for your help on this. Is there anywhere you can point me where this type of information is documented so I can learn this stuff without bothering everyone?

    For instance, why would setting direction be
    DIR PORT A.1 IN

    and pull ups not be
    WPUA.1 = 1

    How do you find this type of syntax information?

     

    Last edit: viscomjim 2015-02-03
  • kent_twt4

    kent_twt4 - 2015-02-03

    Keep asking away, it's not a problem. Always nice to see if the Help file, or forum, has been searched prior to posting. The data sheets can be a bit intimidating for those just starting, but are invaluable.

    If you breadboard your 12f1840, or have some other development board, it is easy to link together the basic concepts (adc, uart, I2C, etc.) thru small experiments. Using an empirical approach is a good one I think.

     
  • kent_twt4

    kent_twt4 - 2015-02-03

    The assembler allows you to address it both ways. So it comes down to a preference, or a coding practice? Their are bit names for register values that are not as obvious as when dealing with the Port(s).

    Take the Fixed Voltage Reference (FVR) module for instance. This comes in handy for battery operations when the Vdd varies over time and the need for an accurate adc reference. One wants to conserve battery capacity so it's a good idea to put the device to sleep before the next adc measurement. Toggling the FVRCON, FVREN bit before sleep gives reduces energy requirements prior to sleep.

    'So enable the FVRCON module
    FVRCON.7 = 1    'Or, Set FVRCON.7 On
    'Or
    FVREN = 1    'Or, Set FVREN ON
    ...
    ...
    ...
    'And disable FVRCON before setting device to sleep
    FVRCON.7 = 0
    'Or
    FVREN = 0
    
    'So which way is easiest to remember?
    

    A look to Help/Variable Operations/Set command deals with variable.bit (On/Off).

     
  • Dmitry

    Dmitry - 2023-06-03

    it is easier to visualize
    Basic uses its own syntax. If it has its own definition of port pins direction, pullup should be defined with same, like manner. For example dir pin out|in|pullup. I seem.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.