Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 16:52 07 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Problem with ultrasonic range

     Page 1 of 6    
Author Message
Frank N. Furter
Guru

Joined: 28/05/2012
Location: Germany
Posts: 815
Posted: 10:23am 03 Mar 2014
Copy link to clipboard 
Print this post

Hi,

I am using Micromite beta 8 (28pin version, PL2303 USB to Uart and separate Power) and I am testing the ultrasonic range (HC-SR04) command and I have following problem:

With my program (and "option autorun on")
Do
range = distance(21,22)
print "Distance =",range
Pause 50
Loop
End


I get following error after first Power on:
Error: Transducer not responding

A new "RUN" command works...

It seems better to work with:
SetPin 21, dout
Do
range = distance(21,22)
print "Distance =",range
Pause 50
Loop
End


Now it works after Power ON - BUT ONLY WITH ONE OF MY TWO PCs!

Same configuration, same Power Supply: Sometimes it works, sometimes I get the error, sometimes it works for a time - than stops with the "not responding" error!

Is there a possibility to "on error goto" to check this curious behavior with a oscilloscope?

I am very confused...

Frank


 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 10:42am 03 Mar 2014
Copy link to clipboard 
Print this post

Out of interest, what happens if you increase the pause time?
For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 10:50am 03 Mar 2014
Copy link to clipboard 
Print this post

Also try two different 5v pins (between 14 & 18) if possible to eliminate a 'dead' pin on 21 or 22.
For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5915
Posted: 11:00am 03 Mar 2014
Copy link to clipboard 
Print this post

The transducer may need time to initialize after power on.
Try putting a pause 1000 before the first range statement.

If it works on one PC but not another, it could also be the 5V supply that is marginal for your transducer.

The other possibility is a poor connection on one of the terminals.

Jim
VK7JH
MMedit   MMBasic Help
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5915
Posted: 12:25pm 03 Mar 2014
Copy link to clipboard 
Print this post

The datasheet recommends a minimum 60ms wait between sampling.

"we suggest to use over 60ms
measurement cycle, in order to prevent trigger signal to the echo signal. "

Jim
VK7JH
MMedit   MMBasic Help
 
Frank N. Furter
Guru

Joined: 28/05/2012
Location: Germany
Posts: 815
Posted: 09:02pm 03 Mar 2014
Copy link to clipboard 
Print this post

Hi,

- I tried Pins 17 and 18
- I increased the Pause between measurements to 500ms
- I tried a Pause with 500ms at beginning of the program
- I tried different Power Suplies
- I tried another PC

...but same behaviour! First time it won't be working at all without SetPin to dout:
"Error: Transducer not responding"

It works mostly after RUN but sometimes it stops with the same error.
The signals are very clear and sharp with my oscilloscope when it works. After Power Up the trigger and echo line goes very unsharp high to 5V.
I have the feeling that the sensor have problems with the crystal...

EDIT: I tried another PIC - same behaviour...

I can't see any pulses on the sensor (4MHz) crystal with my 500MHz oscilloscope - can anybody confirm this? But why does it work without an oscillating crystal? Do I have an measurement error or use the sensor an internal clock when the crystal is defect?


Does anybody have another idea?

Frank
Edited by Frank N. Furter 2014-03-05
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5915
Posted: 09:42pm 03 Mar 2014
Copy link to clipboard 
Print this post

You should be seeing a 10uS pulse on the trigger terminal followed by a variable length pulse on the echo terminal.

Can you see if there is a burst of 40kHz on the transducer?



It looks like you might have a faulty unit.

Jim


VK7JH
MMedit   MMBasic Help
 
Frank N. Furter
Guru

Joined: 28/05/2012
Location: Germany
Posts: 815
Posted: 10:06pm 03 Mar 2014
Copy link to clipboard 
Print this post

Hmmm, is it possible that the timeout of our new range command is to short?
I can see the trigger signal with 10µs and the echo AFTER 453µs!!!

I have found in two manuals that the echo should have a delay of about 250µs!

Blue is trigger, yellow is echo:

The µMite says exact in this moment "no response"!

Frank
Edited by Frank N. Furter 2014-03-05
 
Frank N. Furter
Guru

Joined: 28/05/2012
Location: Germany
Posts: 815
Posted: 10:27pm 03 Mar 2014
Copy link to clipboard 
Print this post

It seems that something is wrong with our range command!
When I suddenly increase the distance, I get my error and it won't run with a new "run" command - always no response.
[8] range = Distance(17,18)
Error: Transducer not responding
> RUN

[8] range = Distance(17,18)
Error: Transducer not responding
> RUN

[8] range = Distance(17,18)
Error: Transducer not responding
> RUN

[8] range = Distance(17,18)
Error: Transducer not responding



But the signals are very curious:


trigger is blue, echo is yellow, but trigger is high (no 10µs pulse) and echo is also high!

But when I change my program to:
'Ultrasonic range test
Pause 100
SetPin 17, dout
'SetPin 18, dout
Pause 100
Do
Pulse 17, 0.01
' range = Distance(17,18)
Print "Distance =",range
Pause 60
Loop
End


can I see that the sensor works all the time without any problem...

Frank
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 12:35am 04 Mar 2014
Copy link to clipboard 
Print this post

Wow, a $7,000 oscilloscope!! Colour me green with envy

  Frank N. Furter said  After Power Up the trigger and echo line goes very unsharp high to 5V.

You might have two issues. The first might be that the echo line is high, it is supposed to be low and the DISTANCE command checks for this and throws the error "Transducer not responding" if it is high.

