Help on PORTB


Closed Thread
Results 1 to 6 of 6

Thread: Help on PORTB

  1. #1

    Default Help on PORTB

    I made this short 2min video with my question. If anybody can answer it, I will greatly appreciate it.


  2. #2
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: Help on PORTB

    RMW problem...
    Add resistor to leds, it might help.
    Last edited by pedja089; - 11th January 2013 at 21:18.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,519


    Did you find this post helpful? Yes | No

    Default Re: Help on PORTB

    Hi,
    Most likely read-modify-write issue as peja089 says.

    If you remove the LEDs and measure the voltage on the pins you'll see that they all goes "high" and close to 5V (if that's your powersupply voltage). If you put the LEDs back you'll get the phenomenon you see and if measure the voltage you'll see that it's no longer 5V due the LED clamping the voltage.

    A LED operate on current and produce a certain voltage drop across it. You must put a resistor in series with the LED to "set" the correct current. Simply wiring the LED to the PIC output pin like that does indeed light up the LED but the output voltage of the PIC will be clamped by the forward voltage drop of the LED which, depending on the color might be somewhere between 1.8 and 2.1V.

    Now, for an input to be concidered "high" the voltage at the pin must be atleast 2V when the power supply voltage is 5V. Why does it matter, you're not using any inputs?
    It matters because when you do HIGH PortB.2 the PIC reads all the bits in PortB into an internal register, it then sets bit 2 of that register "high" and finally writes the register back out to PortB (Read-Modify-Write). Because the voltage of the output pin is being clamped by the forward voltage drop of the LED the PIC reads that pin as low thus setting the output low when it writes back the internal working register to the port.

    So, it's a hardware problem, not a software bug.

    /Henrik.

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Help on PORTB

    Added resistors and its still doing it.

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,519


    Did you find this post helpful? Yes | No

    Default Re: Help on PORTB

    Great, now the hardware is sorted.
    On this chip there are analog functions (the ADC and comparators) on PortB, these are turned on by default.
    When reading a pin that is configured as analog it will be read as low resulating in the same behaviour as before. To enable the digital functionality on all the pins add the following at the beginning of your program:
    Code:
    ANSEL = 0
    ANSELH = 0
    /Henrik.

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: Help on PORTB

    Yes that fixed it.. thanks

Similar Threads

  1. Can't set portb.0 low
    By spcw1234 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 16th February 2012, 14:44
  2. Replies: 6
    Last Post: - 12th March 2011, 13:11
  3. Interrupt portb
    By tazntex in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 18th August 2008, 21:05
  4. Portb = % ???
    By xobx in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 23rd July 2007, 17:03
  5. PORTB vs PORTB.0
    By xzolian in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 4th March 2007, 00:33

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts