Mark, You will need to do a 16x16 multiply. I didn't check your assumtions, however, if you state that the largest input is 204, and the multiplier is .488, you would set the multiplier up as follows: The fixed point location is between the two bytes. The input value from the adc (maximum of 204 = 0x00cc) is loaded into the appropriate variable (16 bits), and the fractional part is calculated as .488*2^8 = 124.92, round to 125. Converting 125 to hex is 0x007d. Do the multiply, and the integer portion is available in the high byte and the fraction is in the low byte. For example, at 100F, the calculation is: 0x00cc * 0x007d = 0x639c. The 0x63 is the integer portion, (99F) and the 0x9C is fraction (.609375F) or about 99.6F. Notice the roundoff error (should have been 100). I guess either the 204 or the .488 is either incorrect, or rounded off, i.e., 204*.488= 99.552F. Also notice that my rounding off of 124.92 to 125 caused my result to be slightly high by .609375-.552= .057F, probably ok for this design. If you need higher resoulution, you will need to use more of the ADC. Instead of 5V for reference, you could use either a resistor divider or a reference device, depending on the accuracy needed. Just make sure that when you multiply the ADC input value with the new multiplier, you don't overflow the 16 bits. Oh, and if you do use 5V reference, make sure you account for errors if the reference is not exactly 5V, i.e., 4.75V - 5.25V or whatever your tolerances are on the regulator. Do the math before you build it, you probably won't like it and will eventually choose a reference device in the 2.5 to 3V range. Ken klumia@adelphia.net ----- Original Message ----- From: "Mark Bellamy" To: "PICLIST" Sent: Thursday, May 26, 2005 11:36 PM Subject: Re: [PIC] Floating Point on 16x > Everyone's input on this has been very helpful. I think fixed point > will work just fine for me. I'm only dealing with daily temperature, > so no big dynamic range requirements. > > I want to display the temperature on an LCD. I'm using a LM34CZ. It > outputs 10mv per degree F. On the LCD, I only expect one place after > the decimal. (I am probably lucky if I get accuracy to the nearest > degree, but it's still nice to have that decimal place to see which > way the temperature is trending.) To make it simple for now, I decide > to place limits of 0-100 degrees F. > > Will this design work?: > > Vcc is 5v. > The PIC ADC is configured to use Vcc as the upper ref voltage. > Take the 10bit ADC value, multiply it by .00488 (5/1024). > That will result in the actual voltage. > Multiply that value by 100 to get degrees. (or instead of of using > .00488 in the previous step, just use .488) > > How do I determine what fixed point format will work? The ADC result > is 10 bits so I will need at least two bytes. How do you determine > how many bits are required for the fractional part after the decimal? > > On figuring out how many bits I need before the decimal point: > Assuming a max temperature of 100 deg F, that results in 1V into the > ADC (100 x 10mv). 1V in the ADC would correspond to 204 ( 1/.00488). > That 204, I believe will be the largest number, so 8 bits should work. > Is this correct logic? > > Since I need to represent .488, I will need enough bits to hold 488. > That ends up requiring 9 bits (2^9=512). Is this the correct way to > tell how many bits you need for the fractional part? Maybe for > simplicity I should use the 16x16 fixed point format? Or maybe it can > be determined that .49 will be accurate enough? Although I don't know > how to calculate how accurate that will be. .488 itself is a rounded > result of 5/1024*100. Maybe .5 would be accurate enough? > > On a slightly different topic, since I'm going to hard code the > voltage per bit of the ADC, I need a stable and accurate voltage > reference. For simplicity's sake, I was going to use Vcc which is 5v. > What are some strategies to help guarantee a stable and accurate > reference voltage for an ADC? > > Thanks for all of your input. > - > > Mark Bellamy > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist