Minimum pulse with Digital Output

74 views
Skip to first unread message

Vic Wintriss

unread,
Jun 12, 2013, 12:49:17 AM6/12/13
to ioio-...@googlegroups.com
What is the minimum pulse width I will get with the following DigitalOutput code:

 rightStrobe.write(true);
 rightStrobe.write(false);

It looks like I am getting 40 millisecs with an android phone.

Ytai Ben-Tsvi

unread,
Jun 12, 2013, 7:42:29 AM6/12/13
to ioio-...@googlegroups.com
Over Bluetooth, this number is not unreasonable.
You can get a much smaller width (a few usec) if you wrap these instructions with a beginBatch() / endBatch() loop.
What is really the question here? There might be a better way to do what you're trying to do.


--
You received this message because you are subscribed to the Google Groups "ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ioio-users+...@googlegroups.com.
To post to this group, send email to ioio-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ioio-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Vic Wintriss

unread,
Jun 12, 2013, 10:30:12 AM6/12/13
to ioio-...@googlegroups.com
I'm using a parallax ultrasonic sensor on our robots.  It requires a short pulse to start the ultrasonic ping.

Do you have an example of how to use the beginBatch()/endBatch() with a digital output write(true), write(false) sequence?

You received this message because you are subscribed to a topic in the Google Groups "ioio-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ioio-users/YeZxBUL_Uto/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to ioio-users+...@googlegroups.com.

Ytai Ben-Tsvi

unread,
Jun 20, 2013, 1:13:43 AM6/20/13
to ioio-...@googlegroups.com
If you're talking about the parallax module that has a single pin for both input and output, this might be a bit tricky...
You may pull this off by connecting two pins together, one working as a PulseInput and the other as a DigitalOutput.
Read the wiki for beginBatch() / endBatch().

Ytai Ben-Tsvi

unread,
Jun 20, 2013, 1:15:07 AM6/20/13
to ioio-...@googlegroups.com
BTW, there are equivalent sensors with separate pins for input and output or, even simpler, with a single analog pin that presents a voltage that's proportional to the distance from the target, which can be read with an AnalogInput.

Carl Pedersen

unread,
Jan 30, 2014, 7:01:13 AM1/30/14
to ioio-...@googlegroups.com
A bit late, but I have just got a DSM-IO Ultrasonic module which also has one pin for a combined output and input.
I have also tried to connect  with a DigitalOutput tied together with a PulseInput (waitPulseGetDuration()) as many others have done, and it did not work.

As I have understood, a PulseInput requires two edges in order to fire, and the DSM-IO only needs a negative pulse in order to start, then the line is high until either an echo is received or a time-out reached.
According to the specs I have found, when a target is detected, a negative pulse of about 150 us is used to indicate a target is found whereas a 10ms pulse means no target within range.

One solution is to use 3pins, two PulseInput plus one DigitalOut.
Presumably the DSM-IO is triggered on the positive going edge of the trigger pulse, hence it should not matter if is 10us or several ms.
As I use a bluetooth connection, the length is probably as above, around 40ms.

To make it working, here is a cut from the code I have used for testing a sonar-like implementation.

sonarTrigger is the DigitaOut.
echoEnd is the PulesInput in NEGATIVE mode.
sonarEcho is the PulesInput in POSITIVE mode.

    sonarTrigger.write(false);
   TimeUnit.MICROSECONDS.sleep(10);  //I know, not needed
    sonarTrigger.write(true);

    //Wait for echo end pulse
    echoCheck = echoEnd.waitPulseGetDuration() * 1000 * 1000;
    //Then get last echo length
    echoSeconds = sonarEcho.getDuration() * 1000 * 1000;
    echoDistCm = echoSeconds / 29 /2;

The waitPulseGetDuration() should always be released as the DSM-IO module always returns a negative pulse at the end.
In the meantime, getDuration() has been triggered on the positive edge of the trigger pulse and the timing stops at the negative edge of the start of the end pulse. This is stored in a double, echoSeconds.

Obviously, there is a start delay, presumably 250us, which should be subtracted from the result before calculating the distance.
The value in echoCheck might be used to accept/reject the distance.
However, using the debugger in eclipse for check, the results have varied so I am not sure how it works.

