<html>
<head><script type="text/javascript">
function distance()
{
var volts;
var dist; // unit: mm
var adcV; // ADC value
// build distance table via ADC value
document.write( "<pre>adcV2DIST:<br />" );
for( adcV = 0; adcV < 1024; adcV++ ) {
volts = adcV * 0.0048828125;
dist = Math.floor( 12.21 * Math.exp( volts - 1.15 ) * 10 );
if( (adcV % 16) == 0 ) { document.write( " dw " ); }
str = "" + dist + ","; len = str.length;
spc = ""; for( i=0; i<6-len; i++) { spc += " "; } // leading space
document.write( spc,str );
if( (adcV % 16) == 15 ) { document.write( "<br />" ); }
}
document.write( "</pre>" );
}
</script></head>
<body>
<input type="button" onclick="distance()" value="Generate Table" />
</body>
</html>