![]() |
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: GermanyPosts: 939 |
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 KingdomPosts: 2927 |
Out of interest, what happens if you increase the pause time? |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2927 |
Also try two different 5v pins (between 14 & 18) if possible to eliminate a 'dead' pin on 21 or 22. |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6223 |
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 |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6223 |
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 |
||||
Frank N. Furter Guru ![]() Joined: 28/05/2012 Location: GermanyPosts: 939 |
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 |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6223 |
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 |
||||
Frank N. Furter Guru ![]() Joined: 28/05/2012 Location: GermanyPosts: 939 |
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 |
||||
Frank N. Furter Guru ![]() Joined: 28/05/2012 Location: GermanyPosts: 939 |
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: AustraliaPosts: 3272 |
Wow, a $7,000 oscilloscope!! Colour me green with envy ![]() 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: GermanyPosts: 939 |
@Geoff: Yeah! It's a fine little toy! ![]() 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 KingdomPosts: 2927 |
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! |
||||
Frank N. Furter Guru ![]() Joined: 28/05/2012 Location: GermanyPosts: 939 |
Yes, I believe too that this f... little thing is defect! ...but I have only this one... ![]() |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6223 |
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 |
||||
Frank N. Furter Guru ![]() Joined: 28/05/2012 Location: GermanyPosts: 939 |
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: AustraliaPosts: 6223 |
Yes, the crystal oscillation can be seen readily with the CRO. I hope the replacement arrives quickly. Jim VK7JH MMedit |
||||
Frank N. Furter Guru ![]() Joined: 28/05/2012 Location: GermanyPosts: 939 |
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: I believe there are different HC-SR04 devices on the market!!! ![]() ![]() 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: GermanyPosts: 437 |
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: GermanyPosts: 939 |
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: GermanyPosts: 437 |
Frankfurt / Main oder Oder ? ;) |
||||
Page 1 of 6 ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |