There is no sure fire way to solve this problem with a pot. This is because there will always be a point where you are on the hairy edge of the ADC switching and the smallest disturbance (i.e.: noise) will push you over the edge. The best you can do is to implement some hysteresis. In other words you switch the value on the LEDs from N to N+1 when you see ADRESHL go from N*16 to N*16+1. However, to go in the other direction you wait for ADRESHL to go all the way down to N*16-1 before switching back to N on the LEDs. This can be implemented as follows: forever: NewADRESH = ADRESH if NewADRESH > PrevADRESH then LEDS = NewADRESH >> 4; else LEDS = (NewADRESH + 1) >> 4; endif PrevADRESH = NewADRESH end forever loop Bob Ammerman RAm Systems leds to ge r ----- Original Message ----- From: "Spehro Pefhany" To: Sent: Saturday, July 26, 2003 9:45 PM Subject: Re: [PIC]: ADC, Pot, need help > At 09:33 PM 7/26/2003 -0400, you wrote: > >Here's the setup: PIC16F872's ADC pin, PORTA pin 0, connected to a 1 Meg > >Ohm pot. Four LEDs provide output. > > > >Here's the requirement: use the pot to select one of 16 values, 0 to 15 > >with the output being the 4 leds...a 4 digit binary number. All i do is > >shift the 8 most significant bits (from the ADRESH, left aligned so 8 most > >sig are in adresh with the two least sig in ADRESL) right four times so i > >keep the four most significant digits which i directly output to the LEDs. > > > >Here's the problem: when the pot is directly between two numbers, and left > >untouched, the pic will flicker between the two values because the pot i > >suppose doesn't give a steady output. This isn't allowed. I've tried > >adding a "debounce" where i wait to see if a value is held for 10 or 20 > >times before switching the display, but all it seems to do is slow the > >flicker down. Any experience or suggestions? Thanks everyone... you have > >no idea how much this community has helped me. > > Switch the pot for a lower value one (40K maximum, so maybe a 20K pot). > > 10K is the maximum input impedance. > > Best regards, > > Spehro Pefhany --"it's the network..." "The Journey is the reward" > speff@interlog.com Info for manufacturers: http://www.trexon.com > Embedded software/hardware/analog Info for designers: http://www.speff.com > > -- > http://www.piclist.com hint: PICList Posts must start with ONE topic: > [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads > -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads