Searching \ for '[PIC]: TRISA and ADCON1' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ios.htm?key=adc
Search entire site for: 'TRISA and ADCON1'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: TRISA and ADCON1'
2001\06\14@012702 by Tony Pan

picon face
Hi all, I need help.

I am using PIC16C73 chip. I need RA0 to be analog input but all others as
digital outputs.

In order to have RA0 as analog input, I must set ADCON1 = 0x4 (RA0, RA1, RA3
as analog inputs). But since I want others (RA1-RA7) to be digit outputs,  I
must set TRISA = 0x1.

But I observed that the RA1 and RA3 outputs, (which are supposed to be
analog inputs had not for the TRISA statemen,) are funny. On my board, those
two pins output pulses instead of straight lines of high or low. Other pins
(RA2, RA4-RA7) output lines -- which is correct.

Seems to me the two statements ADCON1=0x4 and TRISA=0x1 cause confusions on
the outputs of RA1 and RA3.

I loked up the data book of PIC16C7x. Section 13.3 "Configuring Analog Port
Pins" (Page 121) states:

"The ADCON1, TRISA, TRISE registers control the operation of the A/D port
pins. The port pins that are desired as analog inputsmust have their
corresponding TRIS bits set (input). If the TRIS bit is cleared (output),
the digital output level (VOH or VOL) will be converted."

Who can explain to me what the last sentence means? What does it mean by
"the digital output level (VOH or VOL) will be converted"?

More directly, how do I set RA0 as analog input but others (RA1-RA7) as
digital output?


Thanks.
Tony

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body


2001\06\14@024039 by Tony Nixon

flavicon
picon face
Tony Pan wrote:
{Quote hidden}

If a pin is set as analog, but the TRIS is set as an output, when you
read from the pin it will return with a zero value.

If you are using BSF, BCF instructions on PORTA the analog pins will
read as zero and this value will be written back to the output latch.

It is better to write to a shadow register and write that value to
PORTA.

> Who can explain to me what the last sentence means? What does it mean by
> "the digital output level (VOH or VOL) will be converted"?

If you did an anlog conversion on an analog pin with the TRIS bit set as
zero, the converted value will be either 0 or 255, corresponding to
Logic 0 and Logic 1 which is whatever the output state is.


--
Best regards

Tony

mICros
http://www.bubblesoftonline.com
.....salesKILLspamspam@spam@bubblesoftonline.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body


2001\06\14@091818 by Jeff DeMaagd

flavicon
face
----- Original Message -----
From: Tony Nixon <.....Tony.NixonKILLspamspam.....ENG.MONASH.EDU.AU>

> > Who can explain to me what the last sentence means? What does it mean by
> > "the digital output level (VOH or VOL) will be converted"?
>
> If you did an anlog conversion on an analog pin with the TRIS bit set as
> zero, the converted value will be either 0 or 255, corresponding to
> Logic 0 and Logic 1 which is whatever the output state is.

If there is a load on the output pin and you do an A/D on that pin one might
actually find a state between 0 and 255.  Microchip's data sheets need very
thoughrough reading as the line about making all the associated TRIS bits
set as input is just a line dropped in the text somewhere.  It's definitely
there but it's too easy to skim across it.

Jeff

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email EraseMElistservspam_OUTspamTakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body


2001\06\14@110823 by Tony Pan

picon face
Thank you for the reply.

But I don't do ADC on the output pin RA1. I just want to output RA1 to a
constant high. But it seems that ADCON1 has an effect on it despite the fact
that I set TRISA1 to 0.

Question: how do I set RA0 to analog input and RA1 to digital output?


{Original Message removed}

2001\06\14@111439 by Tony Pan

picon face
Thank you for the reply.

>>>> If a pin is set as analog, but the TRIS is set as an output, when you
read from the pin it will return with a zero value.

If I want to write to the pin, will I get a good constant high or low
(depending the value I want to output to)? Is that possible?

{Original Message removed}

2001\06\14@120937 by Bob Ammerman

picon face
When a pin is analog (as defined by the setting of ADCON1) certain circuits
are effectively rewired in the chip.

Specifically, the pin is disconnected from the digital input circuitry. This
is so that a non-logic-level signal on the pin won't cause excessive current
in the digital input circuit.

There is an unfortunate side affect of this...

Whenever an instruction like "BSF PORTA,3" or "XORWF PORTA,F" the PIC reads
the entire port, makes the necessary changes, and writes the result (this is
called read-modify-write logic).

Now if your pin is defined by ADCON1 as an analog, but is TRIS'd to be an
output, then the PIC will always read it as a zero. This will mess up the
next read-modify-write operation.

Here is a concrete example:

Assume RA3 and RA4 are set up as analog inputs according to ADCON1, but as
digital outputs by TRIS.

Lets see what a few instructions will do:

   clrf    PORTA

