Menu

Do I need pull-up resistors on inputs?

Help
2009-02-21
2013-05-30
  • Keith Renecle

    Keith Renecle - 2009-02-21

    Hi All,
    My project has the 12F675 PIC, and I was told not to bother about using pull-up resistors on the switchable inputs because the chips have weak pull-up resistors already. I built a new pc board without the resistors and it would not work until I added them. I checked the inputs and they are indeed low.

    I read the 12F675 data sheet, and it talks about weak pull-up resistors that are disabled when the GPIO pins are told to be outputs. Should they not then be enabled when they are directed to be inputs? Is there some code that I need to add on start-up, or must I just add the pull-up resistors? Thanks.

    Keith R

     
    • Santiago

      Santiago - 2009-02-21

      Hi Keith..
      In the datsheet: "GPIO port" chapter, you can find details about enable or disable individual pull-ups: WPU register.

      You also have to enable general pull-ups by clearig (=0) OPTION_REG,7 bit

       
    • Keith Renecle

      Keith Renecle - 2009-02-22

      Hi Santiago, I read the data sheet, and I suppose that if I could figure out the assembler codes, I could do as you say. Could you give me a short example in GCBasic code please? Thanks.

      Keith R

       
    • Santiago

      Santiago - 2009-02-22

      Yes.. it's just seting or clearing the bits you want:

      When you want to enable general pull-ups you have to set OPTION_REG.7 bit (datasheet page12), then you can do any of this ways:

      OPTION_REG.7 = 1

      set OPTION_REG.7 on

      OPTION_REG.GPPU = 1

      set OPTION_REG.GPPU on

      Or i think in GCBasic you can even do (not sure but you can try):

      GPPU = 1 
      set GPPU on

      You have pull-ups enabled, now you have to enable pull-ups in the pins you want, this is done in WPU register (datasheet page 20), if you want pull_up in GPIO.0 you have to set WPU.0, if you want pull_up in GPIO.4, then set WPU.4, if you want to disable pull_up in GPIO.2 then clear WPU.2 bit....

      Lets suppose you want pull_ups only in GPIO.0 and GPIO.2, you can set one bit then other bit, like this:

      set WPU.0 on
      set WPU.1 off
      set WPU.2 on
      ........
      ..........

      or you can use binary notation:

      WPU = b'00000101'

      You ca do the same for configue direction of pins (input/output) in TRISIO register(datasheet page 20):

      TRISIO = b'00000101'

      This sets GPIO.0 and GPIO.2 as inputs and all others as outputs

      Datasheet is not only for asm, you can set the value of any register in any languaje.
      Using binary notation you can set or clear the bits you want very easy, but this is not a must, you can also use decimal or hexadecimal, for example all these are the same:

      WPU = b'00010101'
      WPU = 21
      WPU = 0x15

      But in binary you can see what is happening with every bit.

      Regards.

       
    • Santiago

      Santiago - 2009-02-22

      Sorry... for enabling general pull-ups you need to CLEAR option_reg.7 bit:

      OPTION_REG.7 = 0

      not setting it as i said in previous post...

       
    • Keith Renecle

      Keith Renecle - 2009-02-22

      Thanks, I'll try this out and get back to you

       
    • Keith Renecle

      Keith Renecle - 2009-02-22

      O.K......I tried the code that you suggested, but it will not compile. It says "symbol not previously defined (GPPU)". This was using your code below:

      OPTION_REG.7 = 1 (I tried 0 as well)

      set OPTION_REG.7 on

      OPTION_REG.GPPU = 1

      set OPTION_REG.GPPU on

      I also tried:

      GPPU = 1 
      set GPPU on

      This also said something about a missing bit, so maybe I am not doing something correctly with your code?

       
    • Santiago

      Santiago - 2009-02-22

      Sorry... my explanations are not very clear...
      All what you need is:

      OPTION_REG.7 = 0
      WPU = b'xxxxxxxx' 'here goes 1 for pins you want pull-up, and 0 for all others

      _________________________________________________________
      _________________________________________________________

      Lets suppose you want pull_ups only in GPIO.0 and GPIO.2, then the WPU value is:

      WPU = b'00000101'

      If you want pull_up only in GPIO.4:

      WPU = b'00010000'

      if you want pull_up only in GPIO.1:

      WPU = b'00000010'

      if you want pull_ups in all inputs (all possible):

      WPU = b'00110111'

      ___________________________________________________________________________

      These are 4 diferent ways of doing the same thing, you have to choose only one:

      OPTION_REG.7 = 0

      set OPTION_REG.7 off

      OPTION_REG.GPPU = 0 

      set OPTION_REG.GPPU off 

       
      👍
      1
    • Keith Renecle

      Keith Renecle - 2009-02-22

      Hah! Now I understand. Thanks so much for your help and for explaining it so well now. I am slowly starting to understand some of these things......it just takes time, and I just want to get the project working, so I tend to be a little impatient! Here is what I tried from your suggestions:

      OPTION_REG.7 = 0
      set WPU.2 on
      set WPU.3 on
      set WPU.4 on

      I tried it out on my PC board, but then one of my pushbuttons is not working without the pull-up resistor. I did in fact then read the data sheet before I bugged you again (I'm getting good!) and I see that GPIO.3 has no pull-up resistor, so I will need to use another pin for this function. In the meantime, I will just add a resistor.

      Thanks very much once again. Step by step I will get there. Keep well.

      Keith R

       
    • Santiago

      Santiago - 2009-02-22

      Hi Keith... I'm happy that you got it working!

      And now datasheet has been useful for you as you find GPIO.3 is a different pin... this is an ussual thing in every PIC: pin dedicated to mclr is usually different to all others.

      Everything in the PIC is controlled by 8 bits registers, usually each bit of the register, controls if a feature is on or off, sometimes groups of bits, for example: CMCON register controls comparators, and CMCON 3 fisrt bits (0-2) are used to choose one of the 8 possible configurations.
      Is usual that some features need more than one 8bit register, for example ADC in pic16f675 uses ADCON0 and ANSEL registers.

      Sometimes having a look to the datasheet is a must, when you need a feature not supported by the compiler libraryes, or when you need doing it in a different way that compiler does.
      You can also create custom functions working as you need and add then to the "include" GCBasic folder then they will be available for any program you write.

      In the datashhet you can see every feature of the PIC... have a look!!... perhaps your PIC can do things you didn't know...  :)

      Greetings.

       
      ❤️
      1
    • Keith Renecle

      Keith Renecle - 2009-02-23

      Hi Santiago, thanks for the advice again. We had plenty of thunderstorm activity last night, so I shut down my PC, and took a break. I do generally read data sheets, but I need to start getting into working with PIC's at the basic level and using assembler, then I will start understanding how the structures work properly. I also need to do my projects, so I do a bit of both, and learn a little more each time. I put this off for many years(I'm 58 now)because it looked too complex for me. When I found GCBasic, and I managed to make things work, it inspired me to want to know more, and I would not have been able to do even this without the help from this forum. So thanks to you and the others that give such help to all of us out there. Be well.

      Keith R

       
      👍
      1

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.