PDA

View Full Version : "quantizing" AD values



dar303
- 21st February 2007, 20:04
Hi,

I'm looking for an easy way to take a 8 bit AD value read from a pot and have it divided into different "zones". This is to have an ordinary pot select different modes in the program and determine what is set by looking at the pot without the need for a display of some sort.

like this:
read AD converter to variable
quantize to one of 16 values and put into new variable
read quantized variable and determine what to do

This is my first post here and I did search the archives and found a lot of good stuff but not quite the answer to my question...

Regards

/Daniel

mister_e
- 21st February 2007, 20:08
hi,
you could use few IF then and branch to different subroutine OR use SELECT CASE.


If (AdVal>0) and (AdVal<10) then GOSUB Routine1
If (AdVal>10) and (AdVal<20) then GOSUB Routine2
' etc etc etc

mister_e
- 21st February 2007, 20:36
LMAO! i don't know why, but it should have hit my mind first...


RoutineToJumpTo=AD_Value/16

BRANCHL RoutineToJumpTo,[Routine0, Routine1, Routine2, Routine3.....Routine15]

dar303
- 21st February 2007, 21:49
Thanks!

I'll try it out and post the results!