PDA

View Full Version : measuring input voltage



thon
- 3rd February 2004, 02:49
Hi everyone, I've downloaded a program that measures voltages from http://microengineeringlabs.com/resources/samples.htm (vmeterx.bas), to measure 0-5VDC with 10-bit ADC and display the voltage with 2 decimal places. Is this only applicable for ADC using 10-Bit because I am using only 8-bits. See code:

' Define ADCIN parameters
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50

adval VAR WORD
TRISA = %11111111
ADCON1 = %10000010

Pause 500

loop: ADCIN 0, adval ' Read channel 0 to adval (0-1023)

adval = (adval */ 500)>>2 ' equates to: (adval * 500)/1024
LCDOut $fe, 1 ' Clear LCD
LCDOut "DC Volts= ", DEC (adval/100),".", DEC2 adval ' Display the decimal value

Pause 100 ' Wait .1 second
GoTo loop ' Do it forever
End


Can someone help me, I want to measure that input voltage 0-5V using only 8-bits, the above code is only for 10-bits I guess, Is the code above applicable only for 10-bit? how do I measure voltage of inputs using 8-bits?

Ingvar
- 3rd February 2004, 10:01
Hi,

Just remove the">>2" part.

/Ingvar

mat janssen
- 3rd February 2004, 22:41
DEFINE ADC_BITS 8

this works !!!

thon
- 16th February 2004, 02:11
Thank you guys for the response, they work fine...by the way I just have a question regarding LCD_bits. Im a little bit coonfused with:
DEFINE LCD_BITS 8 vs. DEFINE LCD_BITS 4
whats the difference between these two?

Melanie
- 16th February 2004, 19:44
DEFINE LCD_BITS 8 vs. DEFINE LCD_BITS 4

Determines if you want to have 8 or 4 wires going to your LCD (they are capable of either). Four bits saves on PIC-pins, interconnections, connectors etc but at the expense that each command or displayed byte is transferred 4 bits at a time therefore the event takes twice as long as with 8-bit transfer. Unless you have an application where writing to the LCD needs to be done at top speed (eg PIC version of Quake), 4-bits is adequate.

Melanie

winsthon
- 19th February 2004, 04:09
Thank you guys for all the help...I appreciate it. I hope to ask again someday for my future projects...

actionplus
- 10th June 2004, 16:37
Here a small problem I am facing with the same program from melabs.

I have 1 PIC that measures the voltage right. When I program a different PIC16F877A, the voltage seems to move around, especially when I remove the battery. It does not go to 0 volts right away. It floats around for a few minutes then goes to 0 then elsewhere.

I even tried reading of the PIC that work right and copying it to the new PIC and still does the same thing?

Any solutions?

G8RPI
- 10th June 2004, 18:12
Hi,
What circuit do you have connected to the PIC's ADC input?
If it is just the test voltage (I guess you are using a 1.5V battery) then you will get strang results when you disconnect it. This is called a floating input. In the simplest terms the stary capacitances formed by the IC, PCB or protoboard etc. retain an indeterminate charge. This charge is altered by the leakage current of the IC. To get a true reading you need to provide a path to ground for this charge / current. If you have a potential divider at your input this will provide a discharge path for you. Otherwise add a resistor from the input to ground. The value depends on the PIC used and the application. I'd reccomend 10K as a resonable value. This also corresponds with the maximum input impedance specification for the ADC on 16F8xx PIC's. A 0.01uF across this capacitor will also help reduce noise etc.

HTH,
Robert G8RPI.

actionplus
- 10th June 2004, 19:08
I just have a battery connected directly to it. 4.8V
Then I just remove it and then the reading start to move around.
I will try to terminate a 10k to the pin ans see what happens.

Thanks

actionplus
- 11th August 2004, 17:03
It seem to be a steady voltmater. can it test underload? Is there anyway to check the battery and then display that it will need recharge?