View Single Post
  #2   Spotlight this post!  
Unread 04-02-2007, 08:05
Ken Streeter's Avatar
Ken Streeter Ken Streeter is offline
Let the MAYHEM begin!
FRC #1519 (Mechanical Mayhem)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 2005
Location: Team: Milford, NH; Me: Bedford, NH
Posts: 471
Ken Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond repute
Re: Potentiometer with ADC

Quote:
Originally Posted by Shinigami2057 View Post
I have a dumb question - I Just hooked up a 100K pot to analog input 01, but Get_Analog_Value(rc_ana_in01) is only returning values from 0-9, and it definitely is not linear. This is the (very simple) code we're using just to test:

Code:
printf("%u\n", Get_Analog_Value(rc_ana_in01));
Am I missing something important here? Is there something wrong with the pot? (It's wired correctly)

Thanks
The problem is that Get_Analog_Value returns a 10-bit value, rather than an 8-bit value. In general, we discarded the lowest 2 bits of the potentiometer value as "noise" and just used the top 8 bits via the following code:

Code:
 int Get_Robot_Pot(void) {
    unsigned char robot_pot_8bits;
 
    // analog inputs on the robot are returned as 10 bit values, the line below
    // drops off the bottom two bits to give a one-byte value for the elevation
    robot_pot_8bits = (unsigned char) (Get_Analog_Value( rc_ana_in01 ) >> 2);
    printf("Pot Value: %3d\r\n", (int) robot_pot_8bits);
    return ((int) robot_pot_8bits);
 }
__________________
Ken Streeter - Team 1519 - Mechanical Mayhem (Milford Area Youth Homeschoolers Enriching Minds)
2015 NE District Winners with 195 & 2067, 125 & 1786, 230 & 4908, and 95 & 1307
2013 World Finalists & Archimedes Division Winners with 33 & 469
2013 & 2012 North Carolina Regional Winners with teams 435 & 4828 and 1311 & 2642
2011, 2010, 2006 Granite State Regional Winners with teams 175 & 176, 1073 & 1058, and 1276 & 133
Team 1519 Video Gallery - including Chairman's Video, and the infamous "Speed Racer!"