A rant about port configurations


Closed Thread
Results 1 to 24 of 24
  1. #1
    Join Date
    Sep 2008
    Location
    Maine, USA
    Posts
    81

    Default A rant about port configurations

    I have a pet peeve about how Microchip writes their datasheets.

    I don't know about most folks, but the first thing that I need to know when I'm getting to know a new chip is what the default configurations are for the ports. Most of the time I don't need half the special features that come with the chip, I just need sufficient memory and lots of digital I/O. So I have to wade through hundreds of pages to try and figure out what the default configuration is for each port so I can disable the features that just get in the way of using the port for simple digital I/O.

    Why the heck can't they put a simple page in every spec sheet that lists what the POR config is per port? It would look something like this:

    PortA:
    All pins digital I/O
    PortB:
    All pins digital I/O with pull-ups enabled
    PortC:
    These special features are enabled....

    Is it just me, or does anyone else struggle with this issue?
    "Do or do not, there is no try" Yoda

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: A rant about port configurations

    I'm with you on this one. Every time I get a new chip I type in every register name (usually about a hundred), and look at each bit. I generally I wind up configuring all 800 bits, because I don't look at the POR defaults much, I just set them the way I need them. The whole process takes 4-5 hours, and is getting worse with some of the new "J" and "K" series parts. One upside - I learn a lot about the new part.
    Charles Linquist

  3. #3
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: A rant about port configurations

    I know I may ba a little wierd, but I like reading them. Admitedly I don't read the parts I never use, like ethernet and such. I usually zoom straight for the osc section after looking at the pinout section. From there I will read the example for each port I/O it usually tells me what needs setup to make it work. I like the charts that show each pin and what it can do, this way I know where to look to see if I need to set stuff.

    I HATE writing headers for the initial set up, hence my wish list item for a header wizard. I think it could knock your 4-5 hours down to 10 mins.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  4. #4
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: A rant about port configurations

    It should be possible for uChip or someone else to write such a wizard - maybe they already have. If I was really good at some 'useful' language like Java, I might try it myself. As it is, I'm going to have to wait for someone smarter than me to do it.
    Charles Linquist

  5. #5
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: A rant about port configurations

    I am on that list with you. But I don't agree with the useful part. You already know the most useful language - PBP. The rest can only make pretty pictures and parse text.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: A rant about port configurations

    I highly dislike the method of trying to initialize ALL the registers at the top of your program.
    Unless you know EVERYTHING about that chip, many of them get initialized incorrectly.
    This had led to more problems than any other issue.

    With the exception of comparators on the older chips ... Everything is turned OFF at power-up.

    All you have to do is turn ON the things you want to use.
    Don't try to turn everything off, they already are.

    Now the first thing people will say is ...
    Then why do I have to turn off analog pins with ADCON1 or ANSELx?

    It's because you aren't turning the Analog functions OFF, you are turning the Digital Inputs ON.
    Analog inputs are always ON, even when the Digital Input is enabled.

    So just concentrate on what you want the chip to do, not what you don't want it to do.
    DT

  7. #7
    Join Date
    Sep 2008
    Location
    Maine, USA
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: A rant about port configurations

    Wise words Darrell. I will keep that in mind.

    But I still think it would be nice if Microchip could add a simple chart showing the port defaults to their data sheets. It's the difference between implicit information and being explicit which is what the spec shhe should be all about
    "Do or do not, there is no try" Yoda

  8. #8
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: A rant about port configurations

    That information is already in the datasheet.
    For the 16F916 you are using, look at Table 2-1 (page 17)
    It has the POR/BOR and "Other" reset defaults for every register.
    DT

  9. #9
    Join Date
    Sep 2008
    Location
    Maine, USA
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: A rant about port configurations

    Yeah, but that table does not explicitly state the POR for each pin. It just lists what each pin CAN DO, not what it wakes up to without tweaking registers.
    I want a clear explicit list of the defaults, it would sure make my life simpler!
    "Do or do not, there is no try" Yoda

  10. #10
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: A rant about port configurations

    The two columns on the right of that table show the Power-On state of every bit in every register.

    The registers control the peripherals.
    The peripherals are multiplexed with the Pins.
    The peripherals are all OFF (except for comparators).
    The pins are tri-stated (OFF).

    What else do you need?
    Last edited by Darrel Taylor; - 20th October 2011 at 18:32.
    DT

  11. #11
    Join Date
    Sep 2008
    Location
    Maine, USA
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: A rant about port configurations

    I guess what I want is something more readable and less abstract. Sure that chart contains the info - but not in a very user friendly format. Maybe you (and others) find that chart fills your needs, it just does not work for me. But I will make a point of trying to study this chart in future.
    "Do or do not, there is no try" Yoda

  12. #12
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: A rant about port configurations

    So my header wizard should only flip the bits needed that are not correct on POR. Got it. Then will you like it?
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  13. #13
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: A rant about port configurations

    Tekart, I by no means ment to hinder your rant, ranting is fun sometimes. I do find it kinda funny that this thread shows very clearly what my wife has been saying for years - I don't need you to solve the problem, just listen to it!!

    So here you started ranting for what was clearly something very annoing for you, Charles jumped in with how he hate it, and how he deals with it. I threw in my 2 cents, but with more advice on how I deal with it. Then Darrel comes along and points out where the information you seek is located on the DS.

    I shudder to suggest this, but I can ALMOST see my wifes point (not admiting she ever has one mind you)
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  14. #14
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: A rant about port configurations

    Darrel, I see that you "highly dislike" my method. That's OK. My code still runs.

    It takes up code space, but I don't mess with chips with 1K of FLASH.
    I start out with a large list and eliminate lines as I need until I get it down to just what I need in the end. By the time I have used a chip 4-5 times, I'm left with 10 lines of configs or so. In the meantime, I have learned a lot about what the chip can do.
    Charles Linquist

  15. #15
    Join Date
    Sep 2008
    Location
    Maine, USA
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: A rant about port configurations

    Charles,
    I see Darrel's point. But in my case if I were to use your "shotgun" approach I would worry about accidentally setting up conflicting registers. In fact I just did that today. I thought I had set a port to all digital I/O by disabling comparators AND configuring the A/D properly, but I accidentally set a bit that I did not need to in the ADCON0 register and it took me an hour to see my error.

    cncmachineguy,
    Listening to the question is good, as is reading answers from Darrell.

    My wife and I have an agreement "I am always right - unless she's right"! What would we do with out our wives?
    "Do or do not, there is no try" Yoda

  16. #16
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: A rant about port configurations

    If I set up conflicting registers, my code doesn't run and I go back and fix them like I would anything else. I have had mysterious problems from time to time that were traced to the fact that I SHOULD have set a register, but didn't. Once everything is working,
    I carefully start removing the setups in small groups, all the while noting what the defaults are. If everything keeps on working, I
    can remove more at my pace. If not, I go back and see why. I use only about 4 chips. None of my headers contains more than about 10 lines of setup - now.
    Charles Linquist

  17. #17
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: A rant about port configurations

    My wife and I have an agreement "I am always right - unless she's right"!
    My approach is a little different:
    She is always right, and I am always happy. It took me many years to realize the reason men work is to be right sometimes. At home - just happy
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  18. #18
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: A rant about port configurations

    I really like Darrel's idea...at least with everything off, you know that you have to turn whatever you need on! (whereas at the minute even the stuff you want to turn on, might conflict with something else that's already turned on!)

    Over time (& with starting to get a grip of this stuff), I find myself turning most stuff off at the top of my program anyway.

    Would it be quick (or even possible) to do a 'switch off everything' header?

  19. #19
    Join Date
    Sep 2008
    Location
    Maine, USA
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: A rant about port configurations

    Quote Originally Posted by HankMcSpank View Post
    Would it be quick (or even possible) to do a 'switch off everything' header?
    Cool! I LIKE that. Darrell - does that sound feasible? Is it "just code"? I would totally value a header that disables ALL peripherals so I could knowingly start from a clean slate.
    "Do or do not, there is no try" Yoda

  20. #20
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: A rant about port configurations

    That's the point!
    Everything is already OFF.

    Except the comparators on old chips, which can be turned off easily with ...
    INCLUDE "AllDigital.pbp"
    But that also enables all Digital Inputs, so technically everything's not OFF anymore.

    Some REALLY OLD 12-bit chips made the T0CKI pin unable to control the TRIS bit while TMR0 was "OFF".
    So that's about the extent of the "Turn it all off" header wizard.

    ; if chip has a 12-bit core
    OPTION_REG.5 = 0 ; Free TRISIO.2 bit

    But then again, you're really turning something ON (TMR0).

    Don't worry about turning things OFF.
    Turn stuff ON if you want to use it.
    DT

  21. #21
    Join Date
    Sep 2008
    Location
    Maine, USA
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: A rant about port configurations

    Thanks for that Darrell. Thing is I only need to learn a new PIC every 12-18 months, so I tend to forget how to set them up. I had really never seen it as "everything is already OFF". As I blunder around a new spec sheet I get distracted by all the registers and features and tend to lose sight of the basics.
    Sometimes it takes someone like you to make the obvious clear. Like Charles, I tend to start off in shotgun mode and try setting all the registers. I see now that I have to think of the PIC as a blank slate (except for the comparators).

    I guess I should re-word my rant to: "Why the heck do PIC chips all come with the blasted comparators enabled by default!" That has always tripped me up in the past. I don't see the reasoning behind it personally. Never used the comparator feature in all my years of PICing (15 and counting). But then I'm a simple soul...
    "Do or do not, there is no try" Yoda

  22. #22
    Join Date
    Mar 2005
    Location
    Cocoa, Florida
    Posts
    42


    Did you find this post helpful? Yes | No

    Default Re: A rant about port configurations

    Great timing as this exact problem has just consumed about 5 hours and I seem to hit a similar brick wall with every new PIC.

    18F27J53 ~ outputs OK, inputs always read 0.
    I know what the problem is, just can't fix it. Is there something else besides ADCON that needs setting?

    Datasheet: ADON: A/D On bit 1 = A/D Converter module is enabled 0 = A/D Converter module is disabled
    Tried ADCON0 = $0F, ADCON0 = %00000000 and all the individual bits such as ADCON0.0 = 0.

    Instead of a rant at Microchip, this should be a programming project or feature request for the IDE.
    Heck, if I knew how to set ADCON, I'd program it myself...

  23. #23
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,520


    Did you find this post helpful? Yes | No

    Default Re: A rant about port configurations

    Hi,
    The ADCON register controls the the actual converter, not the input buffers of the pins. For the 27J53, check the ANCON0 and ANCON1 registers, page 371 in the datasheet.
    The ANCON0 and ANCON1 registers are used to configure the operation of the I/O pin associated with each analog channel. Setting any one of the PCFG bits configures the corresponding pin to operate as a digital
    only I/O. Clearing a bit configures the pin to operate as an analog input for either the A/D Converter or the comparator module. All digital peripherals are disabled and digital inputs read as ‘0’. As a rule, I/O pins that are multiplexed with analog inputs default to analog operation on device Resets.
    Looking up ANCON0 and ANCON1 in table 5.1 (page 76) shows that they default to all zeros at POR meaning that when the chip powers up all analog pins are analog.

    /Henrik.

  24. #24
    Join Date
    Mar 2005
    Location
    Cocoa, Florida
    Posts
    42


    Did you find this post helpful? Yes | No

    Default Re: A rant about port configurations

    Thanks, Henrik, that did it.
    I'll be back on this project in a couple of days and you saved a lot of brain hurt.
    Ken

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