PDA

View Full Version : Ultrasound with PIC12F629



ewandeur
- 27th February 2007, 11:16
Hi !

I'm using a PIC12F629 with internal oscilator (4Mhz) a LM386 as amplifier, and a piezo to emmit ultrasound wave (from 28Khz to 60Khz).
All I can achieve is an annoying sound but no ultrasound at all.

I'm actually using the suroutine below, obtained from Melanie in this forum:

MakeSound:
For CounterA=1 to 1000
High gpio.0
PauseUS 10
Low gpio.0
PauseUS 10
Next CounterA
Return

Can anyone help me?

Tks in advance.

Melanie
- 27th February 2007, 11:42
You may be generating you ultrasound signal but not realising it...

You're looping for 1000 counts, delaying 10uS for the high pulse, and 10uS for the low... (ignore any software delays for now). Now that's 20uS cycle time - which equates to 50kHz (somewhat less in reality because of software excecution times). However you are only outputing 1000 cycles (the For-Next loop count). This means you're only outputing 50kHz for 1/50th of a second.

So, if your For-Next loop is itself in another loop, you'll be hearing an annoying buzz at or around that loop time eg 50Hz, but you won't hear the ultrasound. Put it on a scope and see what you've got. You've probably got 50kHz being switched on/off at about 40/50 times per second - and it's that on/off switching that you can hear in your speaker.

Try this... it'll give you constant ultrasound output... see if it works and move-on from there...

MakeSound:
High gpio.0
PauseUS 10
Low gpio.0
PauseUS 10
goto MakeSound

T.Jackson
- 27th February 2007, 11:43
Hi !

I'm using a PIC12F629 with internal oscilator (4Mhz) a LM386 as amplifier, and a piezo to emmit ultrasound wave (from 28Khz to 60Khz).
All I can achieve is an annoying sound but no ultrasound at all.

I'm actually using the suroutine below, obtained from Melanie in this forum:

MakeSound:
For CounterA=1 to 1000
High gpio.0
PauseUS 10
Low gpio.0
PauseUS 10
Next CounterA
Return

Can anyone help me?

Tks in advance.

From memory I think the bandwidth of the LM386 is inversely proportional to the gain. More gain = less bandwidth. Open loop gain of the LM386 is something like 200, this will place a huge tax on the useable bandwidth. Generally above 15KHz or so, at very low output it's out of our hearing range. All told, Hi-Fi is 20Hz to 20KHz. I believe that the LM386 can go as high as about 100KHz with full feedback. i.e. No gain at all. In this configuration it's deemed a 'buffer' only.

Best Regards,
Trent Jackson

Melanie
- 27th February 2007, 11:53
Also, further to Trent's fine comments...

A piezo transducer has a resonant frequency, the further away from that frequency (or it's harmonics), and the piezo is rubbish. Use an Ultrasonic transducer (old style burglar alarm, antique TV remote, car parking sensors type), but even then, most don't go much beyond 40kHz. A pipistrelle Bat should be a quite good emitter... wire one up to a spare PIC I/O and you're in business (not checked a pipistrelle's Datasheet to see if it's 5v triggered)... trouble is you'll then have to budget for a conformal coating over the PCB to protect it from the Bat guano!

T.Jackson
- 27th February 2007, 11:57
And, Melanie’s right. You're only generating ultrasound for 20mS, 1,000 cycles of 20uS, 1 / 20mS = 50Hz. And the more I think about it with what I just wrote, if you were out of bounds with bandwidth you wouldn't hear anything at all. Completely attenuated.

Best Regards,

Trent Jackson

T.Jackson
- 27th February 2007, 12:56
Keep in mind that you're applying close to 5V to the input of the LM386.
IO ports on PIC’s are CMOS with a guaranteed minimum of 73% of VCC when set high. (You'll lose a bit because of the coupling cap) With this in mind, assuming a supply rail for the LM386 at around 9V, you really don't want a gain of much more than about 1.5 Of course, I am assuming that you don't have a volume control set in place enforcing a limitation on volume.

Best Regards,

Trent Jackson

ewandeur
- 28th February 2007, 10:17
I applied your suggestions and they worked fine, except the pipistrelle's, I think I will use an ultrasonic transducer (they are more clean ...).

Thank you very much!

paul borgmeier
- 28th February 2007, 16:22
Unless I missed someone else noting this ...
Pauseus 10 = 24uS at 4MHz
you need to double+ your T estimates (or more than cut your f values in half)