Ultrasound with PIC12F629


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2007
    Location
    Sao Paulo - Brazil
    Posts
    16

    Default Ultrasound with PIC12F629

    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.

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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

  3. #3
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by ewandeur View Post
    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

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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!

  5. #5
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Post

    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

  6. #6
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Exclamation Don't have much gain.

    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

  7. #7
    Join Date
    Feb 2007
    Location
    Sao Paulo - Brazil
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    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!

  8. #8
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Default

    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)
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

Similar Threads

  1. semaphore pic12f629
    By Leonardo in forum mel PIC BASIC Pro
    Replies: 26
    Last Post: - 7th November 2008, 13:55
  2. pic12f629 EEPROM problem in MPLABSIM
    By nicholastyc in forum General
    Replies: 1
    Last Post: - 16th May 2008, 18:10
  3. How do you interface a 74hc165 to a pic12f629
    By orion1137 in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 6th February 2005, 04:10
  4. PIC12F629, useing all I/O pins
    By Jcee324 in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 7th December 2004, 11:05
  5. PIC12F629 or 8pin
    By andyf in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 27th October 2004, 18:11

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts