Hi Wolfgang,
I don't think the DFF solution will work.
The problem is the execution time between the instruction to initiate the sonar pulse and the instruction to read the echo.
To cancel the effect of that delay, the Picaxe output pulse that starts the sonar conversion must be delayed so that the "init" pulse to the 6500 input and the first transition on the picaxe input used for pulsin will occur at the time of the pulsin instruction when the start transition of the echo pulse is measured.
In this example, the sonar measurement is started with the Picaxe 08M output2 pin going low to initiate the conversion cycle.
A R1/C1 network delays the output2 conversion signal to synchronize with the delayed execution of the pulsin instruction.
I have posted 4 variations of a suitable circuit shown here connected to a 08M chip
<A href='http://www.user.dccnet.com/wrigter/picaxe/6500toPicaxe.gif' Target=_Blank>External Web Link</a>
I will explain the 555 version in some detail but all circuit examples work on the same principle.
The Picaxe initiates the cycle with a low on output2. This removes the positive voltage applied through the diode and allows the R1/C1 delay network connected to the 555 trigger input to time out.
The 555 is triggered when the trigger input voltage drops below Vcc/3. This causes the 555 output to go high which is connected to the Picaxe input1 pin and the 6500 INIT pin.
The 6500 then emits the sonar pulse. After the first sonar return is received, the 6500 echo output pin goes high. This echo pin is connected to the 555 threshold input which, when pulsed high, resets the 555 output to low and terminates the pulsin measurement.
In addition, the 6500 INIT pin is immediately driven low to power down the 6500 unit after the conversion.
The following picaxe basic code snippet works for all circuit variants:
<code><pre><font size=2 face='Courier'>
Symbol init= pin2
Symbol echo= pin1
readsonar:
low init 'start delay
pulsin echo,1,w1 'read positive echo pulse
high init 'reset delay </font></pre></code>
The 74HC14 Schmitt trigger version is less precise than the 555 version but also has signal sharp transitions
The Picaxe initiates the cycle with a low on output2 connected to the R1/C1 delay network to the input of the Schmitt inverter. After a delay, the output of this inverter drives the INIT input of the 6500 high and, through R2, drives the picaxe pin1 input high.
When 6500 echo output pin goes high, this signal is inverted with a second schmitt trigger which output is connected through a diode and drives the Picaxe input1 pin low.
The other two circuits work in a similar manner and are simpler but are less precise and may not meet the required rise and fall times of the 6500 INIT input.
One note about the component values of the R1/C1 delay circuit. The delay time constant I used for R1/C1 is a nominal 10ms assuming this is more that the execution time of the basic instructions involved but this value is not optimized.
The Sonar conversion time can be minimized by making the R1/C1 time constant as short as possible.
Use a 10K pot in series with a 1K resistor for R1 to make the delay adjustable.
First adjust the pot to minimum which generates a delay that is too short, so that the first transition will not be read and the pulsin instruction will timeout (655ms).
Slowly increase the value of the pot until short conversion times are measured and then increase the value of the pot slightly more.
Measure the value of the pot, add 1K and then replace the pot and 1K resistor with a single fixed resistor using the nearest higher standard value. This ensures that timing variations due to temperature and components aging do not reduce the delay time to less than the minimum required.
wilf
Edited by - wilf_nv on 09/07/2006 09:11:14
Edited by - wilf_nv on 09/07/2006 09:17:15
Edited by - wilf_nv on 09/07/2006 09:21:58
Edited by - wilf_nv on 09/07/2006 16:21:27