trouble getting certain pins to act as digital on 18F2550


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2010
    Posts
    10

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

    I have some code written that drives a stepper motor based on an encoder input. Actually there are two sets of encoder/stepper running on the same PIC. Their operation is totally independent. The outputs are going to a L298N stepper driver in both cases. Two of the outputs don't appear to be working as I would like them. RA3 and RA5 do not put out enough voltage for the L298N to recognize them as being on. If I connect leds to the outputs instead of the L298N they will very dimly light when they are on. This allows me to verify that the code is working properly. All the rest of the outputs light the same led/resistor combo brightly. The only significant info I can glean out of the data sheet is that on a POR those two, and only those two, on porta come up as analog. I am trying to set those pins to outputs in the code but maybe I need to be something else because of the way the operate on a POR.

    I also could never get RB1 and RB0 to act as outputs. After I moved those outputs to RB6 and RB7 everything worked fine. The only significant thing I can find on those two pins is they are associated with serial programming. I am apparently not getting those pins configured properly.

    My code and wiring diagram are attached.

    any help or suggestions?
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

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

    Hi,

    First, check the ADCON1 register (it's commented out in your code) and the CMCON register (not included in your code) against the datasheet and make sure all pins used as digital are setup as digital.

    Second, you're doing a lot of consecuitive bit-operations on the port registers which, depending on pin loading and oscillator speed, can suffer from RMW-effects. Since you're on an 18F part try changing the aliases from PORT-register to LAT-register for all pins acting as outputs.

    Third, I'm surprised RB6 and RB7 is working properly as outputs since you have their corrsponding TRIS bits set (ie pins are inputs).

    /Henrik.

  3. #3
    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 read that about the LAT vs PORT but hadn't ran across that before so I was a little scared to mess with it. I may have something wrong in my original post about the RB6 and RB7 pins because, as you say, it shouldn't work - but it does.

    I am not sure what you mean by "consecutive bit-operations on the port registers" and I would like to learn.

    thanks for the feedback

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    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.

  5. #5
    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.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    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.

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

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

    watch the video in this link , it explains the whole issue
    http://www.microchip.com/webinars.mi...cName=en556253

  8. #8
    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

    It is all working good.

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, 20:06
  2. analog to digital setup on 18F2550
    By missouri100 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 20th February 2014, 15: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, 03:31
  4. Analog pins for digital input
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 9th September 2005, 01:32
  5. Microchip MCP41xxx Digital Potentiometer Code Trouble
    By CocaColaKid in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 31st August 2005, 19:21

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