pulsin / timing

I have come across 2 problems of timing pulses which cannot be solved with pulsin 1. A radio control channel mixer needs to measure 2 consecutive pulses but the picaxe cannot respond quick enough to catch the start of the next pulse. 2. I have a polaroid 6500 ultrasound transducer which is triggered by taking the init input high I then need to time from this moment until the echo output goes high as there is no start edge to this "pulse" pulsin will not work.
I believe that the basic stamp has an rcin command which would do this I wonder if it would be possible for technical to add such a command or to enhance pulsin so that the edge parameter could be extended to cater for intervals without start edges I know that there would be inacuracies in the times but offsets can be added in software to counter the errors.
 

Jeremy Leach

Senior Member
If the channel mixer gives a repeated pair of pulses then maybe it's possible to measure between the first pulse of pair 1 to the second pulse of pair 2?

I think simple XOR logic would get around your second problem. If the init and echo signals are XORed then you'll get a pulse you can measure. Don't think XOR is possible with simple diode logic. But if you provide an inverted init pulse by cheating and using another PICAXE output, then you can just use a diode OR gate to get a pulse. (ie OR together the inverted init and the echo out signals, to give a low going pulse between sending and echo received).

Edited by - Jeremy Leach on 06/07/2006 13:58:07
 

BeanieBots

Moderator
Not sure I fully understand the problem with the RC mixer.
Feed one channel to input A and the other channel to input B. Each is a stream of pulses so they can be read at leasure in any order. The only thing to suffer is the response time of the mixed PICAXE output.
If you are looking at the raw un-decoded signal, then the PICAXE is simply not quick enough to see it all. I've not done too much work on this side of the decoder so there might be a solution but I gave up trying as it is much easier to use the decoded signals that feed the un-mixed servos.
 
Thanks for the help, but in the case of the RC mixer the outputs of the decoder which is usually a 4017 counter or a shift register the second output is microseconds after the first I have done it by polling alternate pulses but this produces a litte bit of jitter in the servos. As for the ultrasound ranger problem the start of the pulse has to occur after pulsin has started so XORing etc would not work. I thought that there may be similar problems in other areas where the picaxe language may benefit from such a command it seems to be available for the stamp and proton pic basic.

Barry
 

Jeremy Leach

Senior Member
I was thinking of starting the pulse immediately before Pulsin starts. Ok, there will be a small delay which will limit the detection of near objects - but not sure if the delay would be that great ...and depends on the ranges you want to measure anyway. And I'd think the delay is likely to be a constant. Or use two picaxes....

I take your point though.
 

MPep

Senior Member
Am just wondering if it would not be possible to use the 2nd channel, rather than the next channel after the first pulse output.
You might have to re-arrange wiring inside your transmitter to suit this. This should give you enough time to check/process.

Just a thought.
 

womai

Senior Member
You could use a regular D-Flip-Flop (DFF), with the inverting output wired back to the input. It also needs a reset input. This setup acts as a frequency divider, i.e. each pulse (high-going transition) changes (toggles) the output state. Connect an output of the Picaxe to the reset input of the DFF, and an input to the true (non-inverted) output of the DFF. The flow would be:

(1) re-set the flip-flop by pulling the DFF's reset input high

(2) measure the output of the DFF using the pulsin command. The width of the pulse is the distance between the two rising edges of your initial pulses.

The 74HC74 would be a suitable DFF. It's fast so you get the full accuracy/resolution of the pulsin command.

The only issue could be metastability when the first pulse comes in right after you release the reset pin.

Wolfgang
 

wilf_nv

Senior Member
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
 

jodicalhon

New Member
Nice work, Wilf!

<i>The Picaxe initiates the cycle with a high on output2. </i>

I believe this should be &quot; a LOW on output2&quot; as per the code snippet. Sorry to nitpick!

Jo
 
Thanks for the circuits,I was starting to think on even cruder lines of connecting the init output to the echo input with a resistor between the pins and a capacitor from the echo input to ground to give a short delay (The unit I have has a transistor inverter already in the init circuit).

Barry
 
Top