PDA

View Full Version : ping sensor with 8051 mc



sara alla
02-12-2012, 04:44 PM
can i interface 8051 microcontroller with ping sensor and what about the code ?

Franklin
02-12-2012, 07:14 PM
can i interface 8051 microcontroller with ping sensor Probably, the ping returns a pulse that you need to measure.

and what about the code ? You will need to write that unless it out on the net somewhere and in that case you need to go find it.

jmg
02-12-2012, 09:58 PM
can i interface 8051 microcontroller with ping sensor and what about the code ?
Sure, in an 8051, you would typically connect INT0 to Ping Pulse, and the =\_ halts counting, and generates an interrupt.
You read the value, and 5us is Preamble (discard) and 115us-18ms is echo, so capture and compensate.

Once you have set up as a gated timer and enabled interrupts, the software is trivial, but a little more complex is dynamic range, and compensation.
See
http://en.wikipedia.org/wiki/Speed_of_sound

The 8051 has 16 bit timers, so Dynamic range needs more attention than on a Prop, but choose a newish part like the Atmel AT89LP52, and it drops out quite nicely.

Speed is ~346.18m/s or ~346.18mm/ms, so you want your timer to be 346.18 counts per millisecond, or clocked at 346180Hz

The LP52 adds prescalers to a basic 8051 (/1../512) that allow this from a generic BAUD Crystal like 11.0592MHz : 11.0592e6/(346.18/1m) = 31.94 => /32
and now your captured value is read directly in mm (well LSB is mm, total system precision is poorer than that ).

You can contrast this with a Prop, which has a quite different timer : It is actually a 80MHz, 32 bit adder.

Here, you configure a Prop to add 283 every cycle : Gives what I call a 'virtual clock' of 80e6*283 and the upper 16 bits count at
80e6*283/2^16 = 345459Hz, so your top 16 bits in a Prop, match those 16 bits in the prescaled AT89L52.