Off-the-wall slimy hack. Depending on how fast you need to do the conversion, you could also attach some analogue circuitry to the PIC which does the calculation (you would want to just do 10^V, with a feedback-connected semiconductor junction through an op-amp, or something), and then use single-slope integration via a capacitor to measure the voltage. Its a pretty weird idea, though, I have to admit. I think a lookup table in E2PROM sounds nicest - a 24LC16B gives you 2048 bytes of table space for $1.50, after all, and a random-access lookup time of around 100uS. > ---------- > From: Sean Breheny[SMTP:shb7@CORNELL.EDU] > Reply To: pic microcontroller discussion list > Sent: Thursday, December 11, 1997 4:02 PM > To: PICLIST@MITVMA.MIT.EDU > Subject: Re: logarithmic calc > > At 08:37 PM 12/10/97 -0500, you wrote: > >Good evening, > > > > Can anyone point me in the direction of an example showing > the > >implementation of a logarithmic calculation on the PIC16C84. I am > trying > >to convert a voltage (1.5-8.7 volts) from a vacuum gauge into a > pressure > >in Torr using the relationship (P=10^(V-11.00). Any help/suggestions > >will be greatly appreciated. > > > >Sincerely, > >Aaron Hickman > > > > Aaron, > > It would seem to me that you are looking for an exponential function > rather > than a log. If you have voltage and wish to calculate pressure, then > you > simply want to raise 10 to the power of the Voltage - 11.00 > > Take a look at www.microchip.com I took a quick look at the Embedded > Control Handbook which has many Microchip App notes, including > floating > point math routenes, but no exponentiation functions. As Andrew Mayo > suggested, you might try a lookup table, but I would also suggest > using a > polynomial approximation to fill in the gaps among values from the > lookup > table. I just tried constructing a taylor series for 10^x and it > works, but > it requires alot of terms to be accurate over the range you are > talking > about. You might try expanding around some value other than the center > of > your range. I used 5.1, your center. > > Microchip does publish code for floating point multiplication, > division, > square roots, etc. > > Good luck, > > Sean > > > > > +--------------------------------+ > | Sean Breheny | > | Amateur Radio Callsign: KA3YXM | > | Electrical Engineering Student | > +--------------------------------+ > http://www.people.cornell.edu/pages/shb7 > mailto:shb7@cornell.edu > Phone(USA): (607) 253-0315 >