This will zero the entire port A latch, including driving RA3 and RA4 low.

   bsf    PORTA,3

This will read the port A digital input receivers, turn on bit 3 and write
the result. For our example, the receivers willl be getting whatever is on
the actual pins, except for those bits that are ADCON1'd as analog inputs.
These pins will give us a zero. Thus, this instruction will properly turn on
RA3.

   bsf    PORTA,4

Here is where the trouble starts. Again the PIC will read the digital input
receivers, turn on bit 4 and write the result. For our example, the
receivers will be getting the pin values, except for RA3 and RA4. Thus, the
value seen by the PIC will hae a zero for RA3. It will turn on
bit 4 and write the result back to the port. Note that this will turn RA3
off!

The standard solution to this is the limit all writes to PORTA to MOVWF
instructions. Thus, no read-modify-write problems can occur.

For example:

   CBLOCK 0x??
       PORTA_MIRROR
   ENDC

   bsf        PORTA_MIRROR,3
   movf    PORTA_MIRROR,W
   movwf    PORTA

   bsf    PORTA_MIRROR,4
   movf    PORTA_MIRROR,W
   movwf    PORTA

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)



ired{Original Message removed}

2001\06\14@134245 by Tony Pan

picon face
Thank you.

Now everything makes sense to me. That's why I see my output being pulses
instead of a flat line.

So, to make RA0 an analog input and RA1 a digital output is possible if we
manage to write the output to the whole port instead of individual pins. Am
I right?

I have another approach: set ADCON1 when I do the RA0 reading, and reset
ADCON1 to all digital once the RA0 reading is done. Then I can freely output
to RA1 and other pins.

My program don't require me to read RA0 all the time.

Do you see any potential problems with this approach?

Thanks,
Tony Pan

{Original Message removed}

2001\06\14@180542 by Olin Lathrop

face picon face
> Question: how do I set RA0 to analog input and RA1 to digital output?

With the proper ADCON1 setting.  I don't know what PIC you are using, but on
the 16F876 for example, the ADCON1 setting of xxxx1110 configures RA0 as an
analog input and the other potential analog pins as digital I/O.


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, olinspamspam_OUTembedinc.com, http://www.embedinc.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email @spam@listservKILLspamspammitvma.mit.edu with SET PICList DIGEST in the body


2001\06\14@233609 by Bob Ammerman

picon face
----- Original Message -----
From: "Tony Pan" <KILLspamweidong.panKILLspamspamVERIZON.NET>
To: <RemoveMEPICLISTTakeThisOuTspamMITVMA.MIT.EDU>
Sent: Thursday, June 14, 2001 1:39 PM
Subject: Re: [PIC]: TRISA and ADCON1


> Thank you.
>
> Now everything makes sense to me. That's why I see my output being pulses
> instead of a flat line.
>
> So, to make RA0 an analog input and RA1 a digital output is possible if we
> manage to write the output to the whole port instead of individual pins.
Am
> I right?

Yes you are.

> I have another approach: set ADCON1 when I do the RA0 reading, and reset
> ADCON1 to all digital once the RA0 reading is done. Then I can freely
output
> to RA1 and other pins.
>
> My program don't require me to read RA0 all the time.
>
> Do you see any potential problems with this approach?

Yes, if the signal actually connected to RA0 is analog you will get extra
current consumption in the digital input circuitry on the pin when the
voltage is near the digital threshold.

How much? I don't know.

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)

{Quote hidden}

(this
> is
> > called read-modify-write logic).
> >
> > Now if your pin is defined by ADCON1 as an analog, but is TRIS'd to be
an
> > output, then the PIC will always read it as a zero. This will mess up
the
> > next read-modify-write operation.
> >
> > Here is a concrete example:
> >
> > Assume RA3 and RA4 are set up as analog inputs according to ADCON1, but
as
> > digital outputs by TRIS.
> >
> > Lets see what a few instructions will do:
> >
> >     clrf    PORTA
> >
> > This will zero the entire port A latch, including driving RA3 and RA4
low.
> >
> >     bsf    PORTA,3
> >
> > This will read the port A digital input receivers, turn on bit 3 and
write
> > the result. For our example, the receivers willl be getting whatever is
on
> > the actual pins, except for those bits that are ADCON1'd as analog
inputs.
> > These pins will give us a zero. Thus, this instruction will properly
turn
{Quote hidden}

RA3
{Quote hidden}

the
{Quote hidden}

to
> > > > > Logic 0 and Logic 1 which is whatever the output state is.
> > > >
> > > > If there is a load on the output pin and you do an A/D on that pin
one
> > > might
> > > > actually find a state between 0 and 255.  Microchip's data sheets
need
{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spamBeGonelistservSTOPspamspamEraseMEmitvma.mit.edu with SET PICList DIGEST in the body


More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...