Hi, Peter McNulty wrote: >ADC Ouput (10bit)/ Vref (10bit)=3D A number here. Divide by Vref to get an accurate temperature even if the voltage isn't as constant as one would like. >Then substitute it into a formula like: > >0.15 + (3 * output above) to find the temperature. > >Does anyone know how to do this, or an easier way of doing this. I've been looking around and i can't find how PIC's would represent fractions, and how to=20 >substitute into formulas like the above.=20 Well if the above is correct, I would propose the following: We have: TempOut =3D ADC/Vref, then this should be followed by : DegOut =3D 3*TempOut + 0.15=20 ( BTW this seems very odd to me, are you really sure about these formulas ? ) Anyway assuming these are correct we have: DegOut =3D 3*ADC/Vref + 0.15 As the input is 10 bit (ADC and Vref) and we potentially can get an 10 bit result from the division ADC/Vref, we need to use atleast 10 bit variables, however we follow this division by multiplying by 3 which can give an 12 bit number. So we need atleast 12 bit variables. Now the native data sizes for the pic is either one bit or one byte, neither one is sufficient for this calculation, so we need to extend that somehow, I would suggest 16 bit variables as that is the easiest and most logical solution. And to utilise the full 16bit range I propose that we=20 multiply the input somewhat (i.e. fixed point). In this particular case we can mulitply the input by the factor 16dec. In essence creating an 'fixed point' between bit 3 & 4 in the 16 bit data. We still can represent the full range of 12 bit data and as an bonus have 4 fractional bits. As I choosed an 'power of two' constant we can achive this multiplication of the input by 16 easiest by performing 4 left shifts ( each giving an multiply by 2). So all variables should be 16 bit, we do 4 leftshifts for the input data and use 'normal' 16 bit integer routines. TempOut10q4 =3D ADC<<4 / Vref<<4 ; tempout has fixed point 10q4 DegOut12q4 =3D TempOut10q4<<1 + TempOut10q4 + 0.15<<4 ; degout12q4 =3D temp*3 + 0.15=20 Note due to the granularity of the fixed point variables we can only add 0.125 instead of the desired 0.15, if this poses as an error then other techniques might be better ( larger data sizes etc. ) Fixedpoint granularity is 0.0625 in 12q4. Also note that the output is in 'fixed point' the interger part is the 12 top bits, and the fractional part is the lowest 4 bits. To get the integer part only with rounding you perform: DegOut10bit =3D DegOut12q4>>4; if(DegOut12q4:3 =3D=3D 1)DegOut10bit++ ; if bit 3 is set the we need to = add one to output ( fractional part above 0.5 deg ) Look at the piclist site for all your math routine needs. /Tony -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads