In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Matthias09 wrote: Hi Beau, I just let them run one after the other and give 700ms time in between. So: Ping1 PulseOut Pause 100ms Ping1 PulsIn Pause 700ms Ping2 PulseOut Pause 100ms Ping2 PulseIn So they won't interfere. I have pretty smooth read outs of both sensors, only when I start to smoothen with the algorithm, then I get a lot of jumps. I get a maximal value of 300mm, the reading is already adjusted. 300mm are about 11.8in. The value is correct and works great with my setup. Find a picture enclosed of the BnB System. Other than in the picture, I adjusted the sensors so they now look up in the sky with approx. 25deg. I did these as now they have a much bigger range (maybe due to less reflections from the beam itself). I don't actually know why they have a bigger range (also in single mode, means I only use one sensor) when I don't target them directly towards the object, but a little bit above, but it works fine. THis is my code: [code] FUNC DRIVE_US_SENSOR 'Driver. Has to be called for each sensor. Gives back the position of the ball RELATIVE to the sensor. Provides Data smoothing: 'make [samples] readings, built average, then give out the result. When called for one sensor, [samples] values are taken for 'this one before switching to next one occurs. temp_gs var bit temp_gs = __param1 FOR i = 1 TO 5 'amount of reading before giving out result. when sample rate here, also change at 'Avg = Avg / 10' below '-----Reading----- IF temp_gs = Green THEN led3 = ison led4 = isoff US_Green = 0 'set port to low PULSOUT US_Green, 5 '[PIN][Pulselength]. set port high for width of trigger variable (5). creates the pulse that I will 'later receive. after the pulse, port gets back to initial status (low). PAUSEUS 100 'Pause 450 microseconds PULSIN US_Green, 1, ball_position(i) '[PIN][State][Variable to store result]. measure the width of an incoming pulse. 1 sets the transition of 'the measured pulse (Flankenerkennung und Triggerung: port war auf low gesetzt. nun 'warte ich auf eine Veraenderung auf HIGH durch einfallenden Puls, den ich mit PULSOUT gesendet habe. 'PULSIN triggert also auf steigende Flanke. Der einfallende Puls wird als highpulse bezeichnet, dessen 'Laenge gemessen).The length of the measured pulse is stored in the word ball_position ELSE led4 = ison led3 = isoff US_Black = 0 PULSOUT US_Black, 5 PAUSEUS 100 PULSIN US_Black, 1, ball_position(i) ENDIF PAUSEUS 700 'required for short distance measurements, so the sensor doesn't get signal from the previous cycle '-----Smoothing----- IF ball_position(i) > 150 THEN 'maximal reading is around 150 (raw). Cut above, so sensor input data for smoothing is more reliable ball_position(i) = 150 ELSEIF ball_position(i) = 0 THEN 'value stored in byte variable gets 0, when value > 256 (I define this as out of range). Give sensor special code (252, I chose that) ball_position(i) = 252 'so that I can read from the sensor output, that the sensor is out of range (assuming that he never will ENDIF 'give back 252 as a averaged value) DON'T KNOW YET IF I NEED THIS FEATURE NEXT b1 = ball_position(1) b2 = ball_position(2) b3 = ball_position(3) b4 = ball_position(4) b5 = ball_position(5) ' Avg = Avg / 3 'get averaged result '-----Adjusting----- 'convert the final result in mm. see documentation for details ' Avg = Avg * 5 'use additional var (distance), as avg must remain in raw format to reuse it in the smoothing algorithm. ' Avg = Avg ** RawToMm 'Avg = Avg + 5 '<-- RECALC OFFSET ' PAUSEUS 2000 'to prevend that one sensor reads the other, give some time before function returns 'and can be called again. '-----Transmitting----- RETURN Avg '-----Resetting----- ' Avg = 0 ENDFUNC [/code] ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=175860#m387668 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2009 (http://www.dotNetBB.com)