Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC 16f690 MATH Problem.....

Status
Not open for further replies.

vortexmc

Newbie level 3
Joined
Sep 24, 2008
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,307
PIC 16f690 MATH Problem......
Hi there guys. I am currently working on a distance measurement application using the sharp rangefinder. I am using a PIC 16F690 microcontroller to read in the analogue voltage signal from the rangefinder. The maximum distance measured by this sensor is 30cm. The problem I am have is writing the math routine to convert the adc value too distance. For this project, I must use PIC assembly language. The equation for the conversion is :

volts = analogRead(IRpin)*0.0048828125
distance = 12.21*exp(volts -1.15)

I am a newbie at PIC assembly, so any help would help me greatly assist me. The ADC is 10 bit. The exp is short for exponent.
 

I must use PIC assembly language

a not-so-clever way is to check out the floating point routines by microchip;

a slightly-more-clever way is to figure out a way to do it with fixed point math.

the smarter way is to use C.
 

are you sure the distance is 12.21 * e^(v-1.15) ???

in your case, i would go and get some linear device! (something without the 'e' )
 

Just make a lookup table (ADC value to distance). No complex math is required in PIC assembly language.
To access table by 'Flash Program Read'.
To generate table in your favorite language.
EX: JavaScript
Code:
<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>
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top