pic10f220 source
OK, now I understand what you need to do.
I think the easiest way is this: your ADC will provide a number from 0 to 255, depending on the position of the pot. That is 256 steps.
You require a certain number of steps, say 8 or 16. It's nice to keep them powers of two. Let's assume you need 16 steps.
So you create a delay routine that gives you the step delay, say 5ms. Call it Dly_5ms. All you need now is a counter that counts how many 5ms delays to insert and you load that counter with a number based on the pot position.
So take the ADC reading, divide it by 16 and you get a number from 0 to 15. in other words, if the ADC reading is between 0 and 15 the result is 0, if it's between 16 and 31 the result is 1, and so on.
Add to that number a constant, depending on wha the minimum delay should be. For instance, if you need a min delay of 5ms, add 1, if the minimum delays has to be 25ms, then add 5. Check the result of the addition to make sure the maximum is not exceeded. For example, if the maximum delay is supposed to be 50ms, then make sure the number is not greater than 10.
If you need another number of steps, just divide the ADC reading by something else. If you keep the number of steps powers of two then you can divide by rrf instructions (Don't forget to clear the C flag before each rrf). In this code I used a trick to divide by 16 faster, but that is another story.
If you set the MAX to be smaller than the max # of steps will allow, then you reduce the number of steps, but the last portion of the pot will not be usable. See in the code below that MAX is set to 10. That gives you only 10 steps, but they will still be squeezed in the lower portion of the pot, not spread out evenly.
Increasing MIN will also reduce the # of steps, leaving more of the upper portion of the pot unusable.
From my experience with the 10F220 I can say you can safely have 64 steps with this approach. Anything more will be prone to errors due to ADC noise.
I recommend you use a 10K pot connected directly from Vdd to GND and a 0.1uF cap right on the ADC input.
Code:
MIN EQU 1
MAX EQU 10
swapf ADRES,W ;get ADC reading, with nibbles swapped;
andlw 0x0F ;clear the upper 4 bits; these 2 instructions effectively divide by 16
movwf Counter ;save value in the delay counter
movlw MIN ;
addwf Counter,F ;ensure Counter has a minimum value greater than 0
movlw MAX ;now the checking
subwf Counter,W ;check if Counter is greater than MAX
btfsc STATUS,C ;if not, we are OK
goto Del ;and go do the delay
movlw MAX ;else force Counter to MAX
movwf Counter
Del: call Dly_5ms ;delay 5ms
decfsz Counter,F ;done?
goto Del ;if not, keep going
Done: ......... ;here do what you need after the programmable delay