#1 Rule if things act inconsistantly: CHECK TRIS BITS. I can't begin to count how many times I've had problems like yours and it's been because I had an input as an output and vice versa. nick@veys.com / www.veys.com > -----Original Message----- > From: pic microcontroller discussion list > [mailto:PICLIST@MITVMA.MIT.EDU] On Behalf Of Jai Dhar > Sent: Tuesday, January 14, 2003 10:09 PM > To: PICLIST@MITVMA.MIT.EDU > Subject: [PIC]: 16f877 A/D stability > > > Hello, > > Have a question about the A/D on the 16f877. I gave my first > shot on coding a simple converter that uses a divider from a > pot as an input to one of the pins. Now I'm pretty sure I > have my code set right, because when I read the results (I > did about 5 test cases), they all seem pretty accurate, > except with a few problems. > > Some of the pins had constantly a constantly changing voltage > that was registering on my DMM. Most of the pins would be > stable, either ~0 or 5.2V, but some of them, each on > different tests, would be fluctuating, sometimes from > 2.5-2.9V, and sometimes other values. Is this normal? Does > the fact that my program keeps going in a loop affect this > (even though I'm reading the Go/! Done flag to check when > it's done)? And it seems to be different pins each time, so > there doesn't appear to be a definite pattern. On some > readings, all the pins are perfect. Any ideas? > > Thank you, > > Jai > > PS: Just in case, I have my Code below. > > clrf TRISB ;Set all of Port B and D to outputs > clrf TRISD > > movlw 0xff > movwf TRISA > > movlw 0x0E ;Set Justification and set RA0 as the > only analog input > movwf ADCON1 > > > bcf STATUS, RP0 ;Switch back to Bank 0 > > movlw 0xC1 ;Select A/D on, Channel 0 and RC Clock > movwf ADCON0 > > movlw 0x00 > movwf PORTB ;initialize the ports to a blank value. > movwf PORTD > > Start1 > > > bsf ADCON0, GO ;Start the A/D. > Loop1 > btfsc ADCON0, GO > goto Loop1 > > ;Finished The A/D conversion > > movf ADRESL, 0 ;Move the low byte into Port B (B<7>:B<6>) > movwf PORTB > > movf ADRESH, 0 ;Move the high byte into Port D (D<7>:D<0>) > movwf PORTD > > > goto Start1 ;Start it all over again. > > > > > > ---------------------------------------- > This mail sent through www.mywaterloo.ca > > -- > http://www.piclist.com hint: The PICList is archived three > different ways. See http://www.piclist.com/#archives for details. > -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body