>
> > From: Carol & Tom Tumilty <
.....tumiltyKILLspam@spam@interlog.com>
> > I am new using the pic and would like to build a digital volt meter to
> > read the voltage when charging my battery for my radio controlled boats.
> > I tried the example in the apps notes AN546. The one example only gives
> > me 0-255 not a decmial number. The next example gives me switches to use
> > and I don't need the switches, I only want 1 A/D channel and 4 decmial
> > digits. Is there anyone who can help
> >
> > Thanks Tom
> >
>
> Let's presume you are using a 7.2V NiCd pack...
>
> If you want 4 digits (0000-9999) then you will need at least a 14-bit
> ADC. However, for battery charging you don't really need this level of
> precision - 8 bits should do if you shift the input appropriately (e.g.
> convert a 0-8.99V terminal voltage to, say, -4 to 4.99V then discard the
> negative portion (since normally your battery shouldn't be discharged
> that much) giving a nice 0-5V range. Use a 4V zener diode to drop the
> voltage into a suitable range. In your display routine, you convert
> the binary to decimal then add back the 4V. Your precision (not
> necessarily accuracy!) will be about 20mV.
>
> Converting 0-255 binary, representing 0-4.99V, into 4-8.99V decimal
> requires some simple manipulation. One way is to scale the result
> into two bytes. The first byte will end up with the whole number
> of volts, and the second byte contains the fraction (perhaps hundredths).
> To do this, try the following:
>
> get B = 0..255 count from ADC.
> Multiply B by 5 into a 16-bit register pair (W and L).
> W contains the whole number of volts (0-4).
> L contains the fractional remainder (0..255).
> Multiply L by 10 into another register pair (T and L).
> T now contains the tenths (0-9) and L the remainder (0..255).
> Multiply H by 10 into register pair (H and L).
> H contains the hundredths (0-9).
> Finally, add 4 to W to scale the result correctly to 4-8.99V.
>
> Multiplication by a constant is most easily performed using
> shifts and adds.
>
> I can't help thinking that it would be a whole lot cheaper for you
> to lash out and buy a digital multimeter - you'll probably need it
> to debug your PIC circuitry anyway!
>
> Regards,
> SJH
> Canberra, Australia
>