Continue to Site

Welcome to

Welcome to our site! is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

anyone played with ultrasound before?

Not open for further replies.


Junior Member level 2
Aug 17, 2009
Reaction score
Trophy points
Activity points
ultrasonic pwm

Hey, hope everyones good.

I am currently playing around with some ultrasound transmitters and receivers. Just some basic stuff for now before I attempt a project of mine.

I have no used micro controllers before, so Im still pretty fresh in the area. However, I am willing to learn, and I am currently going through a couple of online tutorials.

For now, I would like to somehow configure the MC (Im using PIC 16f690) to send a PWM signal of 40 KHz to the ultrasonic transmitter. Ive come across this website which does the code for you if you type in the requirements, but I rather start from scratch and understand everything.

This is what the website says:

* PWM registers configuration
* Fosc = 4000000 Hz
* Fpwm = 40000.00 Hz (Requested : 40000 Hz)
* Duty Cycle = 50 %
* Resolution is 6 bits
* Prescaler is 1
* Ensure that your PWM pin is configured as digital output
* see more details on
* this source code is provided 'as is',
* use it at your own risks
PR2 = 0b00011000 ;
T2CON = 0b00000100 ;
CCPR1L = 0b00001100 ;
CCP1CON = 0b00011100 ;

And then I suppose you can use the following commands:

* Pwm_Init()
* Pwm_Change_Duty()
* Pwm_Start()
* Pwm_Stop()

So is this how you go about it? Set your frequency, duty cycle and your off? Can somebody please explain why the website comes up with the above values for PR2,T2CON and so on. And what are they?

Im sorry if this has been posted before, but ive been serching forums for hours on end without luck.

Any help would be appreciated. Just want to send a PWM signal o a ultrasonic transmitter.


pic ultrasound pwm

why are you using the pic to send the 40 khz?
you can just use a 555 timer to do the job

Yes im aware of that. However, creating a 40khz wave using a pic is only a small part of what im trying to do.

Im trying to send RF and ultrasonic pulses together at the same time, and then measure the difference it takes for the two signals to arrive on the other side.

So a 555 wont be able to do this accurately.

From what ive read, I need to use the pwm function of a microcontroller. theres hardly any tutes on this topic, and im finding it extremely difficult to write code for this. Any ideas?

are you making your search using that pic no?

sorry, what do you mean by pic no?

if you mean how im seperating incoming signals, its through the use of RF. Each rf transmitter will have its unique ID, and my receiver will be talking to one at a time.

is that what you mean?

thanks bud

I just can't see an end to such questions!

Go over to the CCS forum, download the PWMWizard (or even here) and copy paste into CCS IDE and you will be set.

Not open for further replies.

Part and Inventory Search

Welcome to