----- Original Message ----- From: "Tony Pan" To: 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) > Thanks, > Tony Pan > > ----- Original Message ----- > From: "Bob Ammerman" > To: > Sent: Thursday, June 14, 2001 11:55 AM > Subject: Re: [PIC]: TRISA and ADCON1 > > > > 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 ----- > > From: "Tony Pan" > > To: > > Sent: Thursday, June 14, 2001 11:04 AM > > Subject: Re: [PIC]: TRISA and ADCON1 > > > > > > > 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 ----- > > > From: "Jeff DeMaagd" > > > To: > > > Sent: Thursday, June 14, 2001 9:13 AM > > > Subject: Re: [PIC]: TRISA and ADCON1 > > > > > > > > > > ----- Original Message ----- > > > > From: Tony Nixon > > > > > > > > > > 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 listserv@mitvma.mit.edu with SET PICList DIGEST in the body > > > > > > > > > > > > > > -- > > > http://www.piclist.com#nomail Going offline? Don't AutoReply us! > > > email listserv@mitvma.mit.edu with SET PICList DIGEST in the body > > > > > > > > > > -- > > http://www.piclist.com#nomail Going offline? Don't AutoReply us! > > email listserv@mitvma.mit.edu with SET PICList DIGEST in the body > > > > > > -- > http://www.piclist.com#nomail Going offline? Don't AutoReply us! > email listserv@mitvma.mit.edu with SET PICList DIGEST in the body > > -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body