Aaron Hickman wrote: >To all, > > My previous message might have been unclear as stated. What I am >looking for is a method of converting a 16 bit ADC value into an >appropriate voltage value (ie. 20 V * (ADC value/65535). I feel certain >that I need to use floating point methods, but have little experience in >using them. Can anyone help? Aaron, First of all, the maximum input to your A/D is probably equal to the reference voltage, typically 2.5 or 5. Second, your question implies a range of 20 volts. You will need a voltge divider with a divisor of F. For example, if you used 10K series and 75K shunt, F = (10+47)/10 = 8.5 ;The input in millivolts to the a/d for a 20V input is: ; 10 * 20000 / 85. Note X10 in numerator and denominator ;Change the divisor here if the resistor voltage divider changes. max_a2d_input equ 10 * 20000 / 85 ; in mv ;Assuming a count of 65535 (16 bit converter) for 2500 mv (Vref) in: count_for_20 equ 2500 * 65535 / max_a2d_input counts_per_volt equ count_for_20 / 20 Now, given an A/D count, the voltage is count/counts_per_volt Using the above numbers: mas_a2d_input = 2.35 mv count_for_20 = 27887 counts_per_volt = 1394 Most of these calculations are done at compile time. To convert an A/D count to volts you only need one division which does not have to be floating point. The following routine will do the trick: ;******************************************************************* ; Division: Divide 16 bits by 16 bits, ; 16 bit quotient and remainder. ; Standard shift and subtract algorithm. ; ; q_2:q_1 / n_2:n_1 -> q_2:q_1 Remainder in t_2:t_1 ; ; Uses count ; ; Execution time: 271 to 361 clock cycles ; Program memory: 27 ; ; (This is a cleaned up version of the routine in AN526) ; ;******************************************************************* div16b16: macro local loop, check_sign, check_count movlw 16 movwf count clrf t_2 clrf t_1 div16_loop: rlf q_1, f rlf q_2, f rlf t_1, f rlf t_2, f movf n_2, w subwf t_2, w skpz goto check_sign movf n_1,w subwf t_1,w check_sign: skpc goto check_count movf n_1,w subwf t_1, f skpc decf t_2, f movf n_2,w subwf t_2, f setc check_count: decfsz count, f goto loop rlf q_1, f rlf q_2, f endm -- Bob Fehrenbach Wauwatosa, WI bfehrenb@execpc.com