Ytai Ben-Tsvi

unread,
Jan 30, 2014, 12:13:14 PM1/30/14
to ioio-...@googlegroups.com
I don't have "an answer", but a few things to try:
  1. At first, simplify: ditch the echoCheck and stay with the negative pulse.
  2. Try to open the pulse input AFTER setting your digital output low, then set it high and get a single reading from the pulse input (not the waitXXX version). Finally, close it. At least for now, this will eliminate any suspects in the form of synchronization problems (e.g. you're reading a value that has been generated before your output pulse actually went through).
  3. Look at the signal with an oscilloscope or a logic analyzer if you have access to them.


Carl Pedersen

unread,
Jan 31, 2014, 9:05:20 AM1/31/14
to ioio-...@googlegroups.com
Thank you for a quick response.

I tried your suggestion, but it did not work:

sonarTrigger.write(false);
sonarEcho = ioio_.openPulseInput(
         new DigitalInput.Spec(ECHO_PIN),
               PulseInput.ClockRate.RATE_2MHz,
               PulseInput.PulseMode.POSITIVE,
               true);
sonarTrigger.write(true);

echoSeconds = sonarEcho.getDuration() * 1000 * 1000;
sonarEcho.close();

It hangs when trying to execute the getDuration() call after setting the output high. Only now and then it might get one or to readings before getting stuck.

However, when using a negative input mode, it consistently returned around 240us with a target, indicating the echo end pulse is detected.

Even adding a 1-5ms delay between the pulse open and output high made no difference.

The hw and sw versions are:
hw is sprk0016
boot IOIO0306
firmware IOIO0326
and
IOIOllib 3.30

I tried the latest IOIOlib 5.02 but it requires a newer boot/firmware as far as I can see from the error code trying to connect.

With my code as in the first post, I tried to connect an oscilloscope and it shows a negative pulse of about 2ms (the low and high output) then a short period before a negative pulse of about 200 us when a target is in range.
Without a target, there is a very long time to the echo end. I was not able to catch it, old 10Mhz scope.

What I meant in the first post, when I mentioned that the results varied , was that the echo end pulse width varied a lot.
The distance also varies, but that could be caused by extra reflections etc.

As my solution seems to work without hanging up, for the moment there is no need to waste more of your time.
Maybe I some time later update the IOIO sw and try the latest IOIOlib.

Vic Wintriss

unread,
Apr 4, 2014, 8:20:54 PM4/4/14
to ioio-...@googlegroups.com
Ytai:

Could you please give me an example of the code that I would need to do the beginBatch()/endBatch() thing.

Thanks,

Vic

Ytai Ben-Tsvi

unread,
Apr 4, 2014, 9:19:40 PM4/4/14
to ioio-...@googlegroups.com
Sure. Something like:

ioio_.beginBatch();  // Start batching
out1.write(true);  // Nothing happens
out2.write(false);  // Nothing happens
...
ioio_.endBatch();  // Now all the previously batched commands all get sent at once.

There's no guarantees that packets will not get fragmented and if you batch too many commands they might get flushed prior to your endBatch(), but in practice it works well for small batches.

Just make sure not to do any blocking calls inside the batch (e.g. TWI.writeRead()) as they'll block forever (waiting for result before having sent the request).


--
You received this message because you are subscribed to the Google Groups "ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ioio-users+...@googlegroups.com.
To post to this group, send email to ioio-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vic Wintriss

unread,
Apr 4, 2014, 10:36:06 PM4/4/14
to ioio-...@googlegroups.com

Ytai:

Thanks...that gives about a 15 micro sec pulse hard wired to the Android.

Vic

Ytai Ben-Tsvi

unread,
Apr 4, 2014, 11:18:35 PM4/4/14
to ioio-...@googlegroups.com

This should not change over Bluetooth. Only the latency between when you issue the endBatch() and until the pin changes state.

Vic Wintriss

unread,
Apr 17, 2014, 7:10:39 PM4/17/14
to ioio-...@googlegroups.com
FYI, here is the circuit that I use with the Ping)))



On Tuesday, June 11, 2013 9:49:17 PM UTC-7, Vic Wintriss wrote:
Image041714031902.pdf
Reply all
Reply to author
Forward
0 new messages