pic16f877 adc drive a 7 segment LED display

Discussion in 'Embedded Systems and Microcontrollers' started by kennyburns, Mar 7, 2008.

  1. kennyburns

    Thread Starter New Member

    Mar 7, 2008
    6
    0
    hi yall. Im new on electronics and i'm doing a project. About getting a signal through a potentiometer puting it through pic16f877 and then depending on what results i get from the adc display a number from 0-6 on the 7segment led display.

    Now i have as much as the 6 diferent voltages that i will receive from the potentiometer which are:

    no== voltage
    --------------------------------
    1 == 0.06v
    2 == 0.08v
    3 == 0.10v
    4 == 0.13v
    5 == 0.16v
    6 == 0.17v
    0 == 4.97v

    I have general idea about what the circuit will look like. i will post it as soon as i have it finished
    Now my big problem is about the adc i think that if i use 8 bit convertion i will get resolution 0-255
    with that i will have problem on assigning the 5th and the 6th number because they both fall in number 8.
    also if anyone knows of a similar project please give me some help.
    i will use mplab ccs compiler for the programming.
    thnx in advance for any help.
     
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    It's a lot like using a yardstick to measure thousandths of an inch - the scale is too coarse to make the measurement. Your best resolution is 19.5 millivolts.

    If the range between 170 mv and 5 volts is in the who cares region, add an amplifier to make the last and largest significant voltage equal to 4.99 volts.
     
  3. kennyburns

    Thread Starter New Member

    Mar 7, 2008
    6
    0
    could you explain a bit more how these would help as i am a begginer in this:)
    by increasing the last significant voltage to 4.99 it will increase my rsolution?
     
  4. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    The resolution of the ADC is fixed, and can't be increased. The only way to make it possible to resolve small differences in the pot's output is to amplify the signal.

    As a for instance, making the gain of an op amp between the wiper of the pot and the ADC input = 2, then a previously invisible 10 mv change becomes 20 mv, and can be detected.

    This link goes to our Ebook and illustrates an op amp follower-with-gain, which just happens to equal 2 - http://www.allaboutcircuits.com/vol_3/chpt_8/6.html. If you only need to operate up to that last 170 mv level, make the gain = 10 and have even less uncertainty about the actual analog voltage.
     
  5. kennyburns

    Thread Starter New Member

    Mar 7, 2008
    6
    0
    look the pot is actually a gear postition indicator
    i understand what you are saying but when i will put on neutral and the 4.97v signall becomes double wouldn that fry my pic?
    i went through the data of the pic16f877 and i found something about resolution of adc being 10 bits is that so?
     
  6. S_lannan

    Active Member

    Jun 20, 2007
    247
    2
    what type of pot are you using? by chance is it logarithmic?
     
  7. kennyburns

    Thread Starter New Member

    Mar 7, 2008
    6
    0
    im afraid i dont kno my friend the pot is fixed on the engine of the bike its got three wires coming out of it one is 5 volts the other one is ground and the other one gave me those results that i have posted for each diferent gear

    btw i'm sure that it's 10 bit for adc so the problem i solved now as i have 0-1023 resolution now i have to start climbing the big mountain of c programming:confused:

    so now i have :
    no== voltage== no adc
    --------------------------------
    1 == 0.06v== 12.288
    2 == 0.08v== 16.384
    3 == 0.10v== 20.480
    4 == 0.13v== 26.624
    5 == 0.16v== 32.768
    6 == 0.17v== 34.816
    0 == 4.97v== 1017.856

    how am i going to make a round up of these numbers in programming?
     
  8. Reshma

    Active Member

    Mar 11, 2007
    54
    0
    Your program is intended to read an external input and display it via the output ports. Make use of 2 output ports. Connect 8 LEDs to one Port to display the digital value of the result of the A/D conversion. Use another Port to connect your 7-segment display (Segments a, b, c, d,..etc). The value of the voltage drop over the Potentiometer is read using the ADC and this value should be displayed as a digit between 0 to F on the 7-Segment.
    Hint: Can you make use of a lookup table?
     
  9. kennyburns

    Thread Starter New Member

    Mar 7, 2008
    6
    0
    never heard that lookup tabl before but i'm lokking at it at the moment
     
  10. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
  11. kennyburns

    Thread Starter New Member

    Mar 7, 2008
    6
    0
    ]
    thnk you very much my friend ...
    i think i got it now:p

    ive got 0-5 volts and 1023 steps
    so its 0.4887585533mv per step

    so the program would have to group the gears like this:
    no== voltage== no adc=======binary
    --------------------------------------------------------------
    1 == 0.06v== >=13--------------------------- >= 0000001101
    2 == 0.08v== 14=< >=17-------0000001110 =< >= 0000010001
    3 == 0.10v== 18=< >=21-------0000010010 =< >= 0000010101
    4 == 0.13v== 22=< >=27-------0000010110 =< >= 0000011011
    5 == 0.16v== 28=< >=33-------0000011100 =< >= 0000100001
    6 == 0.17v== 34=< >=36-------0000100010 =< >= 0000100100
    0 == 4.97v== 37=<-------------0000100101 =<
     
Loading...