trouble getting certain pins to act as digital on 18F2550


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: trouble getting certain pins to act as digital on 18F2550

    Hi,
    I am not sure what you mean by "consecutive bit-operations on the port registers" and I would like to learn.
    What I mean is when you do things like this:
    Code:
            outb1 = 0
            outb2 = 0
            outb3 = 0
            outb4 = 1
    There's been plenty of discussions on Read-Modify-Write effects that can occur when you do things like that so very brief:
    When you're accessing a bit in a register the complete register is read, the bit in question is set/cleared and the register is written back. When you do this to the PORT register there is a possibillity that the voltage at the pin accessed in the previous operation hasn't reached steady state yet and that it's logic level isn't (yet) corresponding the what you told it to - so when the port is READ it reads the wrong value for that bit and therefor the wrong value gets written back to the port.

    The same thing can occur when pins used as digital outputs are left in analog mode. They usually (always? (verify against the datasheet)) read as logic '1' so you can write a 0 to the port register and the pin will go low but then the next time you do a bit operation on that port that '0' will be read as '1' and it'll be written as '1' so the pin changes state.

    EDIT: Using the LAT register(s) works the same way (all registers do) but it is the port LATCH and not the ACTUAL port that is being read-modified-written so it doesn't matter if the actual output is loaded down or whatever. You still need to take care of the analog functions though - you should always do that.

    /Henrik.

  2. #2
    Join Date
    Jan 2010
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Re: trouble getting certain pins to act as digital on 18F2550

    I set all the analog capable pins to digital using ADCON1 as you suggested and it all works great now. I thought that disabling the A/D in ADCON0 would do it but apparently that enables or disables the analog to digital "conversion".

    Is there anything I can do about the RMW effect or do I just need to be aware of it? If I pause after every pin state write my program will be too slow.

    I appreciate your help. We are getting some of your Swedish weather here in NE Missouri today. No thanks for that.

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


    Did you find this post helpful? Yes | No

    Default Re: trouble getting certain pins to act as digital on 18F2550

    I set all the analog capable pins to digital using ADCON1 as you suggested and it all works great now. I thought that disabling the A/D in ADCON0 would do it but apparently that enables or disables the analog to digital "conversion".
    No, that would be too easy ;-) What it does is enable/disable the AD converter itself. Whenever a pin doesn't seem to work like it's supposed to think analog and dig thru the datasheet. I'd say 9 times out of 10 the problem is that the pin is configured for analog mode when its intended use is digital.

    Is there anything I can do about the RMW effect or do I just need to be aware of it? If I pause after every pin state write my program will be too slow.
    Like I said, using the LAT registers instead of PORT registers "isolates" the internal logic from the pins them selves which stops the RMW effects. So, whenever you're doing "bit-flips" on port pins on a device that HAS LAT-registers - use them.

    With that said, are you still suffering from RMW now that you've got the pins properly configured?

    appreciate your help. We are getting some of your Swedish weather here in NE Missouri today. No thanks for that.
    You're welcome, to the help AND to the weather - please keep it ;-)

    /Henrik.

Similar Threads

  1. PIC 18f2550 USB joystick TROUBLE (burnt PIC?)
    By jsags1 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th October 2014, 19:06
  2. analog to digital setup on 18F2550
    By missouri100 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 20th February 2014, 14:49
  3. 16F1826 cannot get MCLR to act as an INPUT
    By SOTASOTA in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 13th February 2014, 02:31
  4. Analog pins for digital input
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 9th September 2005, 00:32
  5. Microchip MCP41xxx Digital Potentiometer Code Trouble
    By CocaColaKid in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 31st August 2005, 18:21

Members who have read this thread : 0

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