question about bits and range

Discussion in 'Embedded Systems and Microcontrollers' started by hunterage2000, Jun 1, 2015.

  1. hunterage2000

    Thread Starter Active Member

    May 2, 2010
    400
    0
    say if only wanted to use 3 values I would use 2 bits with values 00, 01 and 10. But if I used Vdd as V+then 11 would represent the 4th value which I don't want. How can I use 3 of the 4 combinations to represent the full range?
     
  2. JWHassler

    Member

    Sep 25, 2013
    201
    33
    Need more context here
     
  3. DickCappels

    Moderator

    Aug 21, 2008
    2,647
    632
    00 is zero
    01 is midpoint
    10 is max

    Did I read your mind correctly?
     
  4. hunterage2000

    Thread Starter Active Member

    May 2, 2010
    400
    0
    Yes. another example would be I need to show 0 - 5V on 7seg display. I need 6 values say 000 (min)-101(max) . How do I stop the max value being 111 as the 0-5V would be divided by 8 and I want it divided by 6.
     
  5. Art

    Distinguished Member

    Sep 10, 2007
    785
    61
    If your platform does floating point math, divide 7 by 5 and that's what each step is worth.
    If not you could use a resistor divider at the ADC input so the desired value is all that is ever reached.
     
  6. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    What are you stopping? What are you doing?

    As has been stated "Need more context here"
     
  7. hunterage2000

    Thread Starter Active Member

    May 2, 2010
    400
    0
    I have a pot analog input of 0-5V going into a pic. The adc V+ref is 5V and V-ref is 0V. I shift ADRESH so the whole 0-5V range is distributed over 3 bits (000 to 111) instead of 10 bits.
    Each voltage from 0-5V would equal a decimal value of 1.3333. If I could only use 000 to 101 for the whole 0-5V range then 0V = decimal 0, 1V = decimal 1 etc and an array can be made to output the right 7seg number. Unless a floated number can be used in an array.
     
  8. Art

    Distinguished Member

    Sep 10, 2007
    785
    61
    Well if you can't use Fp math connect a 20k pot between gmd and supply, connect the centre pin to the ADC pin and adjust till 5 Volts at the ADC gives the highest reading you want.
     
  9. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    So multiply your A2D result with the max reading and divide by the max count, in that order, without changing or reordering or anything.

    (reading * 5 ) / 1023
     
Loading...