Bharathi Sara
Bharathi Sara

Reputation: 83

Raspberry Pi PWM with Ultrasound Transducers

I need to generate a 1Mhz short unipolar pulse every 20 seconds to generate an ultrasonic pulse on my ultrasonic transducers. What do you think is the best way to do this? My plan was to connect the transducers to the PWM pins and use pigpio to generate the square wave. I was thinking about doing something along these lines... would this work?

import time
import pigpio

pi = pigpio.pi() # Connect to local Pi.

while true
    pi.hardware_clock(18, 1000000) # 1 MHz square wave on gpio#18 (PWM)
    time.sleep(0.5) #wait for 0.5 seconds to shut the signal off
    pi.hardware_clock(18, 0) # turn signal off
    time.sleep(20) #wait 20 seconds before turning signal back on

pi.stop() # Disconnect from local Pi.

Upvotes: 0

Views: 553

Answers (1)

Simon Marcoux
Simon Marcoux

Reputation: 105

Not knowing the transducer or if this actual piece of code worked as intended to begin with, it is hard to pinpoint you toward the best approach to use.

That being said, your approach seems to be reasonable enough to actually try it out. The hardware clock library should be able to give you a reasonably clean 1MHz square wave. The maximum frequency that is documented is about 30MHz.

http://abyz.me.uk/rpi/pigpio/python.html#hardware_clock

If you have any follow up questions, don't hesitate to comment or let me know if it worked or not.

Upvotes: 1

Related Questions