PDA

View Full Version : How to scale to 150 volts for LCD



wildbilly
- 29th December 2006, 05:14
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

Darrel Taylor
- 29th December 2006, 05:23
Have a look here first
http://www.picbasic.co.uk/forum/showpost.php?p=2010&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>

sayzer
- 29th December 2006, 05:40
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.

wildbilly
- 30th December 2006, 02:39
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...

CocaColaKid
- 2nd January 2007, 20:27
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.

wildbilly
- 3rd January 2007, 02:45
Yes. Sounds and looks logical. Thanks for your input

sayzer
- 4th January 2007, 16:43
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.



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