> Here's the setup: PIC16F872's ADC pin, PORTA pin 0, connected to a 1 Meg > Ohm pot. Total impedence driving an A/D pin should be 10Kohm or less. It should, in theory, work with the low accuracy you are asking for, but I would use a 10Kohm 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. It's easier than that: dbankif adresh ;make sure bank set for ADRESH access swapf adresh ;get high result nibble into low W andlw h'F' ;mask in only the 0-15 result > Here's the problem: when the pot is directly between two numbers, and > left untouched, the pic will flicker between the two values As expected. It's called "noise", and can never be totally eliminated. > because the > pot i suppose doesn't give a steady output. Even if it did, there are other noise sources. > 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. Again as expected. You need to add some hysterisis. You are currently just truncating the integer part of the number. That means, for example, that your decision threshold (using decimal numbers for easier visualization) is between 12.99 and 13.00. The problem is that this is the threshold in both directions. You emit 13 whenever the value is 13.00 to 13.99. If you are already at 13, then don't switch to any other number as long as the input value is 12.75 to 14.25. Let's say the pot got cranked upwards, and it crossed over 14.25. Now you emit 14 and the decision thresholds become 13.75 and 15.25 ***************************************************************** Embed Inc, embedded system specialists in Littleton Massachusetts (978) 742-9014, http://www.embedinc.com -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics