How to scale to 150 volts for LCD


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2005
    Location
    Ontario Canada
    Posts
    30

    Default How to scale to 150 volts for LCD

    I am trying to read 0v-150v on the LCD but I am having a rough time figuring it out. I have this code from a book by Dogan Ibrahim which explains how to read 0-5000mV on the LCD. I understood his code but I am trying to be able to read 150v but running into problems with values too big for word variable and converting from 5v to 150v. Can someone take a look at this short code and say if it is possible. If not does anyone know how this can be done. I try not to ask too many questions as I read a lot on the forum, but I am stuck and need some help. My thinking is after setting the voltage divider to as close as possible to 5 volts for the pic and 255 (adc) out would be the top end I would need to do some conversion but everthing I have tried I run into problems with overloading the word type variable. I have worked it out on paper and it works, but I stumble with decimals in the code. The pic is 16F73
    Thanks to all.

    ' Variables
    '
    Res Var Word ' A/D converter result
    Volts1 Var Word ' First part of result in mV
    Volts2 Var Word ' Second part of result in mV

    '
    ' Constants
    '
    Conv1 Con 19 ' 5000/256 = 19.53, this is the decimal part
    Conv2 Con 53 ' This is the fractional part

    TRISA = 1 ' RA0 (AN0) is input
    TRISB = 0 ' PORT B is output

    PAUSE 500 ' Wait 0.5sec for LCD to initialize
    '
    ' Initialize the A/D converter
    '
    ADCON1 = 0 ' Make AN0 to AN4 as analog inputs,
    ' make reference voltage = VDD
    ADCON0 = %11000001 ' A/D clock is internal RC, select channel AN0
    ' Turn on A/D converter
    LCDOUT $FE, 1 ' Clear LCD


    AGAIN:
    '
    ' Start A/D conversion
    '
    ADCIN 0, Res ' Read Channel 0 data

    Volts1 = Res * Conv1 ' Multiply by 19
    Volts2 = Res * Conv2 ' Multiply by 53
    Volts2 = Volts2 / 100
    Volts1 = Volts1 + Volts2 ' Result in mV
    LCDOUT $FE,2,"V=",DEC4 Volts1 ' Display result
    PAUSE 1000 ' Wait 1 second
    GOTO AGAIN ' Repeat

    END ' End of program

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Have a look here first
    http://www.picbasic.co.uk/forum/show...10&postcount=2

    I haven't run your numbers to make sure it works (don't know your voltage divider values), but it's certainly better then what you have.

    If it doesn't work, let me know, we'll figure something out.
    <br>
    DT

  3. #3
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Some notes from me:


    In DT's schematic in that link, use 100K for R1 and 2K2 Trimpot for R2.

    Apply 150V to your probes.

    WHILE you are adjusting trimpot have your eyes looking at LCD for your ADC reading. Just use the raw reading. Do not scale it to anything.


    Main reason for using trimpot: to drop from 150V down to 5V level, you use a resistor value around 100K or 150K. But say that you are using metal film resistor with %1 tolerance.
    That means, your R1 can be 101K or 99K. You never know the actual resistance value in mass production. This difference of "1K" will give you a large deviation in your ADC reading. Thus, you need a fine tune, lets call it calibration by using a trimpot.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  4. #4
    Join Date
    Nov 2005
    Location
    Ontario Canada
    Posts
    30


    Did you find this post helpful? Yes | No

    Default

    Thanks Darrel. I had a look at the link and that has been very helpful. Thanks a lot. Thank you too Sayzer for your input, most valuable. Even though it has been challlenging at times, it still is fun learning this stuff, especially when the forum is off such great help. Thanks again.

    Wild...

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Would it not make more sense to use a 1M and a 33K trimmer? This would allow you to achieve the optimum ration of 30:1 (150V/5V) would it not. With a 100K and 2.2K trimmer you'll have a ratio of 45:1 which will output only 3.33V at the full 150V.

  6. #6
    Join Date
    Nov 2005
    Location
    Ontario Canada
    Posts
    30


    Did you find this post helpful? Yes | No

    Default

    Yes. Sounds and looks logical. Thanks for your input

  7. #7
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by CocaColaKid View Post
    Would it not make more sense to use a 1M and a 33K trimmer? This would allow you to achieve the optimum ration of 30:1 (150V/5V) would it not. With a 100K and 2.2K trimmer you'll have a ratio of 45:1 which will output only 3.33V at the full 150V.
    It was an example.

    But, %1 of 1M is 100K.

    That means, the resistor says 1M but it may actually be somewhere between 900K and 1100K.

    That also means a lot more you know.
    Using 33K trimpot is not going to be helpful in fixing the tolerance deviance.



    -----------------------

Similar Threads

  1. DC volts and A/D converter
    By michel in forum Schematics
    Replies: 3
    Last Post: - 17th September 2008, 11:44
  2. Multiple IR Receivers
    By jhorsburgh in forum General
    Replies: 8
    Last Post: - 9th September 2008, 11:31
  3. Scale 8bit ADC RGB LED voltmeter
    By Ryan7777 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 22nd February 2008, 03:37
  4. me again
    By BobSpencerr in forum General
    Replies: 5
    Last Post: - 1st March 2007, 23:15
  5. Replies: 5
    Last Post: - 2nd March 2006, 09:21

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