Searching \ for '[PIC]: Gotcha - A2D pins' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: massmind.org/techref/microchip/ios.htm?key=a2d
Search entire site for: 'Gotcha - A2D pins'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Gotcha - A2D pins'
2000\08\29@181418 by Tony Nixon

flavicon
picon face
Hi all,

This may be a gotcha for the unwary - well, it got me anyway.

I thought setting A2D pins as outputs, like RA0 etc, would override the
A2D function of the pins, but this does not seem to be the case on the F
series.

I couldn't figure out why these instructions were not toggling bit 0
when I was testing some software on a 16F873 that I knew had worked
previouly on a 16C74.

  movlw 01h
  xorwf PORTA     <<  PORTA always = 1

After my hair turned a lighter shade of grey, it turned out to be the
ADCON1 setting.


Example: [16F873] ADCON1 = default = A2D pins enabled

set TRISA = 00h
set PORTA = FFh

read PORTA = 00h

I would have thought 2Fh, but not so.
However, it does work on a C74 that I have.


Example: [16F873] ADCON1 = 07h = all digital IO

set TRISA = 00h
set PORTA = 02h

read PORTA = 02h

As expected on both chips.


This may be a trap for Read/Modify/Write type instructions as it will
read all 0's and write them back to the port along with the modified
bit.

I suppose the bummer is when you have mixed A2D and digital pins set,
and because of the limited A2D configurations from ADCON1, that you must
have some analog pins set as digital outputs.


--
Best regards

Tony

ICmicro's
http://www.picnpoke.com
spam_OUTsalesTakeThisOuTspampicnpoke.com

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam@spam@mitvma.mit.edu>

2000\08\29@222736 by Plunkett, Dennis

flavicon
face
Yes this is correct! Also note that if you want ADC1 as an analogue port and
ADC0 as a digital this is not possible at the same time unless you turn off
the analogue stuff (PIC16C7710 and 12xxxx)


Dennis




> {Original Message removed}

2000\08\30@094517 by Barry King

flavicon
face
Tony and Dennis pointed out:

> Also note that if you want ADC1 as an analogue port and
> ADC0 as a digital this is not possible

> at the same time

But you can change ADCON and TRIS on the fly to switch pin functions.
For example, switch the port to all digitals, do some digital in
function, then switch on analogs to do an A/D reading.  Sometimes
that lets you use the pins as desired.

Its still a messy proposition- You have to be careful that you don't
leave a mid-range analog input voltage applied to a pin which is then
switched to digital input mode.  If you do, the input buffer will use
excess power becuase its held in the transition region.  When I tried
this, I made it work because I could be sure the analog input circuit
was powered down (and therefore a valid digital zero) when I switched
modes.

Regards,
------------
Barry King, KA1NLH
NRG Systems "Measuring the Wind's Energy"
http://www.nrgsystems.com
Check out the accumulated (PIC) wisdom of the ages at:
PIC/PICList FAQ: http://www.piclist.org

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
"[PIC]:" PIC only "[EE]:" engineering "[OT]:" off topic "[AD]:" ad's

2000\08\30@094730 by John

flavicon
face
Hello Tony & PIC.ers,

I fell foul of this too, I suspect everyone who has migrated
legacy 16c74 code to the 16f8xx parts has had the chance to
curse it.

Such folks might benefit from my own source-code fixup which allows me to
assemble for either 16c74, or the 16f877 which I'm using in this app. for
the ICD debugging capabilities.

Please excuse the lack of tab discipline <blame M$ outhouse>
in the following snippits:-


;******************************************assembler directives begin

#define pic16f877     ;choose  pic16c74 OR pic16f877, should be once only
                                       ;for whole file
      ifdef pic16c74
 #include <P16c74b.inc>      ;for 16c74 only
         list p=16c74b, r=dec
else
 #include <P16f877.inc>      ;for 16f877 only
         list p=16f877, r=dec
endif
     __config _CP_OFF &_PWRTE_ON &_XT_OSC &_WDT_ON ;normally used with
wdt_on
     errorlevel 1,-302 ;kill off page rp0 warnings
     errorlevel 1,-217

;******************************************assembler directives end


;*********************************************************initialisations
initialisation

;setup trisa, b, c, d, e
       bsf status,rp0
ifdef pic16c74
 movlf 11111111b, adcon1 ;16c74 setup adcon1 so that porta works digitally,
not analogly - 16c74 style
else
 movlf 11110111b, adcon1 ;16f877 only, setup adcon1 for 16f877 . NB NOT
like 16c74!!
endif
 movlf 00100000b, trisa
 movlf 11111101b, trisb

etc., etc.,  blah^2





{Quote hidden}

best regards,   John


e-mail from the desk of John Sanderson, JS Controls.
Snailmail:          PO Box 1887, Boksburg 1460, Rep. of South Africa.
Tel/fax:            Johannesburg  893 4154
Cellphone no:   082 469 0446
email:                .....jsandKILLspamspam.....pixie.co.za
Manufacturer & purveyor of laboratory force testing apparatus, and related
products and services.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
"[PIC]:" PIC only "[EE]:" engineering "[OT]:" off topic "[AD]:" ad's

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