Scaling ADC values


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Feb 2006
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Thanks for the help Skimask, it helped a lot. I used your method with a couple of modifications and it seems to work very well.

    First, I added to your method was to define minimums and maximums. I was having problems bumps/shakes of the accelerometer making the min and max values go well outside of the range which I wanted to capture (which is neutral to 90 degrees on either axis). The MIN and MAX statements solved that.

    I also added a line to subtract the minimum value from the capture adc value. This ensured that the final output was actually 0-127. Without it, my output would never go all the way down to 0.

    In the long run (as I am sure many of you will notice) I will probably just define range since I know what the adc values are at +90 and -90 degrees. I haven't done that yet, because I want to be sure that environmental variables don't affect the accelerometer output.

    Here is the routine that I ended up using....


    modcheck:
    ADCIN 1,modval ' Read channel 1 to modval
    modval=modval min 166
    modval=modval max 91
    if modval<minval then minval=modval
    if modval>maxval then maxval=modval
    range=maxval-minval
    modval=modval-minval
    scalefactor=65535/range
    modvalnew=modval*scalefactor
    modvalnew=modvalnew>>9

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    One thing I forgot to mention (but it seems you already took care of it in a way) is to initially set your minimum value very high (so the only place it can go is down) and your maximum value very low (so the only place it can go is up)...

  3. #3
    Join Date
    May 2007
    Posts
    65


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    One thing I forgot to mention (but it seems you already took care of it in a way) is to initially set your minimum value very high (so the only place it can go is down) and your maximum value very low (so the only place it can go is up)...
    yes, both near the center
    "Beethoven had his critics too, see if you can name 3 of them"

Similar Threads

  1. Stable Adc Reading Routine
    By gebillpap in forum General
    Replies: 27
    Last Post: - 13th May 2015, 02:18
  2. 16F877A problem: "coupled" digital values
    By Lupo83 in forum General
    Replies: 16
    Last Post: - 4th December 2007, 12:46
  3. Adc giving widely flactuating values
    By tamersoss in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 17th December 2006, 08:59
  4. ADC value with 2 decimals on an LCD
    By Squibcakes in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd December 2005, 15:54
  5. 12F675 ADC 'Issues'
    By harrisondp in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2005, 01:55

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts