PDA

View Full Version : PortA Doesn't Work



Melanie
- 15th July 2004, 12:55
PortA Doesn't Work
Parts of PortE do not work
I can't transfer my program from a PICF84 to a PICF628


PortA Doesn't Work

Oh yes it does. It might need to be switched ON for Digital use though.

Whilst you weren't looking, Microchip have been busy stuffing the PICs full of goodies. Some of these goodies are ANALOG interface parts. A/D Convertors (eg 16F876) or Comparators (eg 16F628), or even BOTH (eg 16F877A and 12F675). Mostly (but not always), the Analog hardware is multiplexed with PortA (and PortE).

By default, on many PICs which have these Analog parts, when the PIC powers up, it defaults into Analog mode (the controlling Registers are usually set to zero) – which is why you can't do Digital I/O until you set that port into Digital mode.


If your PIC has Comparators…

Then the Comparators are most likely controlled by the CMCON Register. This is most common thing that is overlooked by people transferring programs over from one PIC to another (for example from a 16F84 to a 16F628).

CMCON=%00000111

Will normally switch the Analogue Comparator pins to Digital I/O mode. (CMCON=$07 or CMCON=7 will do the same thing). Go check with your PICs Datasheet to see what setting the CMCON Register to this value does.


If your PIC has A/D Convertors then…

The A/D Convertors are controlled usually by the ADCON1 Register (again check with your PICs datasheet – eg it’s ANSEL with the 12F series).

ADCON1=%00000111

Will normally switch the Analogue A/D pins to Digital I/O mode. (ADCON1=$07 or ADCON1=7 will do the same thing). Go check with your PICs Datasheet to see what setting the ADCON1 Register to this value does.


If your PIC has BOTH A/D Convertors and Comparators…

The you’ll need to set both ADCON1 and CMCON appropriately.

Example 1 - if you have a 12F like a 12F675, then

ANSEL=%00000000
CMCON=%00000111

Is the sequence for you.

Example 2 - if you have a 16F628 then all you need is...

CMCON=%00000111

Example 3 - if you have a 16F876 or 16F877 then this one is for you...

ADCON1=%00000111


ALWAYS check the correct Register settings for your own needs, by looking in the Comparator Section, and/or the A/D Converter Section in your PICs Datasheet.

Melanie

mister_e
- 12th April 2008, 21:25
Maybe some may also download the following PDF and keep it handy somewhere in their PC.

Common 8-Bit PIC® Microcontroller I/O Pin Issues (TB3009)
http://ww1.microchip.com/downloads/en/AppNotes/93009A.pdf

RussMartin
- 17th April 2008, 18:03
Maybe some may also download the following PDF and keep it handy somewhere in their PC.

Common 8-Bit PIC® Microcontroller I/O Pin Issues (TB3009)
http://ww1.microchip.com/downloads/en/AppNotes/93009A.pdf

I've not only downloaded and printed TB3009, I've attached Melanie's post to it!

Thanks to both of you!

bluestar84
- 29th January 2010, 13:29
and for 18f4620 it`s ADCON=00001111 isnt it? do you do that right after tris initialsation or after?

mackrackit
- 29th January 2010, 13:39
I do not have the data sheet with me but if you have the correct register and all it should be
ADCON=%00001111

rmteo
- 29th January 2010, 16:31
and for 18f4620 it`s ADCON=00001111 isnt it? do you do that right after tris initialsation or after?

From the data sheet:

19.0 10-BIT ANALOG-TO-DIGITAL CONVERTER (A/D) MODULE

The Analog-to-Digital (A/D) converter module has
10 inputs for the 28-pin devices and 13 for the 40/44-pin
devices. This module allows conversion of an analog
input signal to a corresponding 10-bit digital number.
The module has five registers:
• A/D Result High Register (ADRESH)
• A/D Result Low Register (ADRESL)
• A/D Control Register 0 (ADCON0)
• A/D Control Register 1 (ADCON1)
• A/D Control Register 2 (ADCON2)

sbobowski
- 12th April 2010, 20:30
I've not only downloaded and printed TB3009, I've attached Melanie's post to it!

Thanks to both of you!

In the 5 Min it took me to read this thread started by Melanie in 2004 & the PDF referenced by mister_e.
you have solved:

I now understand how to read and make sense out of the Microchip data sheets.
using the PIC16F628A I understand what CMCON=7 is actually CMCON=%00000111 (which is binary for 7, and $07 is hexadecimal. lol you think a programmer of as many languages as me would have picked that up, shows I'm still a rookie in my career)
How registers work and how to set them
And many more things


This post is a great aid in going from playing with PBP to being confident in the ability of having a task and completing it.
Thank you

Melanie
- 13th April 2010, 02:00
There's nothing nicer than knowing the time spent in posting something has been of help - even after all the years. *smiles*

Heckler
- 13th April 2010, 16:04
Thanks Melanie,

That is a good troubleshooting doc to have on hand and review.


And as sbobowski noted it is much easier for a newbie to understand why/how to set a particular register if it is depicted as a binary value.

ie. cmcon = %00000111 instead of =07, Since each bit has a unique function, showing it in binary rather than hex or dec is easier for me to understand.

Thanks
Dwight

Melanie
- 13th April 2010, 16:24
Some folks think in Binary, some in Decimal, other in Hexadecimal.

I like Binary (when dealing with say up to 8 bits), because in my mind it immediately relates to those BIT positions in the PICs Registers.

It doesn't matter what you use, or if you chop and change throughout your code, the compiler doesn't care - it's there just for YOUR convenience.

The biggest confusion is when folks come along and say "What's inside the BYTE - is it Decimal or Hex or Binary?". It takes some explaining to convince people the answer is YES - It's ALL OF THOSE simultaneously! It's simply a matter of how you perceive it YOURSELF.

If you wanted to extract say just BIT 5 out of a BYTE... what's easier to visualise what is going on...

Example A.

NewByte=OldByte & %00100000

or...

Example B.

NewByte=Oldbyte & 32

or...

Example C.

NewByte=Oldbyte & $20

All three examples are EXACTLY the same. Use whichever one turns you on.

shahidali55
- 9th May 2012, 14:43
Another option to set PortA to digital automatically is Darrel's "AllDigital.pbp" . It will set the required registers on the selected device to make PortA digital and there is also a provision to see which registers have been set by the "All Digital" include.
http://www.picbasic.co.uk/forum/showthread.php?t=11100
I have used this in almost all of my 16F designs.

Art
- 8th September 2015, 19:41
Port A works, it’s port A bit 4 that doesn’t work lol! :D