Driving a 32Khz ultrasonic transducer with the Prop...

The discussion title says it all...can the prop produce the AC signal to drive the above transducer. I just need a little education on this...never messed with ultrasonic transducers before...I simply just want to turn it on to generate the 32Khz frequency. Not going to be using it for range detection....thank you..
DennO
«1

Comments

  • You can look at this OBEX entry. It is setup for 40Khz, but a software tweek could set for 32Khz.

    http://obex.parallax.com/object/620

    Infernal Machine
  • Tracy AllenTracy Allen Posts: 6,347
    edited 2019-05-06 - 19:37:13
    "The above transducer"? Depends how much oomph it takes to drive the particular transducer you have in mind. Yes, you can drive a small transducer directly with the Prop output pins. Use the NCO differential mode of a cog counter to make it easy and to get a 6V swing across the transducer from a 3V supply.
    CON
     _clkmode = xtal1 + pll16x                '
     _xinfreq = 5_000_000
    MY_APIN = 0 .    ' hook the transducer up between these two pins
    MY_BPIN = 1 .    '   A ----- xducer ----- B
    PUB  RocknRoll
       frqa := 1759219   ' to set 32kHz out with 80MHz clkfreq
       ctra := %00101<<26 + (MY_BPIN<<9) + MY_APIN   ' NCO differential on my pins
       repeat     ' keep it alive
    

    It may be a bit louder if you put a small inductor in series with the piezo, something like 5 or 10 mH.
  • Tracy Allen, thank you for your input. However, I am not that well versed in SPIN, and have been using PROPBASIC by Bean, which does work for me on various embedded situations, (as I am a long time user of PBASIC for the STAMPS) using the Propeller, with the FLIP and/or the Prop Mini. Also, what does NCO stand for?

    My next question is, is it possible to translate the above SPIN to Propbasic. I am sure that it has something to do with COUNTERA and COUNTERB in Propbasic.

    DennO
  • Numerically Controlled Oscillator (NCO)

    Good reading on counters and sample programs:

    https://www.parallax.com/downloads/an001-propeller-p8x23a-counters
    Infernal Machine
  • Tracy AllenTracy Allen Posts: 6,347
    edited 2019-05-07 - 19:13:09
    I like to stick close to the "native" language of the processor, and that is Spin for the Prop. PropBASIC is nice too, and I think it's syntax your purpose would be,

    COUNTERA 40, MY_APIN, MY_BPIN, 1759219

    The "40" is simply a mode value from the PropBASIC documentation, to set NCO differential. The frqx number, 1759219, is calculated on the basis of 32768 Hz, but if you really want 32000 Hz, it should be 1717987.

    Here is the formula to calculate that number, based on your target Hertz and the Prop clock frequency.

    frqx = 2^32 * targetHz / clkfreq . round off to integer value.



  • Thank you Tracy Allen and Publison. You two have really helped me making the transition from the basic stamp (sx) to the prop. I just find SPIN a little difficult to transition to. I am just a self taught hobbiest...Tracy, you have even helped me in days gone by with some issues I was having with I2C and the HMC6352. ((BTW...Great electronic compass..able to hold 1 degree accuracy (azmuth) on a Directv dish on my boat, at anchor while the boat swings with the wind....)) but no longer available from Sparkfun.

    Thanks again..DennO
  • dennodenno Posts: 138
    edited 2019-05-08 - 17:49:06
    Tracy..since I cannot hear 32Khz, I was wondering with the Propbasic code above that you provided, I assume that I keep that in a continuous DO/LOOP, or put in some short duration PAUSE(s) before and after to get a beeping effect. Also, wouldn't I be able to at least see the waveform with an oscilloscope...approx swing of 6 volts, Peak to peak?

    Thanks DennO

  • jmgjmg Posts: 13,522
    denno wrote: »
    Also, wouldn't I be able to at least see the waveform with an oscilloscope...approx swing of 6 volts, Peak to peak?
    Yes, of course. Many multimeters also have a frequency counter range, easily good enough to sanity check frequency generation.

    Or, if you want to measure the Hz on the prop, there is
    PropBasic : http://forums.parallax.com/discussion/123170/propbasic-reciprocal-frequency-counter-0-5hz-to-40mhz-40mhz-now
    and that has been ported to another BASIC
    https://forums.parallax.com/discussion/comment/1446189/#Comment_1446189

  • Tracy AllenTracy Allen Posts: 6,347
    edited 2019-05-08 - 21:31:17
    One instruction I lazily forgot in the Spin code above will also be necessary in the PropBASIC code. That is, the pins have to be set as outputs. The ctra or COUNTERA instructions do not do that for you.
    So, in Spin
    CON
     _clkmode = xtal1 + pll16x                '
     _xinfreq = 5_000_000
    MY_APIN = 0 .    ' hook the transducer up between these two pins
    MY_BPIN = 1 .    '   A ----- xducer ----- B
    PUB  RocknRoll
       dira[MY_APIN] :=1 .  ' set the pins to be outputs
       dira[MY_BPIN] := 1
       frqa := 1759219   ' to set 32kHz out with 80MHz clkfreq
       ctra := %00101<<26 + (MY_BPIN<<9) + MY_APIN   ' NCO differential on my pins
       repeat     ' keep it alive
    

    In PropBASIC, add something like this,
    MY_APIN PIN 0 OUTPUT
    MY_BPIN PIN 1 OUTPUT
    

    Then you should be able to see it on the oscilloscope, but remember when you hook up the 'scope that neither side of the piezo is at ground, so the power supply for the Prop has to be isolated from the ground on the oscilloscope. If not that could be bad for the output pins!

    If you want to hear the sound on an audio piezo speaker, just compile it with a lower audible frequency.

    The program does need something like a DO:LOOP to keep the cog alive. In the Spin version, the final repeat statement does that, it sits there doing nothing. The counter modules run autonomously. Your Spin or PropBASIC program can continue to do other things without disturbing the NCO waveform. Of course the code can modify the waveform as it goes along, such as keying it on and off or modulating the frequency.

    The cog counter modules are a real boon. As jmg pointed out, a cog counter can also measure frequency, so you can have one cog measuring the frequency produced by another cog.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 22,324
    edited 2019-05-08 - 23:37:37
    Then you should be able to see it on the oscilloscope, but remember when you hook up the 'scope that neither side of the piezo is at ground, so the power supply for the Prop has to be isolated from the ground on the oscilloscope. If not that could be bad for the output pins!

    Good advice!

    Also, some scopes and PCs connect earth ground to logic ground. So, even if your power supply is isolated, having your prop connected to the PC at the same time as the scope is, isolation will be lost. If this is the case, and if your scope has two channels, you can also connect each signal wire to an output pin, leaving the ground leads disconnected. Then set the scope for difference input on the two pins.

    Simplest of all with a dual channel scope is just to display both channels, one above the other, and witness that they're 180 degrees out of phase.

    -Phil
    “Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. -Antoine de Saint-Exupery
  • Once again, I would like to thank everyone for there help/input. I was able to get the output to show on the scope. I was using a 12 volt battery source for the FLIP...regulated down...and I disconnected the charger from this laptop..so there was no ground/FLIP output issues. Tracy Allen, thank you for the formula to figure frqx.

    Now, for what I am building...called the "Garden Defender", from deer. Running now on the Prop, are 8 low power lasers, 650mW, pointing out at 45 degrees angles, up in hopes that they will bounce off old DVD's and old CD's hanging in an "X" configuration from corner to corner of the garden. (They really do reflect light) Also, I have four strobes at 90 degree angles, which are very bright. All of this is triggered by 4 PIR's, also at 90 degree angles. When ever a movement..aka..heat source...is detected by the PIR's, certain events start to take place. The strobes..all four...start flashing, the lasers, start to "shoot" out reflecting off the CD's and DVD's and all this continues on until the heat source, (deer, racoons, possiums), leaves.

    I was hoping to use...drive...4 ultrasonic devices, as deer, like dogs can hear higher then us humans...but I am having a little trouble finding a ultrasonic tranducer that works...bought some cheap ones from All Electronics...and tested them on my dog, but he did not blink an eye...or ear.

    Actually, the hardest part of the above device, is making it waterproof for the elements....

    dennO



  • Tracy AllenTracy Allen Posts: 6,347
    edited 2019-05-09 - 20:02:34
    A 25kHz transducer might be more effective. It is almost in range of human hearing. I built some ultrasonic transducer gizmos for a similar purpose, for a scientist who was doing an environmental health survey of the percentage of rabid bats in a population. It was thought that rabid bats tend to attack annoying noise sources, rather than fleeing, and that allowed them to be caught easily in mist nets and then tested. The device used a sealed 25kHz, 25mm transducer, driven differential by an SX20 processor, pulsing the sound.
    432 x 576 - 42K
  • jmgjmg Posts: 13,522
    .... It was thought that rabid bats tend to attack annoying noise sources, rather than fleeing, and that allowed them to be caught easily in mist nets and then tested. ..

    Was that thought proven in the field ?

  • Tracy, do you remember where you got that 25kHz, 25mm transducer? I will look around the internet as well...Thanks..I will include a photo of the finished device, when I receive my PCB from ExpressPCB.
  • Denno, Here's a link to the 25kHz transducer on the ProWave (manufacturer) site.
    http://www.prowave.com.tw/english/products/ut/enclosed/250e250.htm
    I don't see it listed on the Farnell or Element14 web sites at present, but that is where we sourced a lot of other ProWave transducers. I'm not positive we bought those 25kHz/25mm ones there. We might have found some from one of the surplus dealers. You can find lots of 40kHz 25mm sealed transducers on ebay, so it might be worth writing to one of those suppliers to see if they also have a 25kHz version. I'd say, try it with a readily available open version first to see if it works for your purpose.

    About jmg's question, about the attraction of rabid bats to the sound. I wasn't directly involved in the research. It is notoriously difficult to establish a solid control group in this kind of study. They did catch rabid bats and fewer normal bats. The numbers were small, like 3 to 5 in a deployment, and I recall being told that most of the catch was in a bunch, one night, not successive nights. So you could say that all of the rabid bats were captured, or they became habituated, or ???. So it remains anecdotal. The thought started when road crews working with jackhammers reported that they had been swooped by angry bats. The researcher then tried hanging smoke detectors set to alarm test mode out in the field, and found that he could capture rabid bats that way. But that was highly annoying to the peace of nature.
  • Again, many thanks Tracy, for your very detailed and articulate answer. I will check out the link and look around. I did find and bought some 32Khz transducers from All Electronics, to play around with them and the Propeller, and I can drive them. If I hold another 32Khz close to the one being driven by the prop, I can, with the scope, see a very nice sine wave, being generated by the square wave out of the prop, using COUNTERA, as you suggested. I was not expecting to see a sine wave on the second transducer, however.

    But, I believe I will need more power, in wattage, to to effectively scare away critters, aka...deer. I will keep looking around..

    DennO
  • Perhaps, this is not about the Propeller, but I will be using the Propeller to run it...having said that, does anyone have a simple circuit that will operate a 25Khz ultrasonic transducer...around 60 watts. The prop will just trigger it for a certain amount of time when the PIR detects a heat source..aka..deer. Preferred to operate on 12 volts...

    thank you..and Tracy I did follow the link you gave me, but it seems I need a amplifier of sorts to drive it...which I can build. Have looked at a Google search, but nothing strikes me as something that would work. Has anyone made an amplifier that will drive the above transducer....

    DenO
  • If you search for the phrase "ultrasonic drill," you will come across several circuits and drivers in this power range.
  • A single mosFET driver chip like the MICREL MIC4427 can help to max out the power. They make good piezo drivers. It can step up the output of the Prop from 0-3.3V up to +/-12 volts.

    Those small transducers can take only about 15–20V rms drive The Micrel mosFET drivers are basically H-Bridges with an output A and output B that can push enough current to drive a 2nF piezo through the full voltage swing in about 20ns.

    60W transducers are an entirely different category and require a bigger amplifier. Hey--I suspect the critters would be plenty annoyed by the lower power!
  • dennodenno Posts: 138
    edited 2019-05-16 - 16:51:32
    Tracy, again, many thanks for your help and knowledge. But, yet another question about the MIC4427, as I look up the data sheet on Digikey...with the NCO/PWM DIFFERENTIAL in Propbasic, I believe that I want the MIC4427ZN which is the dual non-inverting device..is that correct?

    Thanks...DennO

  • The Z suffix means it's lead-free and the N suffix means it's in a PDIP8 package.

    You could alternatively use the MIC4426 (dual inverting) or the MIC4428 (dual, one inverting one noninverting). A possible advantage of the MIC4428 is that the propeller could drive it from a NCO/single pin instead of NCO/differential. In that case the A and B inputs of the MIC4428 would both be connected to one Prop pin. The A and B outputs would be at opposite polarity to drive the piezo in H-bridge differential fashion. On the other hand, using two Prop pins gives you flexibility to decouple the A and B channels.

  • I understand, and do thank you again...I believe, since I am experimenting I will just order a couple of each, as the postage will still be the same...LOL...do you think the price of IC's from people like Digikey, will go UP, due to the tariffs? Just wondering..?
  • Tracy...cannot figure this one out...when I try to run two MIC4427's using COUNTERA , 40, myPIN_a, myPIN_b, frequency and COUNTERB, 40, myPIN_c, myPIN_d, frequency both MIC's will start to overheat and self destruct, if I let them go. I am running them both in the same DO/LOOP. If I remove one or the other from the breadboard, there is no overheat on the one that is running and I get the desired frequency on the scope, and if I lower the frequency enough, I can hear it. When the condition of the DO/LOOP is met, the program exits the LOOP, and then I use COUNTERA, 40, myPIN_a, myPIN_b, 0 and COUNTERB, 40, myPIN_c, myPIN_d,0 to turn off the transducers.

    I am very careful with my wiring on the breadboard, and I am connecting the two MIC's to Vs and ground in parallel, to 12 volts. But the respective inputs and outputs are not tied together. So, to recap, if I simply lift one or the other MIC's off the breadboard, the overheat condition goes away. And, yes, both will overheat until I remove one or the other...very strange...but I would be willing to bet you have an answer....I hope the above is understandable...

    Thank...lots....DennO
  • YanomaniYanomani Posts: 805
    edited 2019-05-21 - 18:25:26
    Hi denno

    Perhaps your setup is suffering from a Transition Dissipation problem (MIC4427's datasheet, page 7).

    Due to the way CounterA and CounterB are being used, the second counter-commanded pins would switch its own output pin states, soon after the first pair; just in time to worsen (due to noise coupling thru shared GND or V+ connections, or even both) the noise caused when both outputs of each MIC4427 are switching states, simultaneously (due to the fact that each pair is being controlled by the same counter ( A or B ).

    This could lead to the noise induced at the GND/Power rails, caused by the first switching pair, to be coupled to the inputs of the second, making them start their own cycle (switching), earlier than expected/predicted.

    Them, when the second MIC4427 starts conducting, it would influence the first one, as in a ringing effect, which would in turn, worsen the whole effect of noise coupling between them.

    If a condition as depicted above is the main cause of circuit failure, perhaps it could be rulled out by creating a break-before-make mechanism (thus, not entirelly relying on a single counter transition, commanding one pin and its inverted copy, to switch both control inputs of the same MIC4427).

    Separing the twin MIC4427s in two breadboards, apparted from the one that holds the Propeller itself,, following the best high-gauge wiring and heavy decoupling practices could help avoid any negative coupling-effects between them, without further concerns.

    Providing non-overlaping clocks for both control inputs of each MIC4427 could also help, but them you'll need to rely on oscilloscope measurements, in order to be sure there is no propagation of negative effects, from one pair of switching outputs to the control inputs of the second circuit, and vice-versa.

    Hope it helps a bit

    Henrique

  • dennodenno Posts: 138
    edited 2019-05-22 - 11:40:08
    Yanomani...I do understand what you have said, and thank you. And, before the two 4427's started to get hot, I did notice on the scope, what appeared to be extra ringing in both wave forms...dual trace...but, and here is the interesting part...the overheat condition only started after the programming instruction finished, and both counters were set to 0. I could place two fingers on top of the IC(s) and tell exactly, when the instruction in the loop was finished and my fingers would start to heat up.

    It is true, on the breadboard, I have not decoupled the 4427's and I will play with that next. And, here is the code...or a part of it. This is running in COG 0, I wonder if I ran the other MIC4427 in a different COG it would make a difference..and I will read page 7 that you referenced to me..DennO
    DO
         IF IR_sensor_0 = on_ THEN
           frequency_1 = 536870      'SPECIAL NOTE  53687 = 1KHz...use as a multilpler 
           frequency_2 = 536870
           strobe_out_0 = on_
           DO
               laser_0 = on_
               PAUSE duration
               laser_0 = off
               PAUSE duration
    
               COUNTERA 40, ultra_1, ultra_2, frequency_1  
               frequency_1 = frequency_1 + 53687         'adds 1KHz each loop..
               
               IF frequency_1 > 1342177 THEN             'until frequency hits 25KHz
                  frequency_1 = 536870                    'sets frequency back to 10Khz.
               ENDIF  
    
               COUNTERB 40, ultra_3, ultra_4, frequency_2
               frequency_2 = frequency_2 + 53687          'adds 1KHz each loop...
               
               IF frequency_2 > 1342177 THEN               'until frequency hits 25KHz
                 frequency_2 = 536870                           'set frequency back to 10KHz
               ENDIF                                                      
           LOOP until IR_sensor_0 = off      
           strobe_out_0 = off
           COUNTERA 40, ultra_1,ultra_2, 0             'turns off the frequency_1
           COUNTERB 40, ultra_3,ultra_4, 0             'turns off the frequency_2
         ENDIF
       LOOP
    

    Post Scrip...the ultra_1, ultra_2, ultra_3 and ultra_4, are PIN assignments.
  • YanomaniYanomani Posts: 805
    edited 2019-05-22 - 14:18:38
    Hi DennO

    Since you haven't published your present setup schematics, I'll try to progress solely relying on my tactile abilities (given my actual sight capabilities, it'll be just some kind of training-in-advance method). :lol:

    If the destructive warm-up starts soon after the frequency output ends, sure the outputs of each counter are being left in a "0 - 1" or "1 - 0" situation, which, considering that the ultrasonic transducers tend to present an almost pure capacitive load to the MICs outputs, should have mean that no current would flow thru the output pair of each MIC4427.

    Unless you had resorted to the insertion of series capacitors between the Prop output pins and the MICs inputs, it'll suffice to ensure each Propeller output pin pair to be set to "0" (both), after disconnecting them from the counters.

    If there are series capacitors between the Prop outputs and MIC4427 input pins, you'll need four pull-down resistors (~10 KOhm) to GND, directly connected to MICs input pins, to ensure there would be no activity at their output stages.

    Hope it helps

    Henrique
  • Tracy AllenTracy Allen Posts: 6,347
    edited 2019-05-22 - 21:42:27
    Difficult to troubleshoot at a distance. My first reaction was to blame an unwanted connection between the outputs of the two 4427s. Say, the two B outputs are have a common connection on both piezos. Both chips would get hot fast when running, and the problem would go away when one 4427 was pulled from the breadboard. But it sounds like your connections are okay, two independently driven piezos. That should work. But definitely add lots of bypassing at the 4427s. Again refer to page 7 of the data sheet. Bypassing should help with the kind of runaway condition that Yanomani pointed out. Also compact wiring will help, so as not to degrade the Propeller's natural fast transitions. The 4427 does have 100mV of hysteresis to help square up lazy transitions.

    It should not be necessary to start another cog.

    As to the power, I estimated dynamic load dissapation based on 25kHz, the highest in the programmed frequency scan...
    PL = f*CL*Vs^2 = 25000 * 2.2E-9 * 12^2 = 0.008 watt . for a 2.2nF piezo (typical)
    And the transition dissipation (charging 4427 internal capacitances)
    Pt = 2*f*Vs*Q = 2 * 25000 * 12 * 5E-9 = 0.003 watt. where 5E-9 is crossover energy loss per transition.
    So combined, 0.011 watt, which should not feel hot. No heat sink.

    Please reword what you said about the point in the program when it gets hot. I was left confused about that.
  • jmgjmg Posts: 13,522
    denno wrote: »
    ....but, and here is the interesting part...the overheat condition only started after the programming instruction finished, and both counters were set to 0. I could place two fingers on top of the IC(s) and tell exactly, when the instruction in the loop was finished and my fingers would start to heat up..
    Strange.
    Those parts look to have no pullup/pulldown, so you could try pull downs on the board.
    Their only mechanism for heat really looks to be switching, as in oscillating > 1MHz.
    What does the scope show in that heating condition, on IP and OP of driver ?
    Does it confirm the counter is stopped and driving the pin ?

  • Tracy AllenTracy Allen Posts: 6,347
    edited 2019-05-23 - 18:37:14
    Yes, the following program instructions turn off the frequency =0
    COUNTERA 40, ultra_1,ultra_2, 0             'turns off the frequency_1
    COUNTERB 40, ultra_3,ultra_4, 0             'turns off the frequency_2
    
    However, they might also turn the pin back to an input. I'm not sure about that. BASIC tends to mess with the pin direction, whereas in SPIN, the direction is a separate operation. You might try,
    COUNTERA 40, ultra_1,ultra_2, 128 'logic never, counter off (but not disabled?)
    COUNTERB 40, ultra_3,ultra_4, 128
    Or add program lines to turn the Prop pins definitively into LOW outputs when not counting:
    LOW ultra_1
    LOW ultra_2
    LOW ultra_3
    LOW ultra_4

    Crossed out mistaken PropBASIC syntax and logic.
    Or as others have suggested, add pulldown resistors to the MIC4427 inputs.


  • Well, it seems that I have sorted out the overheat issue. First, I decoupled the outputs OUTA and OUTB of both 4427's with a 10N capacitor to ground. Second, I put pull down resistors...10K...on all inputs to ground...aka...INA and INB on both 4427's. And, third, I moved that part of the program to it's own COG.

    Having messed alot with MOSFET..I feel that I was an issue with "shoot through", where the N channel and the P channel in the 4427 were conducting at the same time...hard to tell if it was A or B...

    Here is the code..of the COG that runs the ultrasonics..I may change the frequency spread, but for know, I wanted to be able to hear a part of it (around 10Khz) as well as see it on the scope and thanks to all you that added your help...
    TASK ultraSound 'RUNNING IN COG 5
      ultrasonic SUB
    '=========[PIN ASSIGNMENTS]====================
      ultra_1                    PIN  6  OUTPUT  'MY_APIN
      ultra_2                    PIN  7  OUTPUT  'MY_BPIN
      ultra_3                    PIN  4  OUTPUT  'MY_CPIN
      ultra_4                    PIN  5  OUTPUT  'MY_DPIN
    '========[VARIABLES]===========
      frequency_1          VAR        LONG
      frequency_2          VAR        LONG
      countTimes           VAR        LONG
    '=======[MAIN PROGRAM LOOP]==================
       DO
         IF IR_sensor_0 = on_ THEN
           GOSUB ultrasonic
         ELSEIF IR_sensor_1 = on_ THEN
           GOSUB ultrasonic
         ELSEIF IR_sensor_2 = on_ THEN
           GOSUB ultrasonic
         ELSEIF IR_sensor_3 = on_ THEN    
           GOSUB ultrasonic
         ENDIF   
       LOOP
    
       SUB ultrasonic
         frequency_1 = 536870      'SPECIAL NOTE  53687 = 1KHz...use as a multilpler 
         frequency_2 = 536870
         countTimes = 11
         DO
            COUNTERA 40, ultra_1, ultra_2, frequency_1  
            frequency_1 = frequency_1 + 53687         'adds 1KHz each loop..
            IF frequency_1 > 1342177 THEN             'until frequency hits 25KHz
              frequency_1 = 536870                    'sets frequency back to 10Khz.
            ENDIF  
            COUNTERB 40, ultra_3, ultra_4, frequency_2
            frequency_2 = frequency_2 + 53687          'adds 1KHz each loop...
            IF frequency_2 > 1342177 THEN               'until frequency hits 25KHz
              frequency_2 = 536870                    'set frequency back to 10KHz
            ENDIF                                                 '      
            PAUSE 100
        LOOP  countTimes      
        COUNTERA 40, ultra_1,ultra_2, 0             'turns off the frequency_1
        COUNTERB 40, ultra_3,ultra_4, 0             'turns off the frequency_2
        ultra_1 = off                                'set counterA and counterB outputs to zero 
        ultra_2 = off
        ultra_3 = off
        ultra_4 = off
       ENDSUB
    ENDTASK'ultraSound
    
Sign In or Register to comment.