The second place where you can get this error is if the echo line has not gone high within 2 mS after the trailing edge of the trigger pulse.

For what it is worth, below is the whole DISTANCE command (in C).

Geoff

void fun_distance(void) {
int trig, echo;

getargs(&ep, 3, ",");
if(argc != 3) error("Invalid syntax");
trig = getinteger(argv[0]);
echo = getinteger(argv[2]);
if(IsInvalidPin(trig) || IsInvalidPin(echo)) error("Invalid pin");
ExtCfg(echo, EXT_DIG_IN);
PinSetBit(trig, LATCLR);
ExtCfg(trig, EXT_DIG_OUT);
if(PinRead(echo)) error("Transducer not responding");
PinSetBit(trig, LATSET);
uSec(10);
PinSetBit(trig, LATCLR);
uSec(5);
ExtCfg(echo, EXT_DIG_IN);
PauseTimer = 0;
while(!PinRead(echo)) if(PauseTimer > 2) error("Transducer not responding");
WriteCoreTimer(0);
while(PinRead(echo)) {
if(PauseTimer > 32) {
fret = -1;
return;
}
}
fret = (float)(ReadCoreTimer() * (2000000000u/CurrentCpuSpeed)) / 57820.0;
}

Geoff Graham - http://geoffg.net
 
Frank N. Furter
Guru

Joined: 28/05/2012
Location: Germany
Posts: 815
Posted: 01:32am 04 Mar 2014
Copy link to clipboard 
Print this post

@Geoff:

Yeah! It's a fine little toy! It's my oscilloscope at work...

I think my problem lies at point number one! You can see at my last picture that the echo signal is high!

When i have anything in a distance of 5 to 15cm and remove it fast that the next item is in about one or two meters, my echo-signal goes high and don't fall to low!
But the echo-signal goes low after a manually trigger with pulsout...

What's going wrong?

Frank

 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 01:44am 04 Mar 2014
Copy link to clipboard 
Print this post

How many Sensor modules do you have? If only one then this could be faulty maybe?

If you have more than one and they are all behaving the same then Im still scratching my head over this!


For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
Frank N. Furter
Guru

Joined: 28/05/2012
Location: Germany
Posts: 815
Posted: 02:05am 04 Mar 2014
Copy link to clipboard 
Print this post

Yes, I believe too that this f... little thing is defect! ...but I have only this one...
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5915
Posted: 09:23pm 04 Mar 2014
Copy link to clipboard 
Print this post

My sensor is 3 terminal so Trigger and Echo are combined on the top trace.
The lower trace is from the Tx transducer.



This was with a range of about 50mm

Colour hadn't been invented when I purchased my CRO.

You might have some luck if you attack the sensor with the soldering iron, hopefully fixing a bad joint.

Jim
VK7JH
MMedit   MMBasic Help
 
Frank N. Furter
Guru

Joined: 28/05/2012
Location: Germany
Posts: 815
Posted: 12:11am 05 Mar 2014
Copy link to clipboard 
Print this post

Hi Jim,

thanks a lot! But all my solder joints are looking quiete good.
Maybe is one of the transducers defect.
Can you see the oscillation of the 4MHz crystal?


I contacted the seller - he will send me another sensor...

Frank
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5915
Posted: 10:32am 05 Mar 2014
Copy link to clipboard 
Print this post

  Frank N. Furter said   Hi Jim,

Can you see the oscillation of the 4MHz crystal?

Frank


Yes, the crystal oscillation can be seen readily with the CRO.

I hope the replacement arrives quickly.

Jim
VK7JH
MMedit   MMBasic Help
 
Frank N. Furter
Guru

Joined: 28/05/2012
Location: Germany
Posts: 815
Posted: 10:03am 07 Mar 2014
Copy link to clipboard 
Print this post

Hi,

I have a new sensor from my distributer - but with the same problem!!!

But I am not alone: http://forum.arduino.cc/index.php/topic,55119.0.html

I think that's the same problem as with my two sensors...

I NEED HELP! This f... sensor run (...only with "setpin 17, dout") for a while but:
  Quote  "This sometimes results in the echo line staying high forever, even if you re-trigger a measurement.
The only way to get it to reset is by cycling the power."


I believe there are different HC-SR04 devices on the market!!! But mine doesn't work!

What can I do? I don't thought that's so a problem with this f... sensor!!!

(IR works very well with beta 10 - it was difficult to find the correct code on my ir remote control - not all Sony-codes are supported by µMite - but now it works really good!!! )

Frank
 
plasma
Guru

Joined: 08/04/2012
Location: Germany
Posts: 437
Posted: 10:11am 07 Mar 2014
Copy link to clipboard 
Print this post

a friend of mine uses 2 ultrasonic for his quadcopter , booth works great.
ill ask him for the seller .
 
Frank N. Furter
Guru

Joined: 28/05/2012
Location: Germany
Posts: 815
Posted: 10:16am 07 Mar 2014
Copy link to clipboard 
Print this post

Thanks Plasma,

but I think that the problem is, that's there are different HC-SR04 modules (different firmware) on the market!
All modules should work with the new ultrasonic command...

Frank
 
plasma
Guru

Joined: 08/04/2012
Location: Germany
Posts: 437
Posted: 10:21am 07 Mar 2014
Copy link to clipboard 
Print this post

Frankfurt / Main oder Oder ? ;)
 
     Page 1 of 6    
Print this page
© JAQ Software